runTestJob.xml revision d81978a0815d5b8a75633c35e3e1f8708d36f017
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "/shared/stax.dtd">
<!--
! CDDL HEADER START
!
! The contents of this file are subject to the terms of the
! Common Development and Distribution License, Version 1.0 only
! (the "License"). You may not use this file except in compliance
! with the License.
!
! You can obtain a copy of the license at
! trunk/opends/resource/legal-notices/OpenDS.LICENSE
! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
! See the License for the specific language governing permissions
! and limitations under the License.
!
! When distributing Covered Code, include this CDDL HEADER in each
! file and include the License file at
! trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
! add the following below this CDDL HEADER, with the fields enclosed
! by brackets "[]" replaced with your own identifying information:
! Portions Copyright [yyyy] [name of copyright owner]
!
! CDDL HEADER END
!
! Copyright 2006-2008 Sun Microsystems, Inc.
! -->
<stax>
<defaultcall function="start_job"/>
<function name="start_job">
<sequence>
<script>
STAXLogMessage = 1
</script>
<if expr="not STAXJobScriptFiles">
<sequence>
<message>'No script file (config.py) is specified. Unable to run the tests.'</message>
<return></return>
</sequence>
</if>
<!-- Load in the local shared python objects -->
<script>
import sys,os
sys.path.append("%s/shared/python" % TESTS_ROOT )
from common import *
</script>
<message>'PATH= %s' % sys.path</message>
<!-- Check some of the optional variables from config.py -->
<script>
try:
if TEST_OS_STRING:
ServerOsString=TEST_OS_STRING
else:
ServerOsString='Unknown Operating System'
except NameError,details:
ServerOsString='Unknown Operating System'
try:
if TEST_JVM_STRING:
ServerJVMString=TEST_JVM_STRING
else:
ServerJVMString='Unknown JVM'
except NameError,details:
ServerJVMString='Unknown JVM'
try:
if LOGS_URI:
logsURI=LOGS_URI
else:
logsURI=''
except NameError,details:
logsURI=''
</script>
<job name="'Job: %s %s' % (STAF_REMOTE_HOSTNAME,ServerOsString) " monitor="1" clearlogs="'Enabled'" logtcstartstop="'Enabled'">
<job-file>'%s/testcases/runFuncTests.xml' % TESTS_DIR</job-file>
<job-scriptfiles machine="STAF_LOCAL_HOSTNAME"> STAXJobScriptFiles </job-scriptfiles>
<job-action>
<log>'Started sub-job %s on %s, %s' % (STAXSubJobID,STAF_REMOTE_HOSTNAME,ServerOsString )</log>
</job-action>
</job>
<if expr="RC == 0">
<sequence>
<message>
'Sub-job %s completed. Children: %s' % (STAXSubJobID, STAXResult)
</message>
<script>
listOfChildren=STAXResult
</script>
</sequence>
<else>
<sequence>
<message log="1" level="'Error'">
'Sub-job %s could not be started. RC: %s Result: %s' % (STAXSubJobID,RC,STAFResult)
</message>
<return>1</return>
</sequence>
</else>
</if>
<!--- Import required shared xml libraries -->
<import machine="STAF_LOCAL_HOSTNAME"
file="'%s/stafcmd.xml' % TESTS_FUNCTIONS_DIR" />
<!-- FixMe
dirty workaround because utils.xml now depends on environment.xml
to avoid loading environment.xml I'll just set the required vars here
allegedly ugly
-=arnaud=-
-->
<script>
NO_CHECK = 'noCheck'
</script>
<import machine="STAF_LOCAL_HOSTNAME"
file="'%s/utils.xml' % (TESTS_FUNCTIONS_DIR)" />
<!-- Get Directory Server Variables -->
<call function="'GetVar'">
{ 'location' : STAF_REMOTE_HOSTNAME,
'type' : 'shared',
'variable' : 'Job%s_ServerInfo' % STAXSubJobID
}
</call>
<if expr="RC != 0">
<script>
STAFResult='{}'
</script>
</if>
<!-- Build the Servers Information Dictionary -->
<script>
ServersInfoDict=eval(STAFResult)
ServerVersion='unknown'
ServerBuildId='unknown'
ServerJavaVersion='unknown'
ServerJavaVendor='unknown'
ServerJVMVersion='unknown'
ServerJVMVendor='unknown'
ServerJVMArchitecture='unknown'
ServerJVMLabel='unknown'
ServerSystemOS='unknown'
ServerSystemName='unknown'
ServerSvnRevision='unknown'
if ServersInfoDict.has_key('%s/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)):
ServerInfoDict=ServersInfoDict['%s/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)]
ServerInfoKey='server version'
if ServerInfoDict.has_key(ServerInfoKey):
ServerVersion=ServerInfoDict[ServerInfoKey]
ServerInfoKey='server buildid'
if ServerInfoDict.has_key(ServerInfoKey):
ServerBuildId=ServerInfoDict[ServerInfoKey]
ServerInfoKey='java version'
if ServerInfoDict.has_key(ServerInfoKey):
ServerJavaVersion=ServerInfoDict[ServerInfoKey]
ServerInfoKey='java vendor'
if ServerInfoDict.has_key(ServerInfoKey):
ServerJavaVendor=ServerInfoDict[ServerInfoKey]
ServerInfoKey='jvm version'
if ServerInfoDict.has_key(ServerInfoKey):
ServerJVMVersion=ServerInfoDict[ServerInfoKey]
ServerInfoKey='jvm vendor'
if ServerInfoDict.has_key(ServerInfoKey):
ServerJVMVendor=ServerInfoDict[ServerInfoKey]
ServerInfoKey='jvm architecture'
if ServerInfoDict.has_key(ServerInfoKey):
ServerJVMArchitecture=ServerInfoDict[ServerInfoKey]
ServerInfoKey='system os'
if ServerInfoDict.has_key(ServerInfoKey):
ServerSystemOS=ServerInfoDict[ServerInfoKey]
ServerInfoKey='system name'
if ServerInfoDict.has_key(ServerInfoKey):
ServerSystemName=ServerInfoDict[ServerInfoKey]
ServerInfoKey='svn revision'
if ServerInfoDict.has_key(ServerInfoKey):
ServerSvnRevision=ServerInfoDict[ServerInfoKey]
else:
ServerInfoDict='No key found (%s/%s)' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
if ServerOsString == 'Unknown Operating System':
ServerOsString=ServerSystemOS
if ServerJVMString == 'Unknown JVM':
ServerJVMString=ServerJVMVersion
</script>
<message>'Server= %s' % ServerInfoDict </message>
<!-- Get the location of where the test logs are -->
<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
logsTestsDir='%s/testlogs' % logsDir
</script>
<call function="'createFolder'">
{ 'location' : STAF_LOCAL_HOSTNAME,
'foldername' : logsReportDir }
</call>
<script>
resultQuery=[]
textfile= '%s/results.txt' % logsReportDir
txtfh=open(textfile,'w')
</script>
<iterate var="thisChild" in="listOfChildren">
<sequence>
<stafcmd name="'STAF Command: Log Query All'">
<location>'%s' % STAF_LOCAL_HOSTNAME </location>
<service>'log'</service>
<request>
'QUERY ALL MACHINE %s LOGNAME STAX_Job_%s' % (STAXServiceMachine,thisChild)
</request>
</stafcmd>
<if expr="RC == 0">
<sequence>
<script>
resultQuery=STAFResult
</script>
<message>
'Log Query on STAX_Job_%s Completed. RC=%s' % (thisChild,RC)
</message>
<iterate var="line" in="resultQuery">
<script>
txtfh.write('%s\n' % line)
</script>
</iterate>
</sequence>
<else>
<sequence>
<message log="1" level="'Error'">
'Unable to perform log query on STAX_Job_%s. RC: %s Result: %s' % (thisChild,RC,STAFResult)
</message>
<return>1</return>
</sequence>
</else>
</if>
</sequence>
</iterate>
<script>
txtfh.close()
</script>
<!-- Write XML File for results -->
<script>
import re
xmlfile= '%s/results.xml' % logsReportDir
xmlfh=open(xmlfile,'w')
errorfile= '%s/results.errors' % logsReportDir
errorfh=open(errorfile,'w')
</script>
<!-- Build the test case dictionary object -->
<script>
testDict={}
testCaseList=[]
try:
txtfh=open(textfile,'r')
try:
for line in txtfh.readlines():
element=eval(line)
level=element['level']
message=element['message']
timestamp=element['timestamp']
startValueDict={}
stopValueDict={}
statusValueDict={}
if level == 'Start':
tcpattern=re.compile("(Testcase): (.*)")
tcmatch = tcpattern.search(message)
if tcmatch:
tctype=tcmatch.group(1)
tcname=tcmatch.group(2)
if testDict.has_key(tcname):
for key in testDict[tcname].keys():
value=testDict[tcname][key]
startValueDict[key]=value
startValueDict['start']=timestamp
testDict[tcname]=startValueDict
testCaseList.append(tcname.strip())
else:
errorfh.write('Warning: No match Start element %s.\n' % element)
elif level == 'Stop':
tcpattern=re.compile("(Testcase): (.*), ElapsedTime: (.*)")
tcmatch = tcpattern.search(message)
if tcmatch:
tctype=tcmatch.group(1)
tcname=tcmatch.group(2)
tctime=tcmatch.group(3)
if testDict.has_key(tcname):
for key in testDict[tcname].keys():
value=testDict[tcname][key]
stopValueDict[key]=value
stopValueDict['stop']=timestamp
stopValueDict['duration']=tctime
testDict[tcname]=stopValueDict
else:
errorfh.write('Warning: No match Stop element %s.\n' % element)
elif level == 'Status':
tcpattern=re.compile("(Testcase): (.*), Pass: (.*), Fail: (.*), ElapsedTime: (.*), NumStarts: (.*)")
tcmatch = tcpattern.search(message)
if tcmatch:
tctype=tcmatch.group(1)
tcname=tcmatch.group(2)
tcpass=tcmatch.group(3)
tcfail=tcmatch.group(4)
tctime=tcmatch.group(5)
tcnums=tcmatch.group(6)
if testDict.has_key(tcname):
for key in testDict[tcname].keys():
value=testDict[tcname][key]
statusValueDict[key]=value
statusValueDict['pass']=tcpass
statusValueDict['fail']=tcfail
testDict[tcname]=statusValueDict
else:
errorfh.write('Warning: No match Status element %s.\n' % element)
elif level == 'Info':
errorfh.write('Warning: Info element %s.\n' % element)
else:
errorfh.write('Error: Unknown element %s.\n' % element)
finally:
txtfh.close()
except IOError:
errorfh.write('Error: Unable to open %s. Reason IOError.' % textfile )
</script>
<!-- XML Report Pre -->
<script>
xmlfh.write('&lt;qa&gt;\n')
xmlfh.write(' &lt;functional-tests&gt;\n')
xmlfh.write(' &lt;identification&gt;\n')
xmlfh.write(' &lt;version&gt;\n')
xmlfh.write(' %s\n' % ServerVersion)
xmlfh.write(' &lt;/version&gt;\n')
xmlfh.write(' &lt;buildid&gt;\n')
xmlfh.write(' %s\n' % ServerBuildId)
xmlfh.write(' &lt;/buildid&gt;\n')
xmlfh.write(' &lt;revision&gt;\n')
xmlfh.write(' %s\n' % ServerSvnRevision)
xmlfh.write(' &lt;/revision&gt;\n')
xmlfh.write(' &lt;hostname&gt;\n')
xmlfh.write(' %s\n' % STAF_REMOTE_HOSTNAME)
xmlfh.write(' &lt;/hostname&gt;\n')
xmlfh.write(' &lt;platform&gt;\n')
xmlfh.write(' %s\n' % ServerSystemOS)
xmlfh.write(' &lt;/platform&gt;\n')
xmlfh.write(' &lt;jvm-version&gt;\n')
xmlfh.write(' %s\n' % ServerJVMVersion)
xmlfh.write(' &lt;/jvm-version&gt;\n')
xmlfh.write(' &lt;jvm-label&gt;\n')
xmlfh.write(' %s\n' % ServerJVMString)
xmlfh.write(' &lt;/jvm-label&gt;\n')
xmlfh.write(' &lt;jvm-vendor&gt;\n')
xmlfh.write(' %s\n' % ServerJVMVendor)
xmlfh.write(' &lt;/jvm-vendor&gt;\n')
xmlfh.write(' &lt;jvm-arch&gt;\n')
xmlfh.write(' %s\n' % ServerJVMArchitecture)
xmlfh.write(' &lt;/jvm-arch&gt;\n')
xmlfh.write(' &lt;os-label&gt;\n')
xmlfh.write(' %s\n' % ServerOsString)
xmlfh.write(' &lt;/os-label&gt;\n')
xmlfh.write(' &lt;tests-dir&gt;\n')
xmlfh.write(' %s\n' % logsDir)
xmlfh.write(' &lt;/tests-dir&gt;\n')
xmlfh.write(' &lt;tests-url&gt;\n')
xmlfh.write(' %s\n' % logsURI)
xmlfh.write(' &lt;/tests-url&gt;\n')
xmlfh.write(' &lt;/identification&gt;\n')
xmlfh.write(' &lt;results&gt;\n')
</script>
<!-- XML Report Results -->
<script>
for tcname in testCaseList:
if testDict.has_key(tcname):
tcnamesplit=tcname.split(":")
if tcnamesplit[0]:
tcgroup=tcnamesplit[0].strip()
if tcnamesplit[1]:
tcsuite=tcnamesplit[1].strip()
else:
tcsuite=tcgroup
else:
tcgroup=tcname
tcsuite=tcname
if testDict[tcname].has_key('pass'):
tcpass=testDict[tcname]['pass']
else:
tcpass='0'
if testDict[tcname].has_key('fail'):
tcfail=testDict[tcname]['fail']
else:
tcfail='0'
if testDict[tcname].has_key('start'):
tcstart=testDict[tcname]['start']
else:
tcstart='unknown'
if testDict[tcname].has_key('stop'):
tcstop=testDict[tcname]['stop']
else:
tcstop='unknown'
if testDict[tcname].has_key('duration'):
tcduration=testDict[tcname]['duration']
else:
duration='unknown'
else:
errorfh.write('No key for testcase %s.\n' % tcname)
if int(tcfail) == 0 and int(tcpass) > 0:
tcresult='pass'
elif int(tcfail) == 0 and int(tcpass) == 0:
tcresult='unknown'
else:
tcresult='fail'
tcdurationsecs=test_time().timeToSeconds(tcduration)
xmlfh.write(' &lt;testgroup name="%s"&gt;\n' % tcgroup)
xmlfh.write(' &lt;testsuite name="%s"&gt;\n' % tcsuite)
xmlfh.write(' &lt;testcase group="%s" suite="%s" name="%s" result="%s" start="%s" stop="%s" duration="%s"/&gt;\n' % (tcgroup,tcsuite,tcname,tcresult,tcstart,tcstop,tcdurationsecs))
xmlfh.write(' &lt;/testsuite&gt;\n')
xmlfh.write(' &lt;/testgroup&gt;\n')
</script>
<!-- XML Report Post -->
<script>
xmlfh.write(' &lt;/results&gt;\n')
xmlfh.write(' &lt;/functional-tests&gt;\n')
xmlfh.write('&lt;/qa&gt;\n')
</script>
<script>
xmlfh.close()
errorfh.close()
</script>
<message>
'XML Report Written to %s.' % xmlfile
</message>
<!-- Generate the standard test report showing all testcases -->
<script>
_message='Generated standard test report.'
xslfile= '%s/xsl/gen-alltests-report.xsl' % TESTS_SHARED_DIR
htmlfile= '%s/results.html' % logsReportDir
standardReport=report_generation()
stringParamsDict={}
try:
standardReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
except IOError,details:
_message='Unable to generate standard test report %s.' % details
except:
_message='Unable to generate standard test report !!!'
</script>
<message>_message</message>
<!-- Generate the test report by test groups-->
<script>
_message='Generated groups test report.'
xslfile= '%s/xsl/gen-groups-report.xsl' % TESTS_SHARED_DIR
htmlfile= '%s/groups.html' % logsReportDir
testslog= '%s/tests-log.xml' % logsTestsDir
groupsReport=report_generation()
stringParamsDict={ 'tests-log' : testslog }
try:
groupsReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
except IOError,details:
_message='Unable to generate groups test report %s.' % details
except:
_message='Unable to generate groups test report !!!'
</script>
<message>_message</message>
<!-- Generate the test report by test suites -->
<script>
_message='Generated suites test reports.'
testGroupDirsList=os.listdir(logsTestsDir)
for testGroupName in testGroupDirsList:
groupDir='%s/%s' % (logsTestsDir,testGroupName)
if os.path.isdir(groupDir):
xmlfile='%s/results.xml' % logsReportDir
htmlfile='%s/%s.html' % (groupDir,testGroupName)
xslfile= '%s/xsl/gen-suites-report.xsl' % TESTS_SHARED_DIR
suitesReport=report_generation()
stringParamsDict={ 'group' : testGroupName, 'tests-log' : testslog }
try:
suitesReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
except IOError,details:
_message='Unable to generate suites test report %s.' % details
except:
_message='Unable to generate suites test report %s !!!' % groupDir
</script>
<message>_message</message>
<!-- Generate the drill down test report -->
<script>
_message='Generated the drill down test report.'
myreportxsl='%s/xsl/my-report.xsl' % TESTS_SHARED_DIR
myreporthtml='%s/my-report.html' % logsReportDir
mytestslog='%s/tests-log.xml' % logsTestsDir
drillDownReport=report_generation()
stringParamsDict={}
try:
drillDownReport.transformReport(myreportxsl,mytestslog,myreporthtml,stringParamsDict)
except IOError,details:
_message='Unable to generate drill down test report %s.' % details
except:
_message='Unable to generate drill down test report !!!'
</script>
<message>_message</message>
<!-- Generate the summary text file -->
<script>
_message='Generated the summary text report'
mysummaryxsl='%s/xsl/gen-text-summary.xsl' % TESTS_SHARED_DIR
mysummarytext='%s/summary.txt' % logsReportDir
mysummaryxml=xmlfile
summaryReport=report_generation()
stringParamsDict={}
try:
summaryReport.transformReport(mysummaryxsl,mysummaryxml,mysummarytext,stringParamsDict)
except IOError,details:
_message='Unable to generate summary text file %s.' % details
</script>
<message>_message</message>
<!-- FixMe: Compatability with Hudson -->
<if expr="os.path.exists(myreporthtml)">
<sequence>
<message>'Copy %s to %s' % (myreporthtml,TMPDIR)</message>
<call function="'copyFile'">
{ 'srcfile' : myreporthtml,
'destfile' : '%s/my-report.html' % TMPDIR
}
</call>
</sequence>
</if>
<!-- FixMe: Compatability with Hudson -->
<if expr="os.path.exists(mytestslog)">
<sequence>
<message>'Copy %s to %s' % (mytestslog,TMPDIR)</message>
<call function="'copyFile'">
{ 'srcfile' : mytestslog,
'destfile' : '%s/tests-log.xml' % TMPDIR
}
</call>
</sequence>
</if>
<if expr="SEND_MAIL_AFTER_TEST_RUN == 'TRUE'">
<sequence>
<message>
'Sending Email Test Report to %s.' % SEND_MAIL_TO
</message>
<script>
try:
if SEND_MAIL_REPORT:
MailSendReport=SEND_MAIL_REPORT
else:
MailSendReport='%s/groups.html' % logsReportDir
except NameError,details:
MailSendReport='%s/groups.html' % logsReportDir
try:
if SEND_MAIL_TO:
MailToList= SEND_MAIL_TO.split(",")
else:
MailToList=[]
except NameError,details:
MailToList=[]
try:
if SEND_MAIL_SUBJECT:
MailSubject= SEND_MAIL_SUBJECT
else:
MailSubject= 'OpenDS Test Report for %s' % STAF_REMOTE_HOSTNAME
except NameError,details:
MailSubject= 'OpenDS Test Report for %s' % STAF_REMOTE_HOSTNAME
MailSendTo= ' '
</script>
<iterate var="Recipient" in="MailToList">
<script>
MailSendTo='to %s %s' % (Recipient,MailSendTo)
</script>
</iterate>
<stafcmd name="'STAF Command: Send test report %s' % MailSendTo">
<location>'%s' % STAF_LOCAL_HOSTNAME </location>
<service>'email'</service>
<request>
'send %s contenttype "text/html" file %s subject "%s" noheader' % (MailSendTo,MailSendReport,MailSubject)
</request>
</stafcmd>
<if expr="RC != 0">
<message log="1" level="'Error'">
'Send test report failed. RC: %s STAFResult: %s' % (RC,STAFResult)
</message>
<else>
<message>
'Send test report successful. RC: %s' % (RC)
</message>
</else>
</if>
</sequence>
</if>
</sequence>
</function>
</stax>