From 2d8669c190018f4662039e9da1dd098d183baa89 Mon Sep 17 00:00:00 2001
From: gary_williams <gary_williams@localhost>
Date: Mon, 11 Jun 2007 10:05:14 +0000
Subject: [PATCH] Issue 1120 test results and logs must go into a unique folder

---
 opends/tests/functional-tests/shared/python/common.py          |    9 ++++
 opends/tests/functional-tests/config/config.py                 |    2 +
 opends/tests/functional-tests/shared/functions/environment.xml |   46 +++++++++++++++++++----
 opends/tests/functional-tests/shared/functions/utils.xml       |    2 
 opends/tests/functional-tests/staf-installer/config.py.stubs   |    2 +
 opends/tests/functional-tests/testcases/runTestJob.xml         |   50 +++++++++++++++++++++----
 6 files changed, 94 insertions(+), 17 deletions(-)

diff --git a/opends/tests/functional-tests/config/config.py b/opends/tests/functional-tests/config/config.py
index f44f7c7..40fd9e1 100644
--- a/opends/tests/functional-tests/config/config.py
+++ b/opends/tests/functional-tests/config/config.py
@@ -29,5 +29,7 @@
 STAGED_DATA_DIR             = '%s/functional-tests/shared/data' % DIRECTORY_INSTANCE_DIR
 LOCAL_DATA_DIR		    = '%s/functional-tests/shared/data' % TMPDIR
 JAVA_HOME                   = '/usr/jdk/jdk1.5.0_01'
+LOGS_ROOT                   = '%s' % TMPDIR
+LOGS_URI                    = ''
 SEND_MAIL_AFTER_TEST_RUN    = 'FALSE'
 SEND_MAIL_TO                = ' '
diff --git a/opends/tests/functional-tests/shared/functions/environment.xml b/opends/tests/functional-tests/shared/functions/environment.xml
index 4345185..114f212 100755
--- a/opends/tests/functional-tests/shared/functions/environment.xml
+++ b/opends/tests/functional-tests/shared/functions/environment.xml
@@ -121,7 +121,6 @@
       <!-- XXXX this needs some cleanup XXXX -->
       <script>
         STAXLogMessage = 1 
-        LogDir='%s' % TMPDIR
         SRCFILE = '%s/%s' % (ZIPPATH,ZIPNAME) 
         DSTFILE = '%s/%s' % (TMPDIR,ZIPNAME)
         OPENDS_BINPATH ='%s/%s/bin' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME) 
@@ -208,7 +207,7 @@
         <call function="'SetVar'">
           { 'location'  : STAF_REMOTE_HOSTNAME,
             'type'      : 'shared',
-            'variable'  : 'ServerInfo=%s' % DSInfoServersDict }
+            'variable'  : 'Job%s_ServerInfo=%s' % (STAXJobID,DSInfoServersDict) }
         </call>
 
         <if expr="RC != 0">
@@ -256,7 +255,40 @@
     </try>
         
   </function>
-	
+
+  <function name="SetLogsDir">
+    <function-prolog>
+      This function sets the directory to which logs are written  
+    </function-prolog>
+
+    <sequence>
+    
+      <script>
+        logsDate=strftime("%Y%m%d-%H:%M:%S",localtime())
+        logsArch=DSInfo.getServerArch(DSInfo.ServerDict['system os'])
+        logsOSName=DSInfo.getServerOSName(DSInfo.ServerDict['system os'])
+        logsOS='%s-%s' % (logsOSName,logsArch)
+        logsJvm=DSInfo.getServerJavaMajorMinor(DSInfo.ServerDict['java version'])
+        logsDir='%s/%s/%s-jvm%s' % (LOGS_ROOT,logsDate,logsOS,logsJvm)
+        logsTestsDir='%s/testlogs' % logsDir
+        logsReportDir='%s/reports' % logsDir
+        logsSUTDir='%s/sutlogs' % logsDir
+        logsTmpDir='%s/tmp' % logsDir
+      </script>
+
+      <message>
+        'Tests logs output set to %s' % logsDir
+      </message>
+      
+      <call function="'SetVar'">
+        { 'location'  : STAF_REMOTE_HOSTNAME,
+          'type'      : 'shared',
+          'variable'  : 'Job%s_LogsDir=%s' % (STAXJobID,logsDir) }
+      </call>
+                    
+    </sequence>
+        
+  </function>	
 	
   <function name="loadEnvironment">
     <function-prolog>
@@ -275,13 +307,11 @@
 	  <call function="'importPythonLibraries'"/>
 		
 	  <call function="'initialiseGlobalVariables'"/>
-		  		
-<!--
-      <call function="'prepareInstanceCreation'"></call>						  		
--->					
 		
       <call function="'GetDirectoryServerInformation'"/>
-      						
+
+      <call function="'SetLogsDir'"/>
+            						
       <call function="'checkRC'">
         { 'returncode' : RC ,
           'result'     : STAXResult }
diff --git a/opends/tests/functional-tests/shared/functions/utils.xml b/opends/tests/functional-tests/shared/functions/utils.xml
index fcd6e91..a2c9d12 100755
--- a/opends/tests/functional-tests/shared/functions/utils.xml
+++ b/opends/tests/functional-tests/shared/functions/utils.xml
@@ -559,7 +559,7 @@
         FormattedTestgroup=FormattedTestcase.group(ThisGroupName)         
         FormattedTestsuite=FormattedTestcase.suite(ThisSuiteName)
              
