<?
xml version="1.0" encoding="UTF-8" standalone="no"?>
! 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 ! You can obtain a copy of the license at ! 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 ! 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] ! Copyright 2007-2008 Sun Microsystems, Inc. <
function name="checkRC">
This function checks a return code against an expected return code
<
function-
arg-
def name="returncode" type="required">
<
function-
arg-
description>
return code received from command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
function-
arg-
def name="result" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
function-
arg-
def name="expected" type="optional" default="0">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
if expr="expected == 'noCheck'">
<
if expr="returncode == expected">
'RC=%s, Result=Ok' % (returncode)
'RC=%s, Result=%s' % (returncode,result)
<
message log="1" level="'Error'">
'RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
<
function name="checktestRC">
This function checks the return code against an expected return code for a testcase
<
function-
arg-
def name="returncode" type="required">
<
function-
arg-
description>
return code received from command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
function-
arg-
def name="result" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
function-
arg-
def name="expected" type="optional" default="0">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
if expr="expected == 'noCheck'">
<
if expr="returncode == expected">
<
if expr="STAXCurrentTestcase != None">
<
tcstatus result="'pass'"/>
<
if expr="VERBOSE_MODE == 'True'">
'SUCCESS: RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
'SUCCESS: RC=%s, Expected %s' % (returncode,expected)
<
if expr="STAXCurrentTestcase != None">
<
tcstatus result="'fail'"/>
<
message log="1" level="'Error'">
'ERROR : RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
<!-- Set the test status to PASS --> <
function name="testPassed">
This function set the status of the tests: PASS
<
message>'Set test status to PASS'</
message>
<
tcstatus result="'pass'"/>
<!-- Set the test status to FAIL --> <
function name="testFailed">
This function set the status of the tests: FAIL
<
message>'Set test status to FAIL'</
message>
<
tcstatus result="'fail'"/>
<
function name="checktestString">
This function checks the return string against an expected return substring for a testcase
<
function-
arg-
def name="expectedString" type="required">
<
function-
arg-
description>
the substring expected from the command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="returnString" type="required">
<
function-
arg-
description>
the return string received from command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
if expr='re.search(searchre, returnString) != None'>
<
tcstatus result="'pass'"/>
'SUCCESS : Found substring, %s, in the return string' % (expectedString)
<
tcstatus result="'fail'"/>
<
message log="1" level="'Error'">
'ERROR : Did not find substring, %s, in the return string, %s' % (expectedString, returnString)
<
function name="checktestStringNotPresent">
This function checks the return string against an expected return substring that should not be present for a testcase
<
function-
arg-
def name="testString" type="required">
<
function-
arg-
description>
the substring being tested from the command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="returnString" type="required">
<
function-
arg-
description>
the return string received from command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
if expr='re.search(searchre, returnString) == None'>
<
tcstatus result="'pass'"/>
'Did Not Find substring, %s, in the return string' % (testString)
<
tcstatus result="'fail'"/>
<
message log="1" level="'Error'">
'Found substring, %s, in the return string, %s' % (testString, returnString)
<
function name="searchStringForSubstring">
This function simply searches a string for a substring
<
function-
arg-
def name="testString" type="required">
<
function-
arg-
description>
the substring being tested from the command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="returnString" type="required">
<
function-
arg-
description>
the return string received from command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="expectedResult" type="optional" default="'2'">
<
function-
arg-
description>
the expected result, 0 for false (not present), 1 for true (present), 2 for old behavior
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<!-- Until all the test cases are refactored to use the expectedResult param, we need this if-else conditional. --> <
if expr="expectedResult == '2'">
<
if expr='re.search(searchre, returnString) == None'>
<
script>returnCode='0'</
script>
'Did Not Find substring, %s, in the return string' % (testString)
<
script>returnCode='1'</
script>
'Found substring, %s, in the return string' % (testString)
<
return>returnCode</
return>
<
if expr='re.search(searchre, returnString) == None'>
<
script>returnCode='0'</
script>
<
if expr="expectedResult == '0'">
<
tcstatus result="'pass'"/>
'SUCCESS : Did Not Find substring, %s, in the return string' % (testString)
<
tcstatus result="'fail'"/>
<
message log="1" level="'Error'">
'ERROR : Did Not Find substring, %s, in the return string' % (testString)
<
script>returnCode='1'</
script>
<
if expr="expectedResult == '1'">
<
tcstatus result="'pass'"/>
'SUCCESS : Found substring, %s, in the return string' % (testString)
<
tcstatus result="'fail'"/>
<
message log="1" level="'Error'">
'ERROR : Found substring, %s, in the return string' % (testString)
<
return>returnCode</
return>
<
function name="isAlive" scope="local">
Checks that the ldap server is running
<
function-
arg-
def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="dsPath" type="optional" default="'%s/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)">
<
function-
arg-
description>
Pathname to installation root
</
function-
arg-
description>
<
function-
arg-
property name="type" value="pathname"/>
<
function-
arg-
def name="noOfLoops" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
function-
arg-
def name="noOfMilliSeconds" type="required">
<
function-
arg-
description>
Number of seconds to wait between iterations
</
function-
arg-
description>
<
function-
arg-
property name="type" value="seconds"/>
<
function-
arg-
def name="dsInstanceHost" type="optional" default="DIRECTORY_INSTANCE_HOST">
<
function-
arg-
description>
Directory server hostname or IP address
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="dsInstancePort" type="optional" default="DIRECTORY_INSTANCE_PORT">
<
function-
arg-
description>
Directory server port number
</
function-
arg-
description>
<
function-
arg-
property name="type" value="Port number"/>
<
function-
arg-
def name="dsInstanceDn" type="optional" default="DIRECTORY_INSTANCE_DN">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="DN"/>
<
function-
arg-
def name="dsInstancePswd" type="optional" default="DIRECTORY_INSTANCE_PSWD">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
script>ldapRC=9999</
script>
<
loop from="1" to="noOfLoops" while="ldapRC != 0">
<
call function="'SearchObject'">
{ 'location' : mylocation,
'dsInstanceHost' : myhost ,
'dsInstancePort' : myport ,
'dsInstancePswd' : mypswd ,
'dsBaseDN' : 'cn=config' ,
'dsFilter' : 'objectclass=*' ,
<
call function="'Sleep'">
{ 'sleepForMilliSeconds' : noOfMilliSeconds }
Sleep for number of milliseconds
<
function-
arg-
def name="location" type="optional" default="STAXServiceMachine">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="sleepForMilliSeconds" type="required">
<
function-
arg-
description>
Number of milliseconds to sleep
</
function-
arg-
description>
<
function-
arg-
property name="type" value="seconds"/>
<
stafcmd name="'STAF Command: Delay'">
<
location>'%s' % location</
location>
<
service>'delay'</
service>
'delay %i' % sleepForMilliSeconds
<
call function="'checkRC'">
<
function name="getOSvariables">
<
function-
arg-
def name="hostname" type="required">
<
function-
arg-
description>
Name of host on which to retrieve variables
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
stafcmd name="'STAF Command: Get OS Name'">
<
location>'%s' % hostname</
location>
'OS Name= %s' % STAFResult
<
return>STAFResult</
return>
<
function name="testCase_StartBanner">
Pretty prints a banner at the start of a test.
<
message level="'start'">'testcase: %s' % STAXCurrentTestcase</
message>
<
message>'****************************************************'</
message>
<
message>'*** STARTING TEST CASE %s.' % STAXCurrentTestcase</
message>
<
function name="testCase_EndBanner">
Pretty prints a banner at the end of a test.
<
message>'*** ENDING TEST CASE %s.' % STAXCurrentTestcase</
message>
<
message>'****************************************************'</
message>
<
message level="'stop'">'testcase: %s' % STAXCurrentTestcase</
message>
<
function name="testCase_Preamble">
Performs all the preoperations for a test case
testcaseStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
for logType in ['errors','access']:
logfile=open('%s/%
s/
logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType),'a')
<
call function="'testCase_StartBanner'" />
<
function name="testCase_Postamble">
Performs all the post operations for a test suite
<!-- Check the SignalRaised flag --> 'A signal (%s) was raised during this test case' % SignalRaised
<
tcstatus result="'fail'"/>
<!-- Reset the SignalRaised flag --> <!-- Query the test case results --> <
call function="'queryTestcase'" />
numPass=int(STAFResult['numPasses'])
numFail=int(STAFResult['numFails'])
_status='KNOWN ISSUES %s' % str(issuesList)
<
message level="'status'">'## Test Verdict: %s ##' % _status</
message>
<
call function="'testCase_EndBanner'" />
testcaseEndTime = strftime("%Y%m%d@%H:%M:%S",localtime())
<
call function="'queryLogs'">
{ 'location' : STAXServiceMachine,
'logname' : 'STAX_Job_%s_User' % STAXJobID,
'startfrom' : testcaseStartTime,
'endat' : testcaseEndTime }
def __init__(self, group, suite, fullname, start, stop, failures, successes, issues, duration):
xml = ' <test>%s' % newLine
xml += ' <name>%s</name>%s' % (
self.name,newLine)
xml += ' <group>%s</group>%s' % (
self.group,newLine)
xml += ' <suite>%s</suite>%s' % (
self.suite,newLine)
xml += ' <start>%s</start>%s' % (
self.start,newLine)
xml += ' <stop>%s</stop>%s' % (
self.stop,newLine)
xml += ' <result>%s</result>%s' % (
self.result,newLine)
xml += ' <duration>%d</duration>%s' % (
self.duration,newLine)
xml += ' <issues>%s' % newLine
xml += ' <issue>%s</issue>%s' % (issue,newLine)
xml += ' </issues>%s' % newLine
xml += ' <log>%s' % newLine
xml += ' <![CDATA[%s' % newLine
xml += ' ]]>%s' % newLine
xml += ' </log>%s' % newLine
xml += ' <error>%s' % newLine
xml += ' <![CDATA[%s' % newLine
xml += ' ]]>%s' % newLine
xml += ' </error>%s' % newLine
xml += ' <access>%s' % newLine
xml += ' <![CDATA[%s' % newLine
xml += ' ]]>%s' % newLine
xml += ' </access>%s' % newLine
xml += ' </test>%s' % newLine
def appendLog(self, category, log):
wrappedLog+='%s%s%s' % (_leftPadding,_logChunk,newLine)
wrappedLog += '%s%s%s' % (_leftPadding,_line,newLine)
elif category == 'error':
testcaseDuration=testcaseStop-testcaseStart
thisTest = Test(CurrentTestPath['group'],CurrentTestPath['suite'],STAXCurrentTestcase, testcaseStartTime,testcaseEndTime,numFail,numPass,issuesList,testcaseDuration)
# loop through the log lines
for element in STAFResult:
# this test is BEFORE the append so we don't get the
# end of testcase banner in the XML but only the relevant data
# if the current element is actually this test's output then log it
# this test is AFTER the append log so we don't get the
# "starting testcase ..." header in the XML
tmp = element['message'].split(':')
# this is a verification that we start logging for the right
# test case. this is especially useful for tests that execute
# within the same second (that is the resolution of the STAF
# parse the server's error log
# TODO: figure out how to do this for multiple instance for the replication
for logType in ['errors','access']:
logfile=open('%s/%
s/
logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType),'a')
logfile=open('%s/%
s/
logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType), 'r')
# clean the temporary log files for this test
# this MUST be done AFTER the call to toXML or the logs will appear empty
<
message>'%s' % _message</
message>
<
function name="testSuite_Preamble">
Performs all the pre operations for a test suite
<!-- Take the values from the current test path --> CurrentTestPath['group']='unknown-group'
CurrentTestPath['suite']='unknown-suite'
ThisGroupName=CurrentTestPath['group']
ThisSuiteName=CurrentTestPath['suite']
<!-- Start time of test suite --> TestSuiteStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
'#### %s/%s suite preamble ####' % (ThisGroupName,ThisSuiteName)
<
function name="testSuite_Postamble">
Performs all the post operations for a test suite
<!-- Take the values from the current test path --> ThisSuiteName=CurrentTestPath['suite']
ThisSuiteName='unknown-suite'
ThisGroupName=CurrentTestPath['group']
ThisGroupName='unknown-group'
'#### %s/%s suite postamble ####' % (ThisGroupName,ThisSuiteName)
<!-- Start time of test suite --> TestSuiteEndTime=strftime("%Y%m%d@%H:%M:%S",localtime())
<!-- Format the test group and suite names to create folder --> FormattedTestcase=format_testcase()
TestLogDir= '%s/%s' % (
logs.tests,FormattedTestgroup)
TestLogFile='%s/%s' % (TestLogDir,FormattedTestsuite)
<
call function="'WriteLogsForTestCase'">
{ 'starttime' : TestSuiteStartTime,
'endtime' : TestSuiteEndTime,
'logFile' : TestLogFile }
del CurrentTestPath['suite']
<
function name="testGroup_Preamble">
Performs all the pre operations for a test group
<!-- Take the values from the current test path --> CurrentTestPath['group']='unknown-group'
ThisGroupName=CurrentTestPath['group']
# the reason for that is that the topology is created AFTER the
# first test group has started (as part of the first setup)
# the following groups are going to use the same topology
mylog="::coverage - checking for %s/%
s/
lib/
emma.jar\n" % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
mylog+=" ::coverage on\n"
mylog+=" ::mkdir %
s/
coverage/%s on\n" % (TMPDIR,CurrentTestPath['group'])
<
message>'##### %s group preamble #####' % ThisGroupName</
message>
<
function name="testGroup_Postamble">
Performs all the post operations for a test group
ThisGroupName=CurrentTestPath['group']
ThisGroupName='unknown-group'
<
message>'##### %s group postamble #####' % ThisGroupName</
message>
emmaJar='%s/%
s/
lib/
emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
coverageEm='%s/%
s/
coverage.em' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
<
call function="'runCommand'">
{ 'name' : 'Generate coverage xml report for test group %s' % CurrentTestPath['group'],
from
java.io import FileInputStream
del CurrentTestPath['group']
<
function name="WriteLogsForTestCase" scope="local">
Queries the staf logs for the test case and write to file as text
<
function-
arg-
def name="starttime" type="required">
<
function-
arg-
description>
timestamp to start logging from
</
function-
arg-
description>
<
function-
arg-
property name="type" value="timestamp"/>
<
function-
arg-
def name="endtime" type="required">
<
function-
arg-
description>
timestamp to start logging to
</
function-
arg-
description>
<
function-
arg-
property name="type" value="timestamp"/>
<
function-
arg-
def name="logFile" type="required">
<
function-
arg-
description>
name of file to write the logs
</
function-
arg-
description>
<
function-
arg-
property name="type" value="filepath"/>
<!-- Query STAF to obtain the logs for the test case --> <
call function="'queryLogs'">
{ 'location' : STAXServiceMachine,
'logname' : 'STAX_Job_%s_User' % STAXJobID,
<!-- Write out the logs into an XML file --> <
call function="'WriteXmlLogs'">
{ 'queryresult' : STAFResult,
<!-- Transform the XML file into an HTML file --> <
call function="'WriteHtmlLogs'">
<
function name="WriteXmlLogs" scope="local">
Process staf log query results and write them to a file
<
function-
arg-
def name="queryresult" type="required">
<
function-
arg-
description>
result of the staf log query
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="output" type="required">
<
function-
arg-
description>
name of the XML file to where results are written
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
message>'Creating XML log file %s' % logFile</
message>
<
call function="'createFolder'">
{ 'location' : STAXServiceMachine,
'foldername' : NewLogDir }
# Create the qa base element
# Create the base element
# Try to pass only the pretty print of the test suite name
suite=CurrentTestPath['suite'].split('.')[2].strip()
formattedTestcase = format_testcase()
<
if expr="queryresult == '[]'">
output1 = 'queryresult is empty'
output2 = 'check the date between the OS, the logs'
output3 = 'and the local time zone'
output = '%s %s %s' % (output1,output2,output3)
<
call function="'checktestRC'">
<
iterate var="element" in="queryresult">
message=element['message']
timestamp=element['timestamp']
_message='Generated XML test case report.'
testlogfh=open('%s' % logFile,'w')
except AttributeError,details:
_message='Unable to generate XML test case report %s.' % details
_message='Unable to generate XML test case report !!!'
<
message>_message</
message>
<
function name="WriteHtmlLogs" scope="local">
Process XML file and transform that to an HTML log file
<
function-
arg-
def name="input" type="required">
<
function-
arg-
description>
name of the XML file to where results are obtained
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="output" type="required">
<
function-
arg-
description>
name of the HTML file to where results are written
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="stylesheet" type="required">
<
function-
arg-
description>
name of the XSL stylesheet used to transform results
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
message>'Inputting XML file %s' % xmlFile</
message>
<
message>'Transform XSL file %s' % xslFile</
message>
<
message>'Creating HTML file %s' % htmlFile</
message>
_message='Generated test case logs.'
testCaseLogs=report_generation()
_message='Unable to generate test case logs %s.' % details
_message='Unable to generate test case logs %s.' % details
_message='Unable to generate test case logs !!!'
<
message>'%s' % _message</
message>
<
function name="CheckMatches">
check the number of matching sub-string in a string
<
function-
arg-
def name="string2find" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="mainString" type="required">
<
function-
arg-
description>
the main string where the search is done
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="caseSensitive" type="optional" default="True">
<
function-
arg-
description>
comparison using case sensitive, or not value is :
True/
False </
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="nbExpected" type="optional" default="1">
<
function-
arg-
description>
number of expected sub-string that must be in the main string
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
caseSensitiveInfo = '[case sensitive mode]'
if caseSensitive == False:
caseSensitiveInfo = '[case insensitive mode]'
if nbFound == nbExpected:
myMessage = 'SUCCESS : %s matches %s time(s) (expected %s) %s' % (string2find,nbFound,nbExpected,caseSensitiveInfo)
myMessage = 'ERROR : %s matches %s time(s) (expected %s) in "%s" %s' % (string2find,nbFound,nbExpected,mainString,caseSensitiveInfo)
<
tcstatus result="'pass'"/>
<
tcstatus result="'fail'"/>
<
message log="1" level="'Error'">
<
return>myRC,myMessage</
return>
<
function name="runFunction">
<
function-
arg-
def name="functionName" type="required">
<
function-
arg-
description>
Name of the function to run
</
function-
arg-
description>
<
function-
arg-
def name="functionArguments" type="optional">
<
function-
arg-
description>
Arguments to be passed on to the called function.
This can be a map or a list of arguments, whatever the called function
expects will be carried on here.
. for a map, pass the arguments like this:
{ 'argumentA' : 'argumentAvalue' ,
. for a list, pass the arguments like this:
[ 'argumentAvalue, 1, ... ]
</
function-
arg-
description>
<
function-
arg-
def name="expectedRC" type="optional" default="0">
<
function-
arg-
description>
The expected return code of the function to run.
This is then passed onto the checkRC function.
It is also used to throw an exception if the argument
functionException is provided and set the test case status if the
argument functionSetsTCStatus is provided
</
function-
arg-
description>
<
function-
arg-
property name="type" value="integer"/>
<
function-
arg-
def name="functionException" type="optional">
<
function-
arg-
description>
The exception to throw if the return code differs from the expected
RC. The exception is appended to STAXException.
</
function-
arg-
description>
<
function-
arg-
def name="functionMessage" type="optional">
<
function-
arg-
description>
An optional message to display before running the function
</
function-
arg-
description>
<
function-
arg-
def name="functionSetsTCStatus" type="optional">
<
function-
arg-
description>
Whether the function to run sets the testcase status or not.
If this is set, the test case status is set according to whether
or not the function meets the expected return code.
True or False should be used for this argument.
</
function-
arg-
description>
<
function-
arg-
def name="functionFailureTC" type="optional">
<
function-
arg-
description>
If this argument is provided, a testcase will be created with
this argument's value for name and set to fail only upon failure
</
function-
arg-
description>
<
function-
arg-
def name="functionSignal" type="optional">
<
function-
arg-
description>
If this argument is provided, a signal will be raised upon unsuccesful
execution of the function to run
</
function-
arg-
description>
<
function-
arg-
def name="functionCallBack" type="optional">
<
function-
arg-
description>
If this argument is provided then functionCallBack will be called
after the execution of function name.
</
function-
arg-
description>
<
function-
arg-
def name="functionCallBackArguments" type="optional">
<
function-
arg-
description>
This allows to specify arguments for the call back function
</
function-
arg-
description>
<!-- defining the booleans here should temporary while I find a nicer solution. We have a chicken and egg problem between the loadGlobalEnvironment and loadSharedLibraries functions in <
message log="1" level="'info'" if="_displayMessage == True">'%s' % functionMessage</
message>
<
message log="1" level="'debug'">'runFunction: %s: called with parameters [%s]' % (functionName,functionArguments)</
message>
<
call function="functionName">functionArguments</
call>
<
message log="1" level="'debug'">'runFunction: %s: returned [%s] with [%s]' % (functionName,RC,STAXResult)</
message>
<!-- this section handles the optional case when we need to set the <
if expr="_doSetTCStatus == True">
<
if expr="_functionRC == expectedRC">
<
script>_tcStatus='pass'</
script>
<
tcstatus result="_tcStatus" />
<!-- this section handles the optional case when we need to throw an exception upon unexpected function return code <
if expr="_throwException == True" >
<
if expr="_functionRC != expectedRC" >
<
throw exception="'STAXException.%s' % functionException" />
<!-- this section handles the optional case when we need to set a test case status to fail to reflect the failure in the test report. <
if expr="_createFailureTC == True" >
<
if expr="_functionRC != expectedRC" >
<
testcase name="'!!! %s [%s]' % (functionFailureTC,functionName)">
<
tcstatus result="'fail'" />
<!-- TODO: implement the signal raising mechanism --> <!-- TODO: implement the call back function mechanism --> <!-- bubble the function return code up one level --> <
return>_functionRC</
return>
<
function name="runCommand" >
A general wrapper to run a command without having to write a dedicated
<
function-
arg-
def name="command" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
def name="path" type="optional" default="dsBinPath">
<
function-
arg-
description>
the path where the command is to be run from
</
function-
arg-
description>
<
function-
arg-
def name="arguments" type="optional" default="''">
<
function-
arg-
description>
the path where the command is to be found
</
function-
arg-
description>
<
function-
arg-
def name="env" <
function-
arg-
description>
the environment variables to set. The default set here should just
</
function-
arg-
description>
<
function-
arg-
def name="location" default="STAXServiceMachine">
<
function-
arg-
description>
Which machine should the command be executed on
</
function-
arg-
description>
<
function-
arg-
def name="name" default="'Running %s' % command" <
function-
arg-
description>
The name to give the process (only matters in the STAX Monitor really)
</
function-
arg-
description>
<
function-
arg-
def name="stripOutput" default="True" type="optional">
<
function-
arg-
description>
A boolean (use True or False here, case matters) to enable disable
stripping the output of a command
TODO: consider allowing passing a function name to enable custom
output manipulation (overkill?)
</
function-
arg-
description>
<
function-
arg-
property name="type" value="enum">
<
function-
arg-
property-
description>
This argument can only have boolean values
</
function-
arg-
property-
description>
<
function-
arg-
property-
data type="choice" value="True"/>
<
function-
arg-
property-
data type="choice" value="False"/>
<
function-
arg-
def name="timerDuration" <
function-
arg-
description>
The duration that the process is allowed to run
</
function-
arg-
description>
<
function-
arg-
def name="inputFile" type="optional" default="'None'">
<
function-
arg-
description>
input file containing the command input
</
function-
arg-
description>
<
function-
arg-
property name="type" value="file"/>
<
function-
arg-
def name="outputFile" type="optional" default="'None'">
<
function-
arg-
description>
Output file containing the command output
</
function-
arg-
description>
<
function-
arg-
property name="type" value="file"/>
<
function-
arg-
def name="expectedRC" type="optional" default="0">
<
function-
arg-
description>
Expected return code value. Default value is 0.
Wildcard 'noCheck' to not check the RC
</
function-
arg-
description>
<
function-
arg-
def name="logStderr" type="optional" default="True">
<
function-
arg-
description>
If true, stderr for the command is redirect to stdout.
</
function-
arg-
description>
<
function-
arg-
property name="type" value="enum">
<
function-
arg-
property-
description>
This argument can only have boolean values
</
function-
arg-
property-
description>
<
function-
arg-
property-
data type="choice" value="True"/>
<
function-
arg-
property-
data type="choice" value="False"/>
_id = '%s#%d' % (strftime('%Y-%m-%d %H:%M:%S',localtime()),
random.randint(0,999))
if is_windows_platform(location):
env=['PATH=C:\Windows;C:\Windows\system32;%s' % path, 'JAVA_HOME=%s' % JAVA_HOME]
env=['PATH=/bin:/
usr/
bin:%s' % path, 'JAVA_HOME=%s' % JAVA_HOME]
'%s: Running command:\n %s %s\nlocation: %s\nenv: %s\nworkdir: %s' % (_id,command,arguments,location,env,path)
<!-- If 'logStderr' is True then redirect sdterr to sdtout --> <
if expr="logStderr == True">
<
location>location</
location>
<
command>command</
command>
<
stdout if="outputFile != 'None'" mode="'replace'">'%s' % outputFile</
stdout>
<
stderr mode="'stdout'"/>
<
elseif expr="inputFile != 'None'">
<
location>location</
location>
<
command>command</
command>
<
stdin>'%s' % inputFile</
stdin>
<
location>location</
location>
<
command>command</
command>
<
stdout if="outputFile != 'None'" mode="'replace'">'%s' % outputFile</
stdout>
<!-- The problem here is that STAXResult can either be a string, list or a map object --> cmdOutput=STAXResult[0][1]
<
if expr="expectedRC != 'noCheck'">
<
call function="'checktestRC'">
if var.__class__==[].__class__:
for i in range(len(var)):
if var.__class__==''.__class__:
return 'could not evaluate the following component: %s' % var
<
function-
arg-
def name="location" default="STAF_REMOTE_HOSTNAME">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="dsPath" % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)">
<
function-
arg-
description>
Pathname to installation root
</
function-
arg-
description>
<
function-
arg-
property name="type" value="pathname"/>
'Kill server running on %s at %s' % (location, dsPath)
<
call function="'runSTAFCommand'">
{ 'name' : 'Read server pid file',
if is_windows_platform(location):
<
call function="'runCommand'">
{ 'name' : 'Kill DS server',
<
return>STAXResult</
return>
<
function name="runSTAFCommand" >
A general wrapper to run a STAF command without having to write a
dedicated function for it
<
function-
arg-
def name="location" type="optional" default="STAXServiceMachine">
<
function-
arg-
description>
Which machine should the command be executed on
</
function-
arg-
description>
<
function-
arg-
def name="name" type="required">
<
function-
arg-
description>
The name to give the process
</
function-
arg-
description>
<
function-
arg-
def name="service" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
def name="request" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
def name="arguments" type="optional" default="''">
<
function-
arg-
description>
the arguments for the service request
</
function-
arg-
description>
_id = '%s#%d' % (strftime('%Y-%m-%d %H:%M:%S',localtime()),
random.randint(0,99999))
'%s: Running STAF command:\n %s %s %s\nlocation: %s\n' % (_id,service,request,arguments,location)
<
block name="'%s:Wrapper for %s' % (_id,name)">
<
stafcmd name="'STAF Command: %s' % name">
<
location>'%s' % location</
location>
<
service>service</
service>
'%s %s' % (request,arguments)
'%s: STAF Command returned:\n%s' % (_id,STAFResult)
This function search for a given string in a given file.
BEWARE! of potential performance degradation when grepping big files due
to the use of getFile, which loads the whole file content into a variable.
<
function-
arg-
def name="location" default="STAF_REMOTE_HOSTNAME">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="filename" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="pathname"/>
<
function-
arg-
def name="testString" type="required">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="expectedRC" type="optional" default="0">
<
function-
arg-
description>
Expected return code value.
0 for successful grep, 1 for unsuccessful grep. Default value is 0.
Wildcard 'noCheck' to not check the RC
</
function-
arg-
description>
'Search for string \"%s\" in file %s on host %s' % \
(testString, filename, location)
<
call function="'getFile'">
# getFile returns: STAXResult = [cmdRC, cmdResult]
filecontent = STAXResult[1]
if (expectedRC == 'noCheck'):
# don't care about expected result
# expect testString to be present in filecontent
# expect testString not to be present in filecontent
<
call function="'searchStringForSubstring'">
'testString' : testString,
'returnString' : filecontent,
'expectedResult' : myExpectedResult
<
return>STAXResult</
return>
<
function name="compareFile">
This function compares two files.
Print the differences if the comparison failed.
<
function-
arg-
def name="location" default="STAXServiceMachine">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="remotehost" default="STAF_REMOTE_HOSTNAME">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="dsPath" default="'%s/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)">
<
function-
arg-
description>
Pathname to installation root
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="outputFile" type="required">
<
function-
arg-
description>
file containing output from the command
</
function-
arg-
description>
<
function-
arg-
property name="type" value="file"/>
<
function-
arg-
def name="outputPath" type="optional">
<
function-
arg-
description>
path containing outputFile
</
function-
arg-
description>
<
function-
arg-
property name="type" value="filepath"/>
<
function-
arg-
def name="refFile" type="optional">
<
function-
arg-
description>
reference file containing expected output
</
function-
arg-
description>
<
function-
arg-
property name="type" value="file"/>
<
function-
arg-
def name="refPath" type="optional">
<
function-
arg-
description>
reference path containing refFile
</
function-
arg-
description>
<
function-
arg-
property name="type" value="filepath"/>
<
function-
arg-
def name="diffFile" type="optional">
<
function-
arg-
description>
file containing diff output
</
function-
arg-
description>
<
function-
arg-
property name="type" value="file"/>
<
function-
arg-
def name="diffPath" type="optional">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="filepath"/>
ThisGroupName = CurrentTestPath['group']
ThisGroupName = 'unknown-group'
FormattedTestcase = format_testcase()
outputPath = '%s/..' % (dsPath)
tmpName =
re.sub(regexp, '', outputFile)
refFile = '%
s.ref' % tmpName
refPath = '%s/%s' % (
local.data,FormattedTestgroup)
tmpName =
re.sub(regexp, '', outputFile)
diffFile = '%
s.diff' % tmpName
diffPath = '%
s/
diffs' % (diffPath)
<!-- Check if 'diffPath' is already created --> <
call function="'GetEntry'">
<!-- If 'diffPath' is not already created then create it --> 'Create folder %s' % diffPath
<
call function="'createFolder'">
'location' : cflocation ,
'Copy file %s/%s (on %s) to %s/%s (on %s)' % \
(outputPath, outputFile, cfremotehost, diffPath, outputFile, cflocation)
<
call function="'copyFile'">
'location' : cfremotehost ,
'srcfile' : '%s/%s' % (outputPath, outputFile) ,
'destfile' : '%s/%s' % (diffPath, outputFile) ,
'remotehost' : cflocation
'Copy file %s/%s (on %s) to %s/%s (on %s)' % \
(refPath, refFile, cflocation, diffPath, refFile, cflocation)
<
call function="'copyFile'">
'location' : cflocation ,
'srcfile' : '%s/%s' % (refPath, refFile) ,
'destfile' : '%s/%s' % (diffPath, refFile) ,
'remotehost' : cflocation
<!-- If the copy of 'outputFile' and 'refFile' succeed then compare these files --> <
if expr="outputRC == 0 and refRC == 0">
'Compare file %s/%s to %s/%s on %s' % \
(diffPath, outputFile, diffPath, refFile, cflocation)
CompareFile = compare_file('%s/%s' % (diffPath, outputFile),
'%s/%s' % (diffPath, refFile),
'%s/%s' % (diffPath, diffFile))
<
tcstatus result="'pass'"/>
'SUCCESS : No differences were found between %s and %s' % \
<
tcstatus result="'fail'"/>
'ERROR : Differences were found between %s and %s\n%s' % \
(outputFile, refFile, diff)
'ERROR : Diff file is here: %s/%s' % (diffPath, diffFile)
<
tcstatus result="'fail'"/>
'ERROR : Error during file comparision'
<
function name="compileJava" scope="local">
This function compile java files.
<
function-
arg-
def name="location" default="STAXServiceMachine">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="hostname"/>
<
function-
arg-
def name="foldername" type="required">
<
function-
arg-
description>
Path containing java files to compile
</
function-
arg-
description>
<
function-
arg-
property name="type" value="filepath"/>
<
function-
arg-
def name="classpath" type="optional">
<
function-
arg-
description>
</
function-
arg-
description>
<
function-
arg-
property name="type" value="string"/>
<
function-
arg-
def name="expectedRC" type="optional" default="0">
<
function-
arg-
description>
Expected return code value.
0 for successful grep, 1 for unsuccessful grep. Default value is 0.
Wildcard 'noCheck' to not check the RC
</
function-
arg-
description>
<!-- Build the command --> if is_windows_platform(location):
cp = 'CLASSPATH=%s%s.' % (classpath, separator)
if location == STAXServiceMachine:
env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]
<
call function="'listFolderByExtension'" >
'foldername' : foldername ,
<
if expr="cmdResult != 'Folder does not exist.'">
<
call function="'runCommand'" >
'name' : 'Compile Java files' ,
'arguments' : '-target 1.5 %s' % list ,
'expectedRC' : expectedRC
<
tcstatus result="'fail'"></
tcstatus>
<
function name="getFreePort" scope="local">
Returns the first free TCP port greater or equal to given number
<
function-
arg-
def name="host" default="STAXServiceMachine">
<
function-
arg-
description>
Which machine to look for the free port
</
function-
arg-
description>
<
function-
arg-
def name="port" type="required">
<
function-
arg-
description>
The minimal port number to be returned
</
function-
arg-
description>
# returns first free port in [port; port+5]
# if no free port in this interval, return -1
s = Socket(hostAddr, port)
<
function name="checkFileExists" scope="local">
Set testcase result to FAIL if file (as param) does not exist
<
function-
arg-
def name="file" type="required">
<
function-
arg-
description>
The file to check existence
</
function-
arg-
description>
<
tcstatus result="'fail'"/>
<
function name="checkFileNotExists" scope="local">
Set testcase result to FAIL if file (as param) exists
<
function-
arg-
def name="file" type="required">
<
function-
arg-
description>
The file to check absence
</
function-
arg-
description>
<
tcstatus result="'fail'"/>