-        TestLogDir= '%s/%s' % (LogDir,FormattedTestgroup)
+        TestLogDir= '%s/%s' % (logsTestsDir,FormattedTestgroup)
         TestLogFile='%s/%s' % (TestLogDir,FormattedTestsuite) 
       </script>
                   
diff --git a/opends/tests/functional-tests/shared/python/common.py b/opends/tests/functional-tests/shared/python/common.py
index 8101de2..0fe7442 100644
--- a/opends/tests/functional-tests/shared/python/common.py
+++ b/opends/tests/functional-tests/shared/python/common.py
@@ -64,6 +64,15 @@
   def getServerBuildId(self,string):
     return string.replace("Build ","")
 
+  def getServerOSName(self,string):
+    return string[0:string.find(' ')].strip()
+
+  def getServerArch(self,string):
+    return string[string.rfind(' ') +1:len(string)].strip()
+
+  def getServerJavaMajorMinor(self,string):
+    return string[0:string.rfind('.')]
+
   def getServerValueFromString(self,string):
     return string[string.find(':') +1:len(string)].strip()
 
diff --git a/opends/tests/functional-tests/staf-installer/config.py.stubs b/opends/tests/functional-tests/staf-installer/config.py.stubs
index c037b8a..71af780 100644
--- a/opends/tests/functional-tests/staf-installer/config.py.stubs
+++ b/opends/tests/functional-tests/staf-installer/config.py.stubs
@@ -28,6 +28,8 @@
 DIRECTORY_INSTANCE_BE       = 'userRoot'
 STAGED_DATA_DIR             = '%s/shared/data' % TMP_DATA_DIR
 LOCAL_DATA_DIR              = '%s/functional-tests/shared/data' % TMPDIR
+LOGS_ROOT                   = '%s' % TMPDIR
+LOGS_URI                    = ''
 JAVA_HOME                   = '${java.home}'
 SEND_MAIL_AFTER_TEST_RUN    = '${staf.email.send}'
 SEND_MAIL_TO                = '${staf.email.to}'
diff --git a/opends/tests/functional-tests/testcases/runTestJob.xml b/opends/tests/functional-tests/testcases/runTestJob.xml
index 4f3bee8..eb1df8a 100644
--- a/opends/tests/functional-tests/testcases/runTestJob.xml
+++ b/opends/tests/functional-tests/testcases/runTestJob.xml
@@ -36,7 +36,6 @@
 
       <script>
         STAXLogMessage = 1
-        logdir='%s' % TMPDIR
       </script>
       
       <job name="'Job: %s %s' % (STAF_REMOTE_HOSTNAME,TEST_OS_STRING) " monitor="1" clearlogs="'Enabled'" logtcstartstop="'Enabled'">
@@ -63,11 +62,14 @@
       <import machine="'%s' % (STAF_LOCAL_HOSTNAME)"
         file="'%s/stafcmd.xml' % (TESTS_FUNCTIONS_DIR)" />
         
+      <import machine="'%s' % (STAF_LOCAL_HOSTNAME)"
+        file="'%s/utils.xml' % (TESTS_FUNCTIONS_DIR)" />        
+        
       <!-- Get Directory Server Variables -->
       <call function="'GetVar'">
         { 'location'  : STAF_REMOTE_HOSTNAME,
           'type'      : 'shared',
-          'variable'  : 'ServerInfo' }
+          'variable'  : 'Job%s_ServerInfo' % STAXSubJobID }
       </call>
 
       <if expr="RC != 0">
@@ -75,7 +77,7 @@
           STAFResult='{}'
         </script>
       </if>
-      
+            
       <!-- Build the Servers Information Dictionary -->
       <script> 
                     
@@ -163,10 +165,42 @@
         </sequence>
       </else>
       </if>
- 
+
+      <!-- Get logsDir Variable -->
+      <call function="'GetVar'">
+        { 'location'  : STAF_REMOTE_HOSTNAME,
+          'type'      : 'shared',
+          'variable'  : 'Job%s_LogsDir' % STAXSubJobID }
+      </call>
+
+      <if expr="RC == 0">
+        <script>
+          logsDir=STAFResult
+        </script>
+      <else>
+        <sequence>
+          <message>
+            'Unable to retrieve LogsDir variable, RC=%s,Result=%s.' % (RC,STAFResult)
+          </message>          
+          <script>
+            logsDir='%s' % TMPDIR
+          </script>
+        </sequence>
+      </else>
+      </if>
+
+      <script>
+        logsReportDir='%s/reports' % logsDir
+      </script>
+
+      <call function="'createFolder'">
+        { 'location'   : STAF_LOCAL_HOSTNAME, 
+          'foldername' : logsReportDir }
+      </call>
+                   
       <!-- Write Text File for results -->
       <script>
-          textfile= '%s/results.txt' % logdir
+          textfile= '%s/results.txt' % logsReportDir
           txtfh=open(textfile,'w')
       </script>
       
@@ -189,9 +223,9 @@
       <!-- Write XML File for results -->
       <script>
         import re 
-        xmlfile= '%s/results.xml' % logdir
+        xmlfile= '%s/results.xml' % logsReportDir
         xmlfh=open(xmlfile,'w') 
-        errorfile= '%s/results.errors' % logdir
+        errorfile= '%s/results.errors' % logsReportDir
         errorfh=open(errorfile,'w')
       </script>
 
@@ -390,7 +424,7 @@
       <!-- Transform Report XML into HTML -->
       <script>
         xslfile= '%s/xsl/gen-alltests-report.xsl' % TESTS_SHARED_DIR
-        htmlfile= '%s/results.html' % logdir
+        htmlfile= '%s/results.html' % logsReportDir
       </script>
       
       <message>

--
Gitblit v1.10.0