utils.xml revision 4714
2788N/A<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2788N/A<!DOCTYPE stax SYSTEM "/stax.dtd">
2788N/A<!--
2788N/A ! CDDL HEADER START
2788N/A !
2788N/A ! The contents of this file are subject to the terms of the
2788N/A ! Common Development and Distribution License, Version 1.0 only
2788N/A ! (the "License"). You may not use this file except in compliance
2788N/A ! with the License.
2788N/A !
6982N/A ! You can obtain a copy of the license at
6982N/A ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
2788N/A ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2788N/A ! See the License for the specific language governing permissions
2788N/A ! and limitations under the License.
2788N/A !
6982N/A ! When distributing Covered Code, include this CDDL HEADER in each
6982N/A ! file and include the License file at
6982N/A ! trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
6982N/A ! add the following below this CDDL HEADER, with the fields enclosed
2788N/A ! by brackets "[]" replaced with your own identifying information:
2788N/A ! Portions Copyright [yyyy] [name of copyright owner]
2788N/A !
2788N/A ! CDDL HEADER END
5061N/A !
6063N/A ! Copyright 2007-2009 Sun Microsystems, Inc.
2788N/A ! -->
2788N/A<stax>
2788N/A <function name="checkRC">
3853N/A <function-prolog>
3853N/A This function checks a return code against an expected return code
3853N/A </function-prolog>
3853N/A
3853N/A <function-map-args>
3853N/A <function-arg-def name="returncode" type="required">
3853N/A <function-arg-description>
3853N/A return code received from command
3853N/A </function-arg-description>
3853N/A <function-arg-property name="type" value="integer"/>
3853N/A </function-arg-def>
3853N/A <function-arg-def name="result" type="required">
3853N/A <function-arg-description>
3853N/A the output of the result
3853N/A </function-arg-description>
3853N/A <function-arg-property name="type" value="integer"/>
3853N/A </function-arg-def>
3853N/A <function-arg-def name="expected" type="optional" default="0">
3853N/A <function-arg-description>
3853N/A the expected return code
3853N/A </function-arg-description>
3853N/A <function-arg-property name="type" value="integer"/>
3853N/A </function-arg-def>
3853N/A </function-map-args>
6304N/A
6304N/A <sequence>
6304N/A <if expr="expected == 'noCheck'">
6304N/A <return/>
6304N/A </if>
6304N/A <if expr="returncode == expected">
6304N/A <sequence>
6304N/A <if expr="result == ''">
6304N/A <message log="1">
6304N/A 'RC=%s, Result=Ok' % (returncode)
6304N/A </message>
6304N/A <else>
6304N/A <message log="1">
6304N/A 'RC=%s, Result=%s' % (returncode,result)
6304N/A </message>
6304N/A </else>
6304N/A </if>
6304N/A </sequence>
6304N/A <else>
6304N/A <sequence>
6304N/A <message log="1" level="'Error'">
6304N/A 'RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
6304N/A </message>
6304N/A </sequence>
6304N/A </else>
6304N/A </if>
6304N/A <return>RC</return>
6304N/A </sequence>
6304N/A </function>
6304N/A
6304N/A <function name="checktestRC">
6304N/A <function-prolog>
6304N/A This function checks the return code against an expected return code for a testcase
6304N/A </function-prolog>
6304N/A <function-map-args>
6304N/A <function-arg-def name="returncode" type="required">
6304N/A <function-arg-description>
6304N/A return code received from command
6304N/A </function-arg-description>
6304N/A <function-arg-property name="type" value="integer"/>
6304N/A </function-arg-def>
6304N/A <function-arg-def name="result" type="required">
6304N/A <function-arg-description>
6304N/A the output of the result
6304N/A </function-arg-description>
6304N/A <function-arg-property name="type" value="integer"/>
6304N/A </function-arg-def>
6387N/A <function-arg-def name="expected" type="optional" default="0">
6387N/A <function-arg-description>
6387N/A the expected return code
6387N/A </function-arg-description>
6387N/A <function-arg-property name="type" value="integer"/>
6387N/A </function-arg-def>
6387N/A <function-arg-def name="issue" type="optional" default="None">
6387N/A <function-arg-description>
6387N/A Issue id. Corresponds to an issue number.
6387N/A </function-arg-description>
6387N/A <function-arg-property name="type" value="string"/>
6387N/A </function-arg-def>
6387N/A </function-map-args>
6387N/A <sequence>
6387N/A <if expr="expected == 'noCheck'">
6387N/A <return/>
6387N/A </if>
6387N/A <if expr="returncode == expected">
6387N/A <sequence>
6387N/A <if expr="STAXCurrentTestcase != None">
6387N/A <sequence>
6387N/A <tcstatus result="'pass'"/>
6387N/A </sequence>
6387N/A </if>
6387N/A <if expr="VERBOSE_MODE == 'true'">
6304N/A <message log="1">
6387N/A 'SUCCESS: RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
6304N/A </message>
6387N/A <else>
6304N/A <message log="1">
6304N/A 'SUCCESS: RC=%s, Expected %s' % (returncode,expected)
6304N/A </message>
6304N/A </else>
6304N/A </if>
6304N/A <script>
6304N/A RC=0
6304N/A </script>
6304N/A </sequence>
6304N/A <else>
6304N/A <sequence>
6304N/A <if expr="STAXCurrentTestcase != None">
6304N/A <sequence>
6304N/A <if expr="issue == None">
6304N/A <tcstatus result="'fail'"/>
6304N/A <else>
6304N/A <sequence>
6304N/A <call function="'setKnownIssue'">
6304N/A { 'issueId' : issue }
6304N/A </call>
6304N/A </sequence>
6304N/A </else>
2788N/A </if>
4618N/A
2788N/A </sequence>
2788N/A </if>
4865N/A <message log="1" level="'Error'">
2788N/A 'ERROR : RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
3853N/A </message>
3853N/A </sequence>
3853N/A </else>
2788N/A </if>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A<!-- Set Known Issue -->
5764N/A <function name="setKnownIssue">
5764N/A <function-prolog>
5764N/A This function set the known issue flag and maintains list of known issues
5764N/A </function-prolog>
5764N/A
5764N/A <function-map-args>
5764N/A <function-arg-def name="issueId" type="required">
5764N/A <function-arg-description>
3853N/A Issue ID
3853N/A </function-arg-description>
4153N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A <sequence>
2788N/A <script>
2788N/A try:
2788N/A if issueId not in issuesList:
2788N/A issuesList.append(issueId)
2788N/A except:
2788N/A print 'Issues list undefined. Unable to add issue %s' % issueId
2788N/A </script>
2788N/A <message log="1" level="'Error'">
3853N/A 'ERROR: HIT **** Known Issue (%s) ****' % issueId
3853N/A </message>
3853N/A <tcstatus result="'fail'">
3853N/A 'KnownIssue: %s' % issuesList
3853N/A </tcstatus>
3853N/A </sequence>
3853N/A </function>
3853N/A
5551N/A<!-- testPassed -->
5551N/A<!-- Set the test status to PASS -->
5551N/A
5551N/A <function name="testPassed">
5551N/A <function-prolog>
5551N/A This function set the status of the tests: PASS
2788N/A </function-prolog>
2788N/A
2788N/A <sequence>
2788N/A <message>'Set test status to PASS'</message>
2788N/A <tcstatus result="'pass'"/>
4865N/A </sequence>
2788N/A </function>
2788N/A
2788N/A
2788N/A<!-- testFailed -->
2788N/A<!-- Set the test status to FAIL -->
2788N/A
2788N/A <function name="testFailed">
2788N/A <function-prolog>
2788N/A This function set the status of the tests: FAIL
2788N/A </function-prolog>
2788N/A
4865N/A <sequence>
2788N/A <message>'Set test status to FAIL'</message>
2788N/A <tcstatus result="'fail'"/>
2788N/A </sequence>
2788N/A </function>
2788N/A
4865N/A <!-- Search string -->
2788N/A <function name="searchString" scope="local">
2788N/A <function-prolog>
2788N/A This function search for a string in the retrun string of a testcase
2788N/A Return 0 if the string is found, 1 otherwise
2788N/A </function-prolog>
2788N/A
2788N/A <function-map-args>
2788N/A <function-arg-def name="expectedString" type="required">
2788N/A <function-arg-description>
2788N/A the substring expected from the command
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="returnString" type="required">
2788N/A <function-arg-description>
2788N/A the return string received from command
2788N/A </function-arg-description>
4865N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="knownIssue" type="optional" default="None">
2788N/A <function-arg-description>
2788N/A Known issue. Corresponds to an issue number.
2788N/A </function-arg-description>
3194N/A <function-arg-property name="type" value="string"/>
4618N/A </function-arg-def>
4618N/A <function-arg-def name="expectedRC" type="optional" default="0">
4618N/A <function-arg-description>
4618N/A Expected return code value. Default value is 0.
4618N/A Wildcard 'noCheck' to not check the RC
4618N/A </function-arg-description>
3951N/A <function-arg-property name="type" value="string"/>
3951N/A </function-arg-def>
3951N/A </function-map-args>
3951N/A
3951N/A <sequence>
2788N/A <script>
2788N/A searchre = re.compile('%s' % expectedString)
2788N/A myRC = 0
2788N/A myReason = 'None'
2788N/A </script>
6387N/A
6387N/A <!-- Check that returnString is really a string -->
6387N/A <if expr='returnString.__class__ is not org.python.core.PyString'>
6397N/A <sequence>
6387N/A <message log="1" level="'Error'">
6387N/A 'ERROR : Invalid returnString type (%s), requires org.python.core.PyString.' \
6387N/A % returnString.__class__
6387N/A </message>
6387N/A <script>
6387N/A myRC = 1
6387N/A myReason = 'Python error'
6387N/A </script>
6387N/A
6387N/A <return>[myRC, myReason]</return>
6387N/A </sequence>
2788N/A </if>
6387N/A
6397N/A <!-- Search for the expectedString -->
6397N/A <if expr='re.search(searchre, returnString) != None'>
6397N/A <sequence>
6387N/A <message log="1">
6397N/A 'Found substring, %s, in the return string' \
6397N/A % (expectedString)
6397N/A </message>
2788N/A <script>
2788N/A myRC = 0
6387N/A myReason = 'String found'
6387N/A </script>
6387N/A </sequence>
6387N/A <else>
6387N/A <sequence>
6387N/A <message log="1">
6387N/A 'Did not find substring, %s, in the return string, %s' \
6387N/A % (expectedString, returnString)
6387N/A </message>
6387N/A <script>
6391N/A myRC = 1
6391N/A myReason = 'String not found'
6391N/A </script>
6391N/A </sequence>
6391N/A </else>
6391N/A </if>
6391N/A
6391N/A <!-- Manage expectedRC and knownIssue -->
6391N/A <if expr="expectedRC != 'noCheck'">
6391N/A <if expr="myRC == expectedRC">
6391N/A <sequence>
6391N/A <message log="1">
6391N/A 'SUCCESS: searchString successful'
6391N/A </message>
6391N/A <tcstatus result="'pass'"/>
6391N/A </sequence>
6391N/A <else>
6391N/A <sequence>
6391N/A <message log="1" level="'Error'">
6391N/A 'ERROR: searchString fail'
6387N/A </message>
6387N/A <if expr="knownIssue == None">
6387N/A <tcstatus result="'fail'"/>
2788N/A <else>
2788N/A <call function="'setKnownIssue'">
6387N/A { 'issueId' : knownIssue }
2788N/A </call>
5764N/A </else>
5764N/A </if>
5764N/A </sequence>
2788N/A </else>
2788N/A </if>
2788N/A </if>
3853N/A
3853N/A <return>[myRC, myReason]</return>
3853N/A </sequence>
3853N/A </function>
5551N/A
5551N/A <!-- DEPRECATED, use searchString function -->
5551N/A <function name="checktestString">
5551N/A <function-prolog>
2788N/A This function checks the return string against an expected return substring for a testcase
2788N/A </function-prolog>
2788N/A
2788N/A <function-map-args>
2788N/A <function-arg-def name="expectedString" type="required">
2788N/A <function-arg-description>
2788N/A the substring expected from the command
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="returnString" type="required">
2788N/A <function-arg-description>
2788N/A the return string received from command
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="issue" type="optional" default="None">
2788N/A <function-arg-description>
2788N/A Known issue. Corresponds to an issue number.
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string" />
2788N/A </function-arg-def>
2788N/A </function-map-args>
4865N/A
2788N/A <sequence>
2788N/A <script>
2788N/A searchre = re.compile('%s' % expectedString)
2788N/A </script>
2788N/A
2788N/A <!-- Check that returnString is really a string -->
2788N/A <if expr='returnString.__class__ is not org.python.core.PyString'>
2788N/A <sequence>
2788N/A <message log="1" level="'Error'">
2788N/A 'ERROR : Invalid returnString type (%s), requires org.python.core.PyString.' % returnString.__class__
2788N/A </message>
3194N/A <tcstatus result="'fail'"/>
4618N/A </sequence>
3951N/A </if>
2788N/A <if expr='re.search(searchre, returnString) != None'>
2788N/A <sequence>
2788N/A <tcstatus result="'pass'"/>
2788N/A <message log="1">
2788N/A 'SUCCESS : Found substring, %s, in the return string' % (expectedString)
6103N/A </message>
6103N/A </sequence>
6103N/A <else>
6103N/A <sequence>
6103N/A <if expr="issue == None">
6103N/A <tcstatus result="'fail'"/>
6103N/A <else>
6103N/A <sequence>
6103N/A <call function="'setKnownIssue'">
6103N/A { 'issueId' : issue }
6103N/A </call>
6103N/A </sequence>
6103N/A </else>
6103N/A </if>
6103N/A <message log="1" level="'Error'">
6103N/A 'ERROR : Did not find substring, %s, in the return string, %s' % (expectedString, returnString)
6103N/A </message>
6103N/A </sequence>
6103N/A </else>
6103N/A </if>
6103N/A </sequence>
6103N/A </function>
6103N/A
6103N/A <!-- DEPRECATED, use searchString function -->
6103N/A <function name="checktestStringNotPresent">
6103N/A <function-prolog>
6103N/A This function checks the return string against an expected return substring that should not be present for a testcase
6103N/A </function-prolog>
6103N/A <function-map-args>
6103N/A <function-arg-def name="testString" type="required">
6103N/A <function-arg-description>
6103N/A the substring being tested from the command
6103N/A </function-arg-description>
6103N/A <function-arg-property name="type" value="string"/>
6103N/A </function-arg-def>
6103N/A <function-arg-def name="returnString" type="required">
6103N/A <function-arg-description>
6103N/A the return string received from command
6103N/A </function-arg-description>
6103N/A <function-arg-property name="type" value="string"/>
6103N/A </function-arg-def>
6103N/A <function-arg-def name="issue" type="optional" default="None">
6103N/A <function-arg-description>
6103N/A Known issue. Corresponds to an issue number.
6103N/A </function-arg-description>
6103N/A <function-arg-property name="type" value="string" />
6103N/A </function-arg-def>
6103N/A </function-map-args>
6103N/A
6103N/A <sequence>
6103N/A <script>
6103N/A searchre = re.compile('%s' % testString)
6103N/A </script>
6103N/A <if expr='re.search(searchre, returnString) == None'>
6103N/A <sequence>
6103N/A <tcstatus result="'pass'"/>
6103N/A <message log="1">
6103N/A 'Did Not Find substring, %s, in the return string' % (testString)
6103N/A </message>
6103N/A </sequence>
6103N/A <else>
6103N/A <sequence>
6103N/A <if expr="issue == None">
6103N/A <tcstatus result="'fail'"/>
6103N/A <else>
6103N/A <sequence>
6103N/A <call function="'setKnownIssue'">
6103N/A { 'issueId' : issue }
6103N/A </call>
6103N/A </sequence>
6103N/A </else>
6103N/A </if>
6103N/A <message log="1" level="'Error'">
6103N/A 'Found substring, %s, in the return string, %s' % (testString, returnString)
6103N/A </message>
6103N/A </sequence>
6103N/A </else>
6103N/A </if>
6103N/A </sequence>
6103N/A </function>
6103N/A
6103N/A <!-- DEPRECATED, use searchString function -->
6103N/A <function name="searchStringForSubstring">
6103N/A <function-prolog>
6103N/A This function simply searches a string for a substring
6103N/A </function-prolog>
6103N/A
6103N/A <function-map-args>
6103N/A <function-arg-def name="testString" type="required">
6103N/A <function-arg-description>
6103N/A the substring being tested from the command
6103N/A </function-arg-description>
6103N/A <function-arg-property name="type" value="string"/>
6103N/A </function-arg-def>
6103N/A <function-arg-def name="returnString" type="required">
6103N/A <function-arg-description>
6103N/A the return string received from command
6103N/A </function-arg-description>
6103N/A <function-arg-property name="type" value="string"/>
6103N/A </function-arg-def>
6103N/A <function-arg-def name="expectedResult" type="optional" default="'2'">
6103N/A <function-arg-description>
6103N/A the expected result, 0 for false (not present), 1 for true (present), 2 for old behavior
6103N/A </function-arg-description>
6103N/A <function-arg-property name="type" value="string"/>
6103N/A </function-arg-def>
6103N/A </function-map-args>
6103N/A
6103N/A <!-- Until all the test cases are refactored to use the expectedResult param,
6103N/A we need this if-else conditional. -->
6103N/A <sequence>
6103N/A <if expr="expectedResult == '2'">
6103N/A <sequence>
6103N/A <script>
6103N/A searchre = re.compile(testString)
6103N/A </script>
6103N/A <if expr='re.search(searchre, returnString) == None'>
6103N/A <sequence>
6103N/A <script>returnCode='0'</script>
6103N/A <message log="1">
6103N/A 'Did Not Find substring, %s, in the return string' % (testString)
6103N/A </message>
6103N/A </sequence>
6103N/A <else>
6103N/A <sequence>
6103N/A <script>returnCode='1'</script>
6103N/A <message log="1">
6103N/A 'Found substring, %s, in the return string' % (testString)
6103N/A </message>
6103N/A </sequence>
6103N/A </else>
6103N/A </if>
6103N/A <return>returnCode</return>
6103N/A </sequence>
6103N/A <else>
6103N/A <sequence>
6103N/A <script>
6103N/A searchre = re.compile(testString)
6103N/A </script>
6103N/A <if expr='re.search(searchre, returnString) == None'>
6103N/A <sequence>
6103N/A <script>returnCode='0'</script>
6103N/A <if expr="expectedResult == '0'">
6103N/A <sequence>
6103N/A <tcstatus result="'pass'"/>
6103N/A <message log="1">
6103N/A 'SUCCESS : Did Not Find substring, %s, in the return string' % (testString)
6103N/A </message>
6103N/A </sequence>
6103N/A <else>
6103N/A <sequence>
6103N/A <tcstatus result="'fail'"/>
6103N/A <message log="1" level="'Error'">
6103N/A 'ERROR : Did Not Find substring, %s, in the return string' % (testString)
6103N/A </message>
6103N/A </sequence>
6103N/A </else>
6103N/A </if>
2788N/A </sequence>
2788N/A <else>
2788N/A <sequence>
2788N/A <script>returnCode='1'</script>
2788N/A <if expr="expectedResult == '1'">
2788N/A <sequence>
2788N/A <tcstatus result="'pass'"/>
2788N/A <message log="1">
2788N/A 'SUCCESS : Found substring, %s, in the return string' % (testString)
2788N/A </message>
2788N/A </sequence>
2788N/A <else>
4865N/A <sequence>
2788N/A <tcstatus result="'fail'"/>
2788N/A <message log="1" level="'Error'">
2788N/A 'ERROR : Found substring, %s, in the return string' % (testString)
2788N/A </message>
2788N/A </sequence>
2788N/A </else>
2788N/A </if>
2788N/A </sequence>
2788N/A </else>
2788N/A </if>
4865N/A <return>returnCode</return>
2788N/A </sequence>
2788N/A </else>
2788N/A </if>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="isAlive" scope="local">
2788N/A <function-prolog>
2788N/A Checks that the ldap server is running
2788N/A </function-prolog>
2788N/A <function-map-args>
2788N/A <function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
2788N/A <function-arg-description>
2788N/A Location of target host
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="dsPath" type="optional" default="'%s/%s' % (DIRECTORY_INSTANCE_BIN,OPENDSNAME)">
2788N/A <function-arg-description>
2788N/A Pathname to installation root
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="pathname"/>
2788N/A </function-arg-def>
3194N/A <function-arg-def name="noOfLoops" type="required">
3194N/A <function-arg-description>
3194N/A Number of iterations
3194N/A </function-arg-description>
3194N/A <function-arg-property name="type" value="integer"/>
3194N/A </function-arg-def>
3194N/A <function-arg-def name="noOfMilliSeconds" type="required">
3951N/A <function-arg-description>
3951N/A Number of seconds to wait between iterations
3951N/A </function-arg-description>
3951N/A <function-arg-property name="type" value="seconds"/>
3951N/A </function-arg-def>
2788N/A <function-arg-def name="dsInstanceHost" type="optional" default="DIRECTORY_INSTANCE_HOST">
2788N/A <function-arg-description>
2788N/A Directory server hostname or IP address
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="dsInstancePort" type="optional" default="DIRECTORY_INSTANCE_PORT">
2788N/A <function-arg-description>
2788N/A Directory server port number
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="Port number"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="dsInstanceDn" type="optional" default="DIRECTORY_INSTANCE_DN">
2788N/A <function-arg-description>
2788N/A Bind DN
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="DN"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="dsInstancePswd" type="optional" default="DIRECTORY_INSTANCE_PSWD">
2788N/A <function-arg-description>
2788N/A Bind password
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A
2788N/A <sequence>
2788N/A <!-- Local variables -->
2788N/A <script>
2788N/A mylocation=location
2788N/A mypath=dsPath
2788N/A myhost=dsInstanceHost
2788N/A myport=dsInstancePort
2788N/A mydn=dsInstanceDn
5073N/A mypswd=dsInstancePswd
5073N/A </script>
5073N/A
5073N/A <script>
5073N/A myLoop=0
5073N/A ldapRC=9999
5073N/A </script>
5073N/A <loop from="1" to="noOfLoops" while="ldapRC != 0">
5073N/A <sequence>
5073N/A <script>
5073N/A myLoop=myLoop+1
5073N/A </script>
5073N/A
5073N/A <call function="'SearchObject'">
5073N/A { 'location' : mylocation,
5073N/A 'dsPath' : mypath,
5073N/A 'dsInstanceHost' : myhost ,
5073N/A 'dsInstancePort' : myport ,
5073N/A 'dsInstanceDn' : mydn ,
5073N/A 'dsInstancePswd' : mypswd ,
5116N/A 'dsScope' : 'base' ,
5073N/A 'dsBaseDN' : 'cn=config' ,
5073N/A 'dsFilter' : 'objectclass=*' ,
5073N/A 'attributes' : 'dn',
5073N/A 'expectedRC' : 'noCheck'
5073N/A }
5073N/A </call>
5073N/A
5073N/A <script>
5073N/A ldapRC=RC
5073N/A </script>
5073N/A
5073N/A <message>
5073N/A 'LOOP %s => RC=%s' % (myLoop, ldapRC)
5073N/A </message>
5073N/A
5073N/A <call function="'Sleep'">
5073N/A { 'sleepForMilliSeconds' : noOfMilliSeconds }
5073N/A </call>
5073N/A
5073N/A </sequence>
5073N/A </loop>
5073N/A
5073N/A <call function="'checktestRC'">
5073N/A { 'returncode' : ldapRC ,
5073N/A 'result' : 'Check is alive' }
5073N/A </call>
5073N/A </sequence>
5073N/A </function>
5073N/A
5073N/A <function name="Sleep">
5073N/A <function-prolog>
5073N/A Sleep for number of milliseconds
5073N/A </function-prolog>
5073N/A <function-map-args>
5073N/A <function-arg-def name="sleepForMilliSeconds" type="required">
5073N/A <function-arg-description>
5073N/A Number of milliseconds to sleep
5073N/A </function-arg-description>
5073N/A <function-arg-property name="type" value="seconds"/>
5073N/A </function-arg-def>
5073N/A </function-map-args>
5073N/A
5073N/A <sequence>
5073N/A <stafcmd name="'STAF Command: Delay'">
5073N/A <location>STAXServiceMachine</location>
5073N/A <service>'delay'</service>
5073N/A <request>
5073N/A 'delay %i' % sleepForMilliSeconds
5073N/A </request>
5073N/A </stafcmd>
5073N/A
5073N/A <call function="'checkRC'">
5073N/A { 'returncode' : RC ,
5073N/A 'result' : STAFResult }
5073N/A </call>
5073N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="getOSvariables">
2788N/A <function-prolog>
3194N/A Get OS related variables
3951N/A </function-prolog>
3951N/A <function-map-args>
2788N/A <function-arg-def name="hostname" type="required">
2788N/A <function-arg-description>
3194N/A Name of host on which to retrieve variables
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A <sequence>
2788N/A <stafcmd name="'STAF Command: Get OS Name'">
2788N/A <location>'%s' % hostname</location>
2788N/A <service>'var'</service>
2788N/A <request>
4865N/A 'get system var STAF/Config/OS/Name'
4865N/A </request>
3853N/A </stafcmd>
3853N/A <message>
3853N/A 'OS Name= %s' % STAFResult
2788N/A </message>
2788N/A <return>STAFResult</return>
2788N/A </sequence>
2788N/A </function>
2788N/A
3853N/A <function name="testCase_StartBanner">
3853N/A <function-prolog>
4153N/A Pretty prints a banner at the start of a test.
2788N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
2788N/A <message level="'start'">'testcase: %s' % STAXCurrentTestcase</message>
2788N/A <message>'****************************************************'</message>
2788N/A <message>'*** STARTING TEST CASE %s.' % STAXCurrentTestcase</message>
2788N/A <message>'***'</message>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="testCase_EndBanner">
3853N/A <function-prolog>
3853N/A Pretty prints a banner at the end of a test.
3853N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
2788N/A <message>'***'</message>
2788N/A <message>'*** ENDING TEST CASE %s.' % STAXCurrentTestcase</message>
2788N/A <message>'****************************************************'</message>
2788N/A <message level="'stop'">'testcase: %s' % STAXCurrentTestcase</message>
2788N/A </sequence>
2788N/A </function>
4865N/A
2788N/A <function name="testCase_Preamble">
2788N/A <function-prolog>
2788N/A Performs all the preoperations for a test case
2788N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
2788N/A <script>
2788N/A import time
2788N/A testcaseStart=int(time.time())
2788N/A testcaseStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
2788N/A issuesList=[]
2788N/A for logType in ['errors','access']:
2788N/A if os.path.exists('%s/%s/logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType)):
2788N/A logfile=open('%s/%s/logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType),'a')
2788N/A logfile.seek(0,2)
2788N/A logfile.write('Begin testcase %s\n' % STAXCurrentTestcase)
2788N/A logfile.close()
2788N/A </script>
2788N/A <call function="'testCase_StartBanner'" />
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="testCase_Postamble">
2788N/A <function-prolog>
2788N/A Performs all the post operations for a test suite
2788N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
2788N/A
2788N/A <!-- Check the SignalRaised flag -->
2788N/A <if expr="SignalRaised">
2788N/A <sequence>
2788N/A <message>
2788N/A 'A signal (%s) was raised during this test case' % SignalRaised
2788N/A </message>
4865N/A <tcstatus result="'fail'"/>
2788N/A </sequence>
2788N/A </if>
2788N/A
2788N/A <!-- Reset the SignalRaised flag -->
2788N/A <script>
4865N/A SignalRaised=''
2788N/A </script>
2788N/A
2788N/A <!-- Query the test case results -->
2788N/A <call function="'queryTestcase'" />
2788N/A
4865N/A <script>
2788N/A if STAFResult.has_key('numPasses'):
2788N/A numPass=int(STAFResult['numPasses'])
2788N/A else:
2788N/A numPass=int(0)
2788N/A
2788N/A if STAFResult.has_key('numFails'):
2788N/A numFail=int(STAFResult['numFails'])
2788N/A else:
2788N/A numFail=int(0)
2788N/A
2788N/A if numFail == 0:
2788N/A if numPass == 0:
2788N/A _status='INCONCLUSIVE'
2788N/A else:
2788N/A _status='PASS'
2788N/A else:
2788N/A if len(issuesList)==0:
2788N/A _status='FAIL'
2788N/A else:
2788N/A _status='KNOWN ISSUES %s' % str(issuesList)
2788N/A </script>
2788N/A <message level="'status'">'## Test Verdict: %s ##' % _status</message>
2788N/A <call function="'testCase_EndBanner'" />
4865N/A
2788N/A <script>
2788N/A testcaseEndTime = strftime("%Y%m%d@%H:%M:%S",localtime())
2788N/A </script>
2788N/A
2788N/A <call function="'queryLogs'">
2788N/A { 'location' : STAXServiceMachine,
2788N/A 'logname' : 'STAX_Job_%s_User' % STAXJobID,
2788N/A 'startfrom' : testcaseStartTime,
2788N/A 'endat' : testcaseEndTime }
2788N/A </call>
2788N/A
2788N/A <script>
2788N/A class Test:
2788N/A def __init__(self, group, suite, fullname, start, stop, failures, successes, issues, duration):
2788N/A self.message=[]
2788N/A self.log='%s/test.log' % local.temp
2788N/A self.errors='%s/error.log' % local.temp
4865N/A self.access='%s/access.log' % local.temp
2788N/A for f in [self.log,self.errors,self.access]:
2788N/A if os.path.exists(local.temp):
2788N/A fh=open(f,'w')
2788N/A fh.write('')
2788N/A fh.close()
2788N/A self.group=group
2788N/A self.suite=suite
2788N/A self.fullname=fullname
2788N/A self.start=start
2788N/A self.stop=stop
2788N/A tmp=fullname.split(":")
2788N/A if len(tmp) > 2:
4865N/A del tmp[0:2]
4865N/A self.name=''.join(tmp)
4865N/A else:
4865N/A self.name=fullname
4865N/A self.duration = duration
4865N/A if failures == 0:
4865N/A if successes == 0:
4865N/A self.result='inconclusive'
4865N/A else:
4865N/A self.result='pass'
4865N/A else:
4865N/A if len(issues) == 0:
4865N/A self.result='fail'
4865N/A else:
4865N/A self.result='known'
4865N/A self.issues=issues
3194N/A
3194N/A def toXML(self):
3194N/A xml = ' &lt;test&gt;%s' % newLine
3194N/A xml += ' &lt;name&gt;%s&lt;/name&gt;%s' % (self.name,newLine)
3194N/A xml += ' &lt;group&gt;%s&lt;/group&gt;%s' % (self.group,newLine)
3194N/A xml += ' &lt;suite&gt;%s&lt;/suite&gt;%s' % (self.suite,newLine)
3951N/A xml += ' &lt;start&gt;%s&lt;/start&gt;%s' % (self.start,newLine)
3951N/A xml += ' &lt;stop&gt;%s&lt;/stop&gt;%s' % (self.stop,newLine)
3951N/A xml += ' &lt;result&gt;%s&lt;/result&gt;%s' % (self.result,newLine)
3951N/A xml += ' &lt;duration&gt;%d&lt;/duration&gt;%s' % (self.duration,newLine)
3951N/A xml += ' &lt;issues&gt;%s' % newLine
2788N/A for issue in self.issues:
2788N/A xml += ' &lt;issue&gt;%s&lt;/issue&gt;%s' % (issue,newLine)
2788N/A xml += ' &lt;/issues&gt;%s' % newLine
2788N/A xml += ' &lt;log&gt;%s' % newLine
2788N/A xml += ' &lt;![CDATA[%s' % newLine
2788N/A if self.result!='pass':
2788N/A try:
2788N/A fh=open(self.log)
2788N/A xml += fh.read()
2788N/A fh.close()
2788N/A except IOError,details:
2788N/A self.message.append('IOError: Opening %s for reading %s' % (self.log,details.args))
2788N/A xml += ' ]]&gt;%s' % newLine
2788N/A xml += ' &lt;/log&gt;%s' % newLine
2788N/A xml += ' &lt;error&gt;%s' % newLine
2788N/A xml += ' &lt;![CDATA[%s' % newLine
3853N/A if self.result!='pass':
3853N/A try:
3853N/A fh=open(self.errors)
3853N/A xml += fh.read()
2788N/A fh.close()
2788N/A except IOError,details:
2788N/A self.message.append('IOError: Opening %s for reading %s' % (self.errors,details.args))
2788N/A xml += ' ]]&gt;%s' % newLine
2788N/A xml += ' &lt;/error&gt;%s' % newLine
2788N/A xml += ' &lt;access&gt;%s' % newLine
2788N/A xml += ' &lt;![CDATA[%s' % newLine
2788N/A if self.result!='pass':
2788N/A try:
2788N/A fh=open(self.access)
2788N/A xml += fh.read()
2788N/A fh.close()
2788N/A except IOError,details:
2788N/A self.message.append('IOError: Opening %s for reading %s' % (self.access,details.args))
2788N/A xml += ' ]]&gt;%s' % newLine
2788N/A xml += ' &lt;/access&gt;%s' % newLine
2788N/A xml += ' &lt;/test&gt;%s' % newLine
2788N/A return xml
2788N/A
2788N/A def appendLog(self, category, log):
2788N/A wrappedLog=''
2788N/A for _line in log.splitlines():
2788N/A _line=_line.strip()
2788N/A _leftPadding=''
2788N/A while len(_line)>100:
2788N/A _logChunk=_line[:100]
2788N/A _line=_line[100:]
2788N/A wrappedLog+='%s%s%s' % (_leftPadding,_logChunk,newLine)
2788N/A _leftPadding='... '
2788N/A wrappedLog += '%s%s%s' % (_leftPadding,_line,newLine)
2788N/A if category == 'access':
2788N/A try:
2788N/A fh=open(self.access,'a')
2788N/A except IOError,details:
2788N/A self.message.append('IOError: Opening %s for appending %s' % (self.access,details.args))
2788N/A elif category == 'error':
2788N/A try:
2788N/A fh=open(self.errors,'a')
2788N/A except IOError,details:
2788N/A self.message.append('IOError: Opening %s for appending %s' % (self.errors,details.args))
2788N/A else:
2788N/A try:
2788N/A fh=open(self.log,'a')
2788N/A except IOError,details:
2788N/A self.message.append('IOError: Opening %s for appending %s' % (self.log,details.args))
2788N/A fh.seek(0,2)
2788N/A fh.write(wrappedLog)
2788N/A fh.close()
2788N/A
2788N/A def getName(self):
2788N/A return self.name
2788N/A
5815N/A def clean(self):
5815N/A for _file in [self.log,self.errors,self.access]:
5815N/A if os.path.exists(_file):
2788N/A os.remove(_file)
2788N/A
2788N/A testcaseStop=int(time.time())
2788N/A testcaseDuration=testcaseStop-testcaseStart
2788N/A thisTest = Test(CurrentTestPath['group'],CurrentTestPath['suite'],STAXCurrentTestcase, testcaseStartTime,testcaseEndTime,numFail,numPass,issuesList,testcaseDuration)
2788N/A
2788N/A doLog = False
2788N/A
2788N/A # loop through the log lines
2788N/A for element in STAFResult:
3194N/A level=element['level']
3951N/A
3951N/A # this test is BEFORE the append so we don't get the
2788N/A # end of testcase banner in the XML but only the relevant data
2788N/A if level == 'Stop':
6103N/A doLog=False
6103N/A
6103N/A # if the current element is actually this test's output then log it
6103N/A if doLog == True:
6103N/A thisTest.appendLog('test',element['message'])
4865N/A
5061N/A # this test is AFTER the append log so we don't get the
5061N/A # "starting testcase ..." header in the XML
5061N/A if level == 'Start':
5061N/A tmp = element['message'].split(':')
5061N/A # this is a verification that we start logging for the right
5061N/A # test case. this is especially useful for tests that execute
5061N/A # within the same second (that is the resolution of the STAF
5061N/A # log facility)
5061N/A if thisTest.getName().startswith(tmp[3]):
5061N/A doLog=True
5061N/A
5061N/A # parse the server's error log
5061N/A # TODO: figure out how to do this for multiple instance for the replication
5061N/A # tests for example
5061N/A for logType in ['errors','access']:
5061N/A if os.path.exists('%s/%s/logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType)):
5061N/A logfile=open('%s/%s/logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType),'a')
5061N/A logfile.seek(0,2)
4865N/A logfile.write('End testcase %s\n' % STAXCurrentTestcase)
5815N/A logfile.close()
5815N/A logfile=open('%s/%s/logs/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME,logType), 'r')
5815N/A _log=''
5815N/A _doLog=False
5815N/A while True:
5815N/A line = logfile.readline()
5815N/A if not line:
5815N/A break
5815N/A if line.startswith('End testcase %s' % STAXCurrentTestcase):
5815N/A _doLog=False
5815N/A if _doLog:
5816N/A _log+=line
5815N/A if line.startswith('Begin testcase %s' % STAXCurrentTestcase):
6103N/A _doLog=True
6103N/A logfile.close()
6103N/A thisTest.appendLog(logType, _log)
6103N/A
2788N/A # save to test log
2788N/A testlog=open('%s/tests-log.xml' % logs.tests,'a')
2788N/A testlog.seek(0,2)
5073N/A testlog.write(thisTest.toXML())
5912N/A testlog.close()
2788N/A
5073N/A # clean the temporary log files for this test
2788N/A # this MUST be done AFTER the call to toXML or the logs will appear empty
2788N/A thisTest.clean()
5073N/A </script>
3853N/A
3853N/A <if expr="thisTest.message">
2788N/A <iterate in="thisTest.message" var="_message">
2788N/A <message>'%s' % _message</message>
2788N/A </iterate>
2788N/A </if>
2788N/A
5073N/A <script>thisTest.message=[]</script>
3853N/A
4153N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="testSuite_Preamble">
2788N/A <function-prolog>
2788N/A Performs all the pre operations for a test suite
2788N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
2788N/A
2788N/A <!-- Take the values from the current test path -->
2788N/A <script>
2788N/A if not CurrentTestPath.has_key('group'):
2788N/A CurrentTestPath['group']='unknown-group'
2788N/A
2788N/A if not CurrentTestPath.has_key('suite'):
2788N/A CurrentTestPath['suite']='unknown-suite'
2788N/A
5073N/A ThisGroupName=CurrentTestPath['group']
5073N/A ThisSuiteName=CurrentTestPath['suite']
5073N/A </script>
5073N/A
5073N/A <!-- Start time of test suite -->
5073N/A <script>
2788N/A TestSuiteStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
2788N/A </script>
2788N/A
2788N/A <message>
2788N/A '#### %s/%s suite preamble ####' % (ThisGroupName,ThisSuiteName)
4865N/A </message>
2788N/A
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="testSuite_Postamble">
4865N/A <function-prolog>
2788N/A Performs all the post operations for a test suite
2788N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
2788N/A
2788N/A <!-- Take the values from the current test path -->
2788N/A <script>
2788N/A if CurrentTestPath.has_key('suite'):
2788N/A ThisSuiteName=CurrentTestPath['suite']
2788N/A else:
2788N/A ThisSuiteName='unknown-suite'
2788N/A
5073N/A if CurrentTestPath.has_key('group'):
5073N/A ThisGroupName=CurrentTestPath['group']
5073N/A else:
2788N/A ThisGroupName='unknown-group'
2788N/A </script>
2788N/A
2788N/A <message>
2788N/A '#### %s/%s suite postamble ####' % (ThisGroupName,ThisSuiteName)
5073N/A </message>
5073N/A
5073N/A <!-- Start time of test suite -->
5073N/A <script>
5073N/A TestSuiteEndTime=strftime("%Y%m%d@%H:%M:%S",localtime())
5073N/A </script>
5184N/A
5073N/A <!-- Format the test group and suite names to create folder -->
5073N/A <script>
5073N/A FormattedTestcase=format_testcase()
5073N/A FormattedTestgroup=FormattedTestcase.group(ThisGroupName)
5073N/A FormattedTestsuite=FormattedTestcase.suite(ThisSuiteName)
5073N/A
5073N/A TestLogDir= '%s/%s' % (logs.tests,FormattedTestgroup)
5073N/A TestLogFile='%s/%s' % (TestLogDir,FormattedTestsuite)
2788N/A </script>
2788N/A
2788N/A <call function="'WriteLogsForTestCase'">
5073N/A { 'starttime' : TestSuiteStartTime,
5073N/A 'endtime' : TestSuiteEndTime,
5073N/A 'logFile' : TestLogFile }
5073N/A </call>
5073N/A
5073N/A <script>
5073N/A if CurrentTestPath.has_key('suite'):
5073N/A del CurrentTestPath['suite']
5073N/A </script>
2788N/A
2788N/A </sequence>
2788N/A </function>
5073N/A
5073N/A <function name="testGroup_Preamble">
5073N/A <function-prolog>
5073N/A Performs all the pre operations for a test group
5073N/A </function-prolog>
5073N/A <function-no-args />
5073N/A <sequence>
5073N/A <!-- Take the values from the current test path -->
5073N/A <script>
5073N/A if not CurrentTestPath.has_key('group'):
5073N/A CurrentTestPath['group']='unknown-group'
5073N/A
5073N/A ThisGroupName=CurrentTestPath['group']
5073N/A </script>
5073N/A <message>'##### %s group preamble #####' % ThisGroupName</message>
2788N/A </sequence>
2788N/A </function>
2788N/A
5073N/A <function name="testGroup_Postamble">
5073N/A <function-prolog>
5073N/A Performs all the post operations for a test group
2788N/A </function-prolog>
2788N/A <function-no-args />
2788N/A <sequence>
5073N/A
5073N/A <script>
5073N/A if CurrentTestPath.has_key('group'):
2788N/A ThisGroupName=CurrentTestPath['group']
2788N/A else:
2788N/A ThisGroupName='unknown-group'
5073N/A
5073N/A coverage='N/A'
5073N/A </script>
2788N/A
2788N/A <message>'##### %s group postamble #####' % ThisGroupName</message>
4865N/A
2788N/A <script>
2788N/A emmaJar='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
2788N/A </script>
2788N/A <if expr="os.path.exists(emmaJar)">
2788N/A <sequence>
2788N/A <script>
2788N/A coveragePath=os.path.join(LOGS_ROOT,'coverage')
2788N/A coverageEm=os.path.join(coveragePath,'coverage.em')
2788N/A ecPath=os.path.join(coveragePath,CurrentTestPath['group'])
2788N/A coverageEcs=[ os.path.join(ecPath,ec) for ec in os.listdir(ecPath) if ec.startswith('coverage') and ec.endswith('.ec')]
2788N/A coverageFiles=','.join(coverageEcs)
2788N/A coverageXml=os.path.join(ecPath,'coverage.xml')
2788N/A coverageHtml=os.path.join(ecPath,'coverage.html')
2788N/A srcPathPrefix = os.path.join(TMPDIR,"..","..","..","..","..","..","src")
2788N/A srcPaths = [ os.path.join(srcPathPrefix,"server"),
2788N/A os.path.join(srcPathPrefix,"ads"),
2788N/A os.path.join(srcPathPrefix,"server","org"),
2788N/A os.path.join(srcPathPrefix,"admin","defn","org"),
2788N/A os.path.join(srcPathPrefix,"snmp","src","org"),
2788N/A os.path.join(srcPathPrefix,"ads","org"),
2788N/A os.path.join(srcPathPrefix,"dsml","org"),
2788N/A os.path.join(srcPathPrefix,"messages","src","org")
2788N/A ]
2788N/A srcArgs = " -sp ".join(srcPaths)
2788N/A </script>
2788N/A <call function="'runCommand'">
2788N/A { 'name' : 'Generate coverage xml report for test group %s' % CurrentTestPath['group'],
2788N/A 'command' : 'java',
2788N/A 'arguments' : ' -Xms64M -Xmx1G -cp %s emma report -r html -in %s,%s -Dreport.html.out.file=%s -sp %s' % (emmaJar, coverageEm, coverageFiles, coverageHtml, srcArgs),
4865N/A 'path' : TMPDIR
2788N/A }
2788N/A </call>
2788N/A <script>
2788N/A from java.io import FileInputStream
2788N/A from javax.xml.transform.stream import StreamSource
2788N/A from javax.xml.transform.stream import StreamResult
5073N/A from javax.xml.parsers import DocumentBuilderFactory
5073N/A from org.w3c.dom import *
5073N/A
5073N/A factory = DocumentBuilderFactory.newInstance()
5073N/A builder = factory.newDocumentBuilder()
5073N/A
5073N/A input = FileInputStream("%s/coverage/%s/coverage.xml" % (TMPDIR,CurrentTestPath['group']))
5073N/A document = builder.parse(input)
5073N/A dom = document.getDocumentElement()
5073N/A coverageNodes = dom.getElementsByTagName("all").item(0).getChildNodes()
5073N/A for coverageNodeIndex in range(coverageNodes.getLength()):
5073N/A thisNode = coverageNodes.item(coverageNodeIndex)
2788N/A if thisNode.getNodeName() == 'coverage':
2788N/A thisNodeAttributes = thisNode.getAttributes()
2788N/A if thisNodeAttributes.getNamedItem("type").getNodeValue() == 'block, %':
2788N/A rawCoverage = thisNodeAttributes.getNamedItem("value").getNodeValue()
2788N/A coverage = rawCoverage.split('%')[0]
4865N/A testlog=open('%s/tests-log.xml' % logs.tests,'a')
2788N/A testlog.seek(0,2)
2788N/A testlog.write(" &lt;group&gt;\n")
2788N/A testlog.write(" &lt;name&gt;\n")
2788N/A testlog.write(" %s\n" % CurrentTestPath['group'])
2788N/A testlog.write(" &lt;/name&gt;\n")
4865N/A testlog.write(" &lt;coverage&gt;\n")
3289N/A testlog.write(" %s\n" % coverage)
3289N/A testlog.write(" &lt;/coverage&gt;\n")
3289N/A testlog.write(" &lt;/group&gt;\n")
3289N/A testlog.close()
3289N/A </script>
4865N/A </sequence>
4865N/A <else>
3951N/A <script>
3951N/A testlog=open('%s/tests-log.xml' % logs.tests,'a')
3951N/A testlog.seek(0,2)
3951N/A testlog.write(" &lt;group&gt;\n")
4865N/A testlog.write(" &lt;name&gt;\n")
5073N/A testlog.write(" %s\n" % CurrentTestPath['group'])
5073N/A testlog.write(" &lt;/name&gt;\n")
5073N/A testlog.write(" &lt;coverage&gt;\n")
5073N/A testlog.write(" N/A\n")
5073N/A testlog.write(" &lt;/coverage&gt;\n")
5073N/A testlog.write(" &lt;/group&gt;\n")
5073N/A testlog.close()
5073N/A </script>
5073N/A </else>
2788N/A </if>
5073N/A
2788N/A <script>
5073N/A if CurrentTestPath.has_key('group'):
2788N/A del CurrentTestPath['group']
2788N/A </script>
5073N/A </sequence>
5073N/A </function>
2788N/A
2788N/A <function name="WriteLogsForTestCase" scope="local">
5073N/A
5073N/A <function-prolog>
5073N/A Queries the staf logs for the test case and write to file as text
2788N/A </function-prolog>
5912N/A <function-map-args>
5912N/A <function-arg-def name="starttime" type="required">
5073N/A <function-arg-description>
5073N/A timestamp to start logging from
5073N/A </function-arg-description>
5073N/A <function-arg-property name="type" value="timestamp"/>
5073N/A </function-arg-def>
5073N/A <function-arg-def name="endtime" type="required">
5073N/A <function-arg-description>
5073N/A timestamp to start logging to
5073N/A </function-arg-description>
5073N/A <function-arg-property name="type" value="timestamp"/>
5073N/A </function-arg-def>
5073N/A <function-arg-def name="logFile" type="required">
5073N/A <function-arg-description>
5073N/A name of file to write the logs
5073N/A </function-arg-description>
5073N/A <function-arg-property name="type" value="filepath"/>
5073N/A </function-arg-def>
5073N/A </function-map-args>
5073N/A
5073N/A <sequence>
5073N/A
5073N/A <script>
5073N/A xmlFile = '%s-log.xml' % logFile
5912N/A htmlFile = '%s-log.html' % logFile
5073N/A xslFile = '%s/gen-logs.xsl' % TESTS_XSL_DIR
5073N/A </script>
5073N/A
5912N/A <!-- Query STAF to obtain the logs for the test case -->
5073N/A <call function="'queryLogs'">
5073N/A { 'location' : STAXServiceMachine,
5073N/A 'logname' : 'STAX_Job_%s_User' % STAXJobID,
5073N/A 'startfrom' : starttime,
5073N/A 'endat' : endtime }
5073N/A </call>
5073N/A
5073N/A <!-- Write out the logs into an XML file -->
5073N/A <call function="'WriteXmlLogs'">
5073N/A { 'queryresult' : STAFResult,
5073N/A 'output' : xmlFile }
5073N/A </call>
5073N/A
5073N/A <!-- Transform the XML file into an HTML file -->
5073N/A <call function="'WriteHtmlLogs'">
5073N/A { 'input' : xmlFile,
5073N/A 'stylesheet' : xslFile,
5073N/A 'output' : htmlFile }
5073N/A </call>
5073N/A
5073N/A </sequence>
5073N/A
5073N/A </function>
5073N/A
5073N/A <function name="WriteXmlLogs" scope="local">
5073N/A
5073N/A <function-prolog>
5073N/A Process staf log query results and write them to a file
5073N/A </function-prolog>
5073N/A <function-map-args>
5073N/A <function-arg-def name="queryresult" type="required">
5073N/A <function-arg-description>
5073N/A result of the staf log query
5073N/A </function-arg-description>
5073N/A <function-arg-property name="type" value="string"/>
5073N/A </function-arg-def>
5073N/A <function-arg-def name="output" type="required">
5073N/A <function-arg-description>
5073N/A name of the XML file to where results are written
5073N/A </function-arg-description>
5073N/A <function-arg-property name="type" value="string"/>
5073N/A </function-arg-def>
5073N/A </function-map-args>
5073N/A
5073N/A <sequence>
5073N/A
5073N/A <script>
5073N/A logFile=output
5073N/A NewLogDir=os.path.dirname(logFile)
5073N/A </script>
5073N/A
5073N/A <message>'Creating XML log file %s' % logFile</message>
2788N/A
5073N/A <call function="'createFolder'">
5912N/A { 'location' : STAXServiceMachine,
5912N/A 'foldername' : NewLogDir }
5912N/A </call>
5912N/A
5912N/A <script>
5912N/A from xml.dom.minidom import Document
5073N/A doc = Document()
5073N/A
5073N/A # Create the qa base element
5912N/A qa = doc.createElement("qa")
5073N/A doc.appendChild(qa)
5073N/A
5073N/A # Create the base element
5073N/A logs = doc.createElement("logs")
2788N/A qa.appendChild(logs)
5073N/A
5073N/A # Try to pass only the pretty print of the test suite name
5073N/A try:
5073N/A suite=CurrentTestPath['suite'].split('.')[2].strip()
5073N/A except:
5073N/A formattedTestcase = format_testcase()
5073N/A suite = formattedTestcase.suite(CurrentTestPath['suite'])
5073N/A
2788N/A # Create the log element
3269N/A log = doc.createElement("log")
3269N/A log.setAttribute("group", "%s" % CurrentTestPath['group'])
5815N/A log.setAttribute("suite", "%s" % suite)
5073N/A log.setAttribute("jobid", "%s" % STAXJobID)
3269N/A log.setAttribute("parent", "%s" % STAXParentID)
5073N/A logs.appendChild(log)
5073N/A </script>
2788N/A
5073N/A <if expr="queryresult == '[]'">
5073N/A <sequence>
5073N/A <script>
5073N/A output1 = 'queryresult is empty'
5073N/A output2 = 'check the date between the OS, the logs'
5073N/A output3 = 'and the local time zone'
5073N/A output = '%s %s %s' % (output1,output2,output3)
5073N/A </script>
5073N/A <call function="'checktestRC'">
5073N/A { 'returncode' : '1' ,
5073N/A 'result' : output,
5073N/A 'expected' : '0' }
5073N/A </call>
3289N/A </sequence>
2788N/A <else>
2788N/A <iterate var="element" in="queryresult">
5073N/A <script>
5073N/A level=element['level']
5073N/A message=element['message']
2788N/A timestamp=element['timestamp']
2788N/A
2788N/A line = doc.createElement("line")
2788N/A line.setAttribute("timestamp", "%s" % timestamp)
2788N/A line.setAttribute("level", "%s" % level)
5476N/A line.setAttribute("message", "%s" % message)
2788N/A if level == 'Start':
2788N/A tag=get_test_name(message.replace('testcase: ',''))
2788N/A line.setAttribute("tag", "%s" % tag.lower())
2788N/A log.appendChild(line)
3853N/A </script>
3853N/A </iterate>
3853N/A </else>
2788N/A </if>
2788N/A
2788N/A <script>
2788N/A _message='Generated XML test case report.'
2788N/A testlogfh=open('%s' % logFile,'w')
3853N/A try:
3853N/A testlogfh.writelines(doc.toprettyxml(indent=" "))
4153N/A except AttributeError,details:
2788N/A _message='Unable to generate XML test case report %s.' % details
2788N/A except:
2788N/A _message='Unable to generate XML test case report !!!'
2788N/A testlogfh.close()
2788N/A </script>
3853N/A
3853N/A <message>_message</message>
3853N/A
2788N/A </sequence>
2788N/A
2788N/A </function>
2788N/A
4865N/A <function name="WriteHtmlLogs" scope="local">
3853N/A
3853N/A <function-prolog>
3853N/A Process XML file and transform that to an HTML log file
2788N/A </function-prolog>
2788N/A <function-map-args>
2788N/A <function-arg-def name="input" type="required">
2788N/A <function-arg-description>
2788N/A name of the XML file to where results are obtained
3853N/A </function-arg-description>
3853N/A <function-arg-property name="type" value="string"/>
3853N/A </function-arg-def>
3853N/A <function-arg-def name="output" type="required">
3853N/A <function-arg-description>
3853N/A name of the HTML file to where results are written
3853N/A </function-arg-description>
3853N/A <function-arg-property name="type" value="string"/>
3853N/A </function-arg-def>
3853N/A <function-arg-def name="stylesheet" type="required">
3853N/A <function-arg-description>
2788N/A name of the XSL stylesheet used to transform results
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
4865N/A </function-map-args>
3853N/A
3853N/A <sequence>
3853N/A
2788N/A <script>
2788N/A xmlFile=input
2788N/A htmlFile=output
2788N/A xslFile=stylesheet
4865N/A </script>
5476N/A
5476N/A <message>'Inputting XML file %s' % xmlFile</message>
5476N/A <message>'Transform XSL file %s' % xslFile</message>
5476N/A <message>'Creating HTML file %s' % htmlFile</message>
5476N/A
5476N/A <script>
2788N/A _message='Generated test case logs.'
2788N/A testCaseLogs=report_generation()
2788N/A stringParamsDict={}
2788N/A
2788N/A try:
2788N/A testCaseLogs.transformReport(xslFile,xmlFile,htmlFile,stringParamsDict)
3853N/A except java.io.FileNotFoundException,details:
3853N/A _message='Unable to generate test case logs %s.' % details
3853N/A except IOError,details:
2788N/A _message='Unable to generate test case logs %s.' % details
2788N/A except:
2788N/A _message='Unable to generate test case logs !!!'
2788N/A </script>
2788N/A
3853N/A <message>'%s' % _message</message>
3853N/A
3853N/A </sequence>
2788N/A
2788N/A </function>
2788N/A
2788N/A <function name="CheckMatches">
4865N/A <function-prolog>
3853N/A check the number of matching sub-string in a string
3853N/A </function-prolog>
3853N/A <function-map-args>
2788N/A <function-arg-def name="string2find" type="required">
2788N/A <function-arg-description>
2788N/A the sub-string to check
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
5476N/A </function-arg-def>
5476N/A <function-arg-def name="mainString" type="required">
5476N/A <function-arg-description>
5476N/A the main string where the search is done
5476N/A </function-arg-description>
5476N/A <function-arg-property name="type" value="string"/>
5476N/A </function-arg-def>
5476N/A <function-arg-def name="caseSensitive" type="optional" default="True">
3853N/A <function-arg-description>
3853N/A comparison using case sensitive, or not value is : True/False
3853N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="nbExpected" type="optional" default="1">
2788N/A <function-arg-description>
2788N/A number of expected sub-string that must be in the main string
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="integer"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="issue" type="optional" default="None">
2788N/A <function-arg-description>
2788N/A Issue id. Corresponds to an issue number.
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A
2788N/A <sequence>
2788N/A <script>
2788N/A caseSensitiveInfo = '[case sensitive mode]'
2788N/A
2788N/A if caseSensitive == False:
3853N/A string2find = string2find.lower()
2788N/A mainString = mainString.lower()
2788N/A caseSensitiveInfo = '[case insensitive mode]'
5476N/A
2788N/A nbFound = mainString.count(string2find)
2788N/A if nbFound == nbExpected:
2788N/A myMessage = 'SUCCESS : %s matches %s time(s) (expected %s) %s' % (string2find,nbFound,nbExpected,caseSensitiveInfo)
2788N/A myRC=0
2788N/A else:
2788N/A myMessage = 'ERROR : %s matches %s time(s) (expected %s) in "%s" %s' % (string2find,nbFound,nbExpected,mainString,caseSensitiveInfo)
2788N/A myRC=1
2788N/A </script>
2788N/A <if expr="myRC == 0">
2788N/A <sequence>
2788N/A <tcstatus result="'pass'"/>
2788N/A <message log="1">
2788N/A '%s' % myMessage
2788N/A </message>
2788N/A </sequence>
2788N/A <else>
2788N/A <sequence>
2788N/A <if expr="issue == None">
2788N/A <tcstatus result="'fail'"/>
2788N/A <else>
2788N/A <sequence>
2788N/A <call function="'setKnownIssue'">
2788N/A { 'issueId' : issue }
2788N/A </call>
2788N/A </sequence>
2788N/A </else>
2788N/A </if>
4153N/A <message log="1" level="'Error'">
2788N/A '%s' % myMessage
2788N/A </message>
2788N/A </sequence>
2788N/A </else>
2788N/A </if>
5476N/A <return>myRC,myMessage</return>
5476N/A </sequence>
5476N/A </function>
5476N/A
5476N/A <function name="runFunction" scope="local">
5476N/A <function-map-args>
5476N/A <function-arg-def name="functionName" type="required">
5476N/A <function-arg-description>
5540N/A Name of the function to run
5540N/A </function-arg-description>
5540N/A </function-arg-def>
5476N/A
5476N/A <function-arg-def name="functionArguments" type="optional">
5476N/A <function-arg-description>
5476N/A Arguments to be passed on to the called function.
5476N/A This can be a map or a list of arguments, whatever the called function
5476N/A expects will be carried on here.
5476N/A . for a map, pass the arguments like this:
5476N/A { 'argumentA' : 'argumentAvalue' ,
5476N/A 'argumentB' : 1 ,
5476N/A ...
5476N/A }
5476N/A . for a list, pass the arguments like this:
5476N/A [ 'argumentAvalue, 1, ... ]
5476N/A </function-arg-description>
5476N/A </function-arg-def>
5476N/A
5476N/A <function-arg-def name="expectedRC" type="optional" default="0">
5476N/A <function-arg-description>
5476N/A The expected return code of the function to run.
5476N/A This is then passed onto the checkRC function.
5476N/A It is also used to throw an exception if the argument
5476N/A functionException is provided and set the test case status if the
5476N/A argument functionSetsTCStatus is provided
5476N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="integer"/>
2788N/A </function-arg-def>
2788N/A
5476N/A <function-arg-def name="functionException" type="optional">
5540N/A <function-arg-description>
5540N/A The exception to throw if the return code differs from the expected
5540N/A RC. The exception is appended to STAXException.
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A
2788N/A <function-arg-def name="functionMessage" type="optional">
4673N/A <function-arg-description>
4673N/A An optional message to display before running the function
5476N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A
2788N/A <function-arg-def name="functionSetsTCStatus" type="optional">
2788N/A <function-arg-description>
2788N/A Whether the function to run sets the testcase status or not.
2788N/A If this is set, the test case status is set according to whether
2788N/A or not the function meets the expected return code.
2788N/A True or False should be used for this argument.
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A
2788N/A <function-arg-def name="functionFailureTC" type="optional">
2788N/A <function-arg-description>
2788N/A If this argument is provided, a testcase will be created with
2788N/A this argument's value for name and set to fail only upon failure
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A
2788N/A <function-arg-def name="functionSignal" type="optional">
4673N/A <function-arg-description>
2788N/A If this argument is provided, a signal will be raised upon unsuccesful
4673N/A execution of the function to run
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A
2788N/A <function-arg-def name="functionCallBack" type="optional">
2788N/A <function-arg-description>
2788N/A If this argument is provided then functionCallBack will be called
2788N/A after the execution of function name.
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A
3853N/A <function-arg-def name="functionCallBackArguments" type="optional">
3853N/A <function-arg-description>
3853N/A This allows to specify arguments for the call back function
3853N/A </function-arg-description>
3853N/A </function-arg-def>
3853N/A </function-map-args>
4865N/A <sequence>
2788N/A <script>
2788N/A <!-- defining the booleans here should temporary while I find a nicer
2788N/A solution. We have a chicken and egg problem between the
2788N/A loadGlobalEnvironment and loadSharedLibraries functions in
4865N/A environment.xml at the moment.
5912N/A -->
2788N/A if not False:
2788N/A False=0
2788N/A
2788N/A if not True:
2788N/A True=1
2788N/A
2788N/A _expectedRC=int(expectedRC)
2788N/A
2788N/A _throwException=False
2788N/A if functionException:
4153N/A _throwException=True
2788N/A
2788N/A _displayMessage=False
2788N/A if functionMessage:
2788N/A _displayMessage=True
2788N/A
2788N/A _tcStatus='fail'
2788N/A _doSetTCStatus=False
2788N/A if functionSetsTCStatus:
2788N/A _doSetTCStatus=True
2788N/A
2788N/A _createFailureTC=False
2788N/A if functionFailureTC:
2788N/A _createFailureTC=True
2788N/A </script>
2788N/A <message log="1" level="'info'" if="_displayMessage == True">
2788N/A '%s' % functionMessage
2788N/A </message>
4865N/A <message log="1" level="'debug'">
4865N/A 'runFunction: %s: called with parameters [%s]' % (functionName,functionArguments)
4865N/A </message>
4865N/A <call function="functionName">functionArguments</call>
4865N/A <script>
4865N/A _functionRC = int(RC)
2788N/A _functionResult = STAXResult
2788N/A </script>
2788N/A
2788N/A <!-- this section handles the optional case when we need to set the
2788N/A test case status
4865N/A -->
2788N/A <if expr="_doSetTCStatus == True">
2788N/A <sequence>
2788N/A <if expr="_functionRC == _expectedRC">
2788N/A <script>_tcStatus='pass'</script>
2788N/A </if>
4865N/A <tcstatus result="_tcStatus" />
2788N/A </sequence>
2788N/A </if>
2788N/A
2788N/A <!-- this section handles the optional case when we need to throw an
2788N/A exception upon unexpected function return code
2788N/A -->
2788N/A <if expr="_throwException == True" >
2788N/A <if expr="_functionRC != _expectedRC" >
2788N/A <throw exception="'STAXException.%s' % functionException" />
2788N/A </if>
2788N/A </if>
2788N/A
2788N/A <!-- this section handles the optional case when we need to set a
2788N/A test case status to fail to reflect the failure in the test report.
2788N/A -->
2788N/A <if expr="_createFailureTC == True" >
2788N/A <if expr="_functionRC != _expectedRC" >
2788N/A <testcase name="'!!! %s [%s]' % (functionFailureTC,functionName)">
4865N/A <tcstatus result="'fail'" />
4865N/A </testcase>
4865N/A </if>
4865N/A </if>
4865N/A
4865N/A <!-- TODO: implement the signal raising mechanism -->
5184N/A <!-- TODO: implement the call back function mechanism -->
4865N/A
4865N/A <!-- bubble the function return code and result up one level -->
4865N/A <return>[_functionRC,_functionResult]</return>
4865N/A </sequence>
4865N/A </function>
4865N/A
2788N/A <function name="runCommand" >
2788N/A <function-description>
2788N/A A general wrapper to run a command without having to write a dedicated
2788N/A function for it
2788N/A </function-description>
4865N/A <function-map-args>
2788N/A <function-arg-def name="command" type="required">
2788N/A <function-arg-description>
2788N/A the command to run
2788N/A </function-arg-description>
2788N/A </function-arg-def>
4865N/A <function-arg-def name="path" type="optional" default="dsBinPath">
2788N/A <function-arg-description>
2788N/A the path where the command is to be run from
2788N/A </function-arg-description>
2788N/A </function-arg-def>
4865N/A <function-arg-def name="arguments" type="optional" default="''">
2788N/A <function-arg-description>
2788N/A the path where the command is to be found
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="envCmd"
2788N/A type="optional"
2788N/A default="''">
2788N/A <function-arg-description>
2788N/A the environment variables to set. The default set here should just
2788N/A work for OpenDS commands
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="location"
2788N/A type="optional"
2788N/A default="STAXServiceMachine">
2788N/A <function-arg-description>
2788N/A Which machine should the command be executed on
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="name"
2788N/A default="'Running %s' % command"
2788N/A type="optional">
2788N/A <function-arg-description>
2788N/A The name to give the process (only matters in the STAX Monitor really)
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="stripOutput" default="True" type="optional">
2788N/A <function-arg-description>
2788N/A A boolean (use True or False here, case matters) to enable disable
4865N/A stripping the output of a command
2788N/A TODO: consider allowing passing a function name to enable custom
2788N/A output manipulation (overkill?)
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="enum">
2788N/A <function-arg-property-description>
2788N/A This argument can only have boolean values
4865N/A </function-arg-property-description>
2788N/A <function-arg-property-data type="choice" value="True"/>
2788N/A <function-arg-property-data type="choice" value="False"/>
2788N/A </function-arg-property>
4865N/A </function-arg-def>
4865N/A <function-arg-def name="timerDuration"
4865N/A type="optional"
4865N/A default="'5m'">
4865N/A <function-arg-description>
4865N/A The duration that the process is allowed to run
4865N/A </function-arg-description>
2788N/A </function-arg-def>
3406N/A <function-arg-def name="inputFile" type="optional" default="'None'">
3406N/A <function-arg-description>
3406N/A input file containing the command input
3406N/A </function-arg-description>
3406N/A <function-arg-property name="type" value="file"/>
4865N/A </function-arg-def>
4865N/A <function-arg-def name="outputFile" type="optional" default="'None'">
4865N/A <function-arg-description>
4865N/A Output file containing the command output
4865N/A </function-arg-description>
4865N/A <function-arg-property name="type" value="file"/>
4865N/A </function-arg-def>
4865N/A <function-arg-def name="expectedRC" type="optional" default="0">
4865N/A <function-arg-description>
3406N/A Expected return code value. Default value is 0.
3951N/A Wildcard 'noCheck' to not check the RC
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="knownIssue" type="optional" default="None">
2788N/A <function-arg-description>
2788N/A Known issue. Corresponds to an issue number.
2788N/A </function-arg-description>
4865N/A </function-arg-def>
4865N/A <function-arg-def name="logStderr" type="optional" default="True">
2788N/A <function-arg-description>
2788N/A If true, stderr for the command is redirect to stdout.
4865N/A </function-arg-description>
4865N/A <function-arg-property name="type" value="enum">
2788N/A <function-arg-property-description>
2788N/A This argument can only have boolean values
5912N/A </function-arg-property-description>
5912N/A <function-arg-property-data type="choice" value="True"/>
4865N/A <function-arg-property-data type="choice" value="False"/>
4865N/A </function-arg-property>
4865N/A </function-arg-def>
4865N/A </function-map-args>
4865N/A <sequence>
4865N/A <script>
4865N/A import random
4865N/A import java.util.Date
5912N/A random.seed(java.util.Date().getTime())
4865N/A _id = '%s#%d' % (strftime('%Y-%m-%d %H:%M:%S',localtime()),random.randint(0,999))
4865N/A
4865N/A env=[]
4865N/A for item in envCmd:
2788N/A env.append('%s' % item)
4865N/A if is_windows_platform(location):
4865N/A env.append('PATH=%s\\bin;C:\\Windows;C:\\Windows\\system32;%s' % (REMOTE_STAF_ROOT,path))
4865N/A env.append('JAVA_HOME=%s' % JAVA_HOME)
4865N/A else:
4865N/A env.append('PATH=/bin:/usr/bin:%s' % path)
2788N/A env.append('JAVA_HOME=%s' % JAVA_HOME)
4865N/A </script>
4865N/A <message>
4865N/A '%s: Running command:\n %s %s\nlocation: %s\nenv: %s\nworkdir: %s' % (_id,command,arguments,location,env,path)
4865N/A </message>
4865N/A
4865N/A <!-- If 'logStderr' is True then redirect sdterr to sdtout -->
4865N/A <if expr="logStderr == True">
4865N/A <process name="name">
2788N/A <location>location</location>
4865N/A <command>command</command>
4865N/A <parms>arguments</parms>
4865N/A <workdir>path</workdir>
4865N/A <envs>env</envs>
4865N/A <console use="'same'"/>
4865N/A <stdout if="outputFile != 'None'" mode="'replace'">'%s' % outputFile</stdout>
4865N/A <stderr mode="'stdout'"/>
4865N/A <returnstdout/>
4865N/A </process>
4865N/A <elseif expr="inputFile != 'None'">
4865N/A <process name="name">
4865N/A <location>location</location>
4865N/A <command>command</command>
4865N/A <parms>arguments</parms>
4865N/A <workdir>path</workdir>
4865N/A <envs>env</envs>
2788N/A <console use="'same'"/>
4865N/A <stdin>'%s' % inputFile</stdin>
2788N/A <returnstdout/>
4865N/A </process>
4865N/A </elseif>
4865N/A <else>
4865N/A <process name="name">
4865N/A <location>location</location>
2788N/A <command>command</command>
4865N/A <parms>arguments</parms>
2788N/A <workdir>path</workdir>
4865N/A <envs>env</envs>
4865N/A <console use="'same'"/>
4865N/A <stdout if="outputFile != 'None'" mode="'replace'">'%s' % outputFile</stdout>
4865N/A <returnstdout/>
4865N/A </process>
2788N/A </else>
4865N/A </if>
5912N/A
5912N/A <!-- The problem here is that STAXResult can either be a
5912N/A string, list or a map object -->
5912N/A <script>
5912N/A try:
5912N/A cmdOutput=STAXResult[0][1]
4865N/A cmdRC = RC
4865N/A except:
4865N/A cmdOutput=STAXResult
5912N/A cmdRC = RC
4865N/A
5073N/A cmdResult=STAXResult
4865N/A </script>
2788N/A
4865N/A <script>
4865N/A def dig(var):
4865N/A try:
4865N/A if var.__class__==[].__class__:
4865N/A for i in range(len(var)):
4865N/A var[i]=dig(var[i])
4865N/A return var
4865N/A else:
2788N/A if var.__class__==''.__class__:
3269N/A return re.compile(r'EMMA:.*\n').sub('',var)
3269N/A else:
4865N/A return var
4865N/A except TypeError:
4865N/A return 'could not evaluate the following component: %s' % var
3269N/A
4865N/A if stripOutput == True:
4865N/A cmdResult=dig(cmdResult)
2788N/A </script>
4865N/A
5073N/A <if expr="expectedRC != 'noCheck'">
4865N/A <call function="'checktestRC'">
4865N/A { 'returncode' : cmdRC,
4865N/A 'result' : cmdResult,
4865N/A 'expected' : expectedRC,
4865N/A 'issue' : knownIssue
4865N/A }
4865N/A </call>
4865N/A </if>
4865N/A
4865N/A <return>
4865N/A cmdResult
4865N/A </return>
2788N/A </sequence>
2788N/A </function>
4865N/A
4865N/A
4865N/A
4865N/A <function name="killDs">
2788N/A <function-prolog>
2788N/A Kill the ldap server
2788N/A </function-prolog>
2788N/A <function-map-args>
5912N/A <function-arg-def name="location"
2788N/A type="optional"
2788N/A default="STAF_REMOTE_HOSTNAME">
2788N/A <function-arg-description>
2788N/A Location of target host
3853N/A </function-arg-description>
3853N/A <function-arg-property name="type" value="hostname"/>
3853N/A </function-arg-def>
2788N/A <function-arg-def name="dsPath"
2788N/A type="optional"
2788N/A default="'%s/%s'
2788N/A % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)">
2788N/A <function-arg-description>
3853N/A Pathname to installation root
3853N/A </function-arg-description>
4153N/A <function-arg-property name="type" value="pathname"/>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A
2788N/A <sequence>
2788N/A <message>
4865N/A 'Kill server running on %s at %s' % (location, dsPath)
2849N/A </message>
2849N/A
2849N/A <script>
2849N/A pidPath = '%s/logs/server.pid' % dsPath
4865N/A _args = '%s' % pidPath
3853N/A </script>
3853N/A
3853N/A <call function="'runSTAFCommand'">
2849N/A { 'name' : 'Read server pid file',
2849N/A 'location' : location,
2849N/A 'service' : 'FS',
2849N/A 'request' : 'GET FILE',
2849N/A 'arguments' : _args
2849N/A }
2849N/A </call>
2849N/A
4865N/A <script>
2849N/A if is_windows_platform(location):
2849N/A _cmd = 'tskill'
2849N/A _args = STAXResult
2849N/A else:
2849N/A _cmd = '/bin/kill'
4865N/A pid = STAXResult[:-1]
2788N/A _args = '-9 %s' % pid
2788N/A </script>
2788N/A <call function="'runCommand'">
2788N/A { 'name' : 'Kill DS server',
2788N/A 'location' : location,
2788N/A 'command' : _cmd,
2788N/A 'arguments' : _args
2788N/A }
2788N/A </call>
2788N/A <return>STAXResult</return>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="runSTAFCommand" >
2788N/A <function-description>
2788N/A A general wrapper to run a STAF command without having to write a
2788N/A dedicated function for it
4865N/A </function-description>
2849N/A <function-map-args>
2849N/A <function-arg-def name="location" type="optional" default="STAXServiceMachine">
2849N/A <function-arg-description>
2849N/A Which machine should the command be executed on
4865N/A </function-arg-description>
4865N/A </function-arg-def>
2951N/A <function-arg-def name="name" type="required">
2951N/A <function-arg-description>
3194N/A The name to give the process
3194N/A </function-arg-description>
2951N/A </function-arg-def>
2951N/A <function-arg-def name="service" type="required">
4865N/A <function-arg-description>
3951N/A the command to run
3951N/A </function-arg-description>
3951N/A </function-arg-def>
3951N/A <function-arg-def name="request" type="required">
3951N/A <function-arg-description>
4162N/A the command to run
4162N/A </function-arg-description>
4162N/A </function-arg-def>
4162N/A <function-arg-def name="arguments" type="optional" default="''">
4162N/A <function-arg-description>
4162N/A the arguments for the service request
4162N/A </function-arg-description>
4162N/A </function-arg-def>
4162N/A </function-map-args>
4162N/A <sequence>
4162N/A <script>
4162N/A import random
4162N/A import java.util.Date
4162N/A random.seed(java.util.Date().getTime())
2788N/A _id = '%s#%d' % (strftime('%Y-%m-%d %H:%M:%S',localtime()),random.randint(0,99999))
2788N/A
2788N/A </script>
2788N/A <message>
2788N/A '%s: Running STAF command:\n %s %s %s\nlocation: %s\n' % (_id,service,request,arguments,location)
2849N/A </message>
2849N/A
2849N/A <block name="'%s:Wrapper for %s' % (_id,name)">
2849N/A <stafcmd name="'STAF Command: %s' % name">
4865N/A <location>'%s' % location</location>
4865N/A <service>service</service>
2849N/A <request>
4865N/A '%s %s' % (request,arguments)
5912N/A </request>
5912N/A </stafcmd>
2849N/A </block>
2849N/A
2849N/A <message level="'info'">
2849N/A '%s: STAF Command returned:\n%s' % (_id,STAFResult)
2849N/A </message>
5912N/A
2849N/A <return>
2849N/A STAFResult
2849N/A </return>
2849N/A </sequence>
2849N/A </function>
2849N/A
2849N/A <function name="grep">
2849N/A <function-prolog>
4162N/A This function search for a given string in a given file.
2849N/A BEWARE! of potential performance degradation when grepping big files due
4162N/A to the use of getFile, which loads the whole file content into a variable.
4162N/A </function-prolog>
4162N/A <function-map-args>
4162N/A <function-arg-def name="location"
4464N/A type="optional"
4464N/A default="STAF_REMOTE_HOSTNAME">
4162N/A <function-arg-description>
2849N/A Location of target host
2849N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
5912N/A </function-arg-def>
5912N/A <function-arg-def name="filename" type="required">
5912N/A <function-arg-description>
5912N/A File path
5912N/A </function-arg-description>
5912N/A <function-arg-property name="type" value="pathname"/>
5912N/A </function-arg-def>
2788N/A <function-arg-def name="testString" type="required">
2849N/A <function-arg-description>
2788N/A String searched
4865N/A </function-arg-description>
5912N/A <function-arg-property name="type" value="string"/>
5912N/A </function-arg-def>
5912N/A <function-arg-def name="expectedRC" type="optional" default="0">
5912N/A <function-arg-description>
2788N/A Expected return code value.
2849N/A 0 for successful grep, 1 for unsuccessful grep. Default value is 0.
2849N/A Wildcard 'noCheck' to not check the RC
2849N/A </function-arg-description>
3194N/A </function-arg-def>
3951N/A </function-map-args>
3951N/A
2849N/A <sequence>
4865N/A <message>
3194N/A 'Search for string \"%s\" in file %s on host %s' % \
2849N/A (testString, filename, location)
3194N/A </message>
3194N/A
2788N/A <call function="'getFile'">
4865N/A {
2849N/A 'location' : location,
2788N/A 'filename' : filename
5544N/A }
2788N/A </call>
2788N/A
2788N/A <script>
2788N/A # getFile returns: STAXResult = [cmdRC, cmdResult]
2788N/A filecontent = STAXResult[1]
2788N/A
2788N/A if (expectedRC == 'noCheck'):
2788N/A # don't care about expected result
2788N/A myExpectedResult = '2'
2788N/A elif (expectedRC == 0):
4153N/A # expect testString to be present in filecontent
2788N/A myExpectedResult = '1'
2788N/A else:
2788N/A # expect testString not to be present in filecontent
2788N/A myExpectedResult = '0'
2788N/A </script>
2788N/A
2788N/A <call function="'searchStringForSubstring'">
2788N/A {
2788N/A 'testString' : testString,
2788N/A 'returnString' : filecontent,
2788N/A 'expectedResult' : myExpectedResult
2788N/A }
2788N/A </call>
2788N/A
2788N/A <return>STAXResult</return>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="compareFile">
2788N/A <function-prolog>
2788N/A This function compares two files.
2788N/A Print the differences if the comparison failed.
4865N/A </function-prolog>
2788N/A <function-map-args>
2788N/A <function-arg-def name="location"
2788N/A type="optional"
2788N/A default="STAXServiceMachine">
4865N/A <function-arg-description>
2788N/A Location of target host
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="remotehost"
4865N/A type="optional"
2788N/A default="STAF_REMOTE_HOSTNAME">
2788N/A <function-arg-description>
2788N/A The name of remote host
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="dsPath"
2788N/A type="optional"
2788N/A default="'%s/%s' % (DIRECTORY_INSTANCE_BIN,OPENDSNAME)">
2788N/A <function-arg-description>
2788N/A Pathname to installation root
2788N/A </function-arg-description>
4865N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="outputFile" type="required">
2788N/A <function-arg-description>
2788N/A file containing output from the command
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="file"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="outputPath" type="optional">
2788N/A <function-arg-description>
2788N/A path containing outputFile
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="refFile" type="optional">
2788N/A <function-arg-description>
2788N/A reference file containing expected output
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="file"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="refPath" type="optional">
2788N/A <function-arg-description>
2788N/A reference path containing refFile
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="diffFile" type="optional">
2788N/A <function-arg-description>
2788N/A file containing diff output
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="file"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="diffPath" type="optional">
2788N/A <function-arg-description>
2788N/A file containing diffFile
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="knownIssue" type="optional" default="None">
2788N/A <function-arg-description>
2788N/A Known issue. Corresponds to an issue number.
2788N/A </function-arg-description>
3406N/A <function-arg-property name="type" value="string" />
3406N/A </function-arg-def>
3406N/A </function-map-args>
3406N/A
3406N/A <sequence>
4865N/A <script>
3406N/A if CurrentTestPath.has_key('group'):
2788N/A ThisGroupName = CurrentTestPath['group']
3406N/A else:
2788N/A ThisGroupName = 'unknown-group'
2788N/A
4865N/A FormattedTestcase = format_testcase()
2788N/A FormattedTestgroup = FormattedTestcase.group(ThisGroupName)
2788N/A
3611N/A if not outputPath:
5544N/A outputPath = '%s/..' % (dsPath)
3611N/A
3611N/A if not refFile:
3611N/A regexp = re.compile('\..*$')
3816N/A tmpName = re.sub(regexp, '', outputFile)
3816N/A refFile = '%s.ref' % tmpName
2788N/A
2788N/A if not refPath:
2788N/A refPath = '%s/%s' % (local.data,FormattedTestgroup)
2788N/A
2788N/A if not diffFile:
5540N/A regexp = re.compile('\..*$')
5540N/A tmpName = re.sub(regexp, '', outputFile)
5540N/A diffFile = '%s.diff' % tmpName
2788N/A
2788N/A if not diffPath:
2788N/A diffPath = '%s/%s/diffs' % (logs.tests,FormattedTestgroup)
2788N/A else:
2788N/A diffPath = '%s/diffs' % (diffPath)
2788N/A
2788N/A cflocation=location
2788N/A cfremotehost=remotehost
2788N/A </script>
2788N/A
2788N/A <!-- Check if 'diffPath' is already created -->
2788N/A <call function="'GetEntry'">
2788N/A {
2788N/A 'location' : cflocation,
2788N/A 'entry' : diffPath,
2788N/A 'attribute' : 'TYPE'
2788N/A }
2788N/A </call>
2788N/A <!-- If 'diffPath' is not already created then create it -->
2788N/A <if expr="RC == 48">
2788N/A <sequence>
2788N/A <message>
2788N/A 'Create folder %s' % diffPath
2788N/A </message>
2788N/A <call function="'createFolder'">
2788N/A {
2788N/A 'location' : cflocation ,
2788N/A 'foldername' : diffPath
2788N/A }
2788N/A </call>
2788N/A </sequence>
2788N/A </if>
2788N/A
2788N/A <message>
2788N/A 'Copy file %s/%s (on %s) to %s/%s (on %s)' % \
2788N/A (outputPath, outputFile, cfremotehost, diffPath, outputFile, cflocation)
2788N/A </message>
2788N/A <call function="'copyFile'">
2788N/A {
2788N/A 'location' : cfremotehost ,
2788N/A 'srcfile' : '%s/%s' % (outputPath, outputFile) ,
2788N/A 'destfile' : '%s/%s' % (diffPath, outputFile) ,
2788N/A 'remotehost' : cflocation
2788N/A }
2788N/A </call>
3269N/A <script>
2788N/A outputRC=RC
2788N/A </script>
2788N/A
2788N/A <message>
2788N/A 'Copy file %s/%s (on %s) to %s/%s (on %s)' % \
3406N/A (refPath, refFile, cflocation, diffPath, refFile, cflocation)
3406N/A </message>
2788N/A <call function="'copyFile'">
3269N/A {
3269N/A 'location' : cflocation ,
3269N/A 'srcfile' : '%s/%s' % (refPath, refFile) ,
3269N/A 'destfile' : '%s/%s' % (diffPath, refFile) ,
3269N/A 'remotehost' : cflocation
2788N/A }
2788N/A </call>
2788N/A <script>
4865N/A refRC=RC
2788N/A </script>
3269N/A
2788N/A <!-- If the copy of 'outputFile' and 'refFile' succeed
2788N/A then compare these files -->
2788N/A <if expr="outputRC == 0 and refRC == 0">
2788N/A <sequence>
2788N/A <message>
4865N/A 'Compare file %s/%s to %s/%s on %s' % \
4865N/A (diffPath, outputFile, diffPath, refFile, cflocation)
4865N/A </message>
3406N/A <script>
3406N/A CompareFile = compare_file('%s/%s' % (diffPath, outputFile),
4865N/A '%s/%s' % (diffPath, refFile),
2788N/A '%s/%s' % (diffPath, diffFile))
4865N/A diff = CompareFile.genDiff()
2788N/A </script>
2788N/A
2788N/A <if expr="diff == ''">
2788N/A <sequence>
2849N/A <tcstatus result="'pass'"/>
2788N/A <message log="1">
2788N/A 'SUCCESS : No differences were found between %s and %s' % \
2788N/A (outputFile, refFile)
2788N/A </message>
2788N/A </sequence>
2788N/A <else>
3853N/A <sequence>
3853N/A <if expr="knownIssue == None">
3853N/A <tcstatus result="'fail'"/>
2788N/A <else>
2788N/A <call function="'setKnownIssue'">
2788N/A { 'issueId' : knownIssue }
2788N/A </call>
2788N/A </else>
3853N/A </if>
3853N/A <message log="1">
4153N/A 'ERROR : Differences were found between %s and %s\n%s' % \
2788N/A (outputFile, refFile, diff)
2788N/A </message>
2788N/A <message log="1">
2788N/A 'ERROR : Diff file is here: %s/%s' % (diffPath, diffFile)
2788N/A </message>
4865N/A </sequence>
2849N/A </else>
2849N/A </if>
2849N/A </sequence>
2849N/A <else>
4865N/A <sequence>
3853N/A <tcstatus result="'fail'"/>
3853N/A <message log="1">
3853N/A 'ERROR : Error during file comparision'
2849N/A </message>
2849N/A </sequence>
2849N/A </else>
2849N/A </if>
2849N/A </sequence>
2849N/A </function>
2849N/A
2849N/A <function name="compileJava" scope="local">
4865N/A <function-prolog>
2849N/A This function compile java files.
2849N/A </function-prolog>
2849N/A <function-map-args>
2849N/A <function-arg-def name="location"
2849N/A type="optional"
4865N/A default="STAXServiceMachine">
2788N/A <function-arg-description>
2788N/A Location of remote host
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="foldername" type="optional">
2788N/A <function-arg-description>
2788N/A Path containing java files to compile
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
4865N/A <function-arg-def name="destfolder" type="optional">
2849N/A <function-arg-description>
2849N/A Path where to place generated class files
2849N/A </function-arg-description>
2849N/A <function-arg-property name="type" value="filepath"/>
4865N/A </function-arg-def>
4865N/A <function-arg-def name="classpath" type="optional">
2951N/A <function-arg-description>
2951N/A Additional classpath
3194N/A </function-arg-description>
3194N/A <function-arg-property name="type" value="string"/>
2951N/A </function-arg-def>
2951N/A <function-arg-def name="expectedRC" type="optional" default="0">
4865N/A <function-arg-description>
3951N/A Expected return code value. Default value is 0.
3951N/A Wildcard 'noCheck' to not check the RC
3951N/A </function-arg-description>
3951N/A </function-arg-def>
3951N/A </function-map-args>
4162N/A
4162N/A <sequence>
4162N/A
4162N/A <!-- Build the command -->
4162N/A <script>
4162N/A cmdOptions = ''
4162N/A
4162N/A if is_windows_platform(location):
4162N/A separator=';'
4162N/A else:
4162N/A separator=':'
4162N/A
4162N/A if classpath:
4162N/A cp = 'CLASSPATH=%s%s.' % (classpath, separator)
2788N/A else:
2788N/A cp = 'CLASSPATH=.'
2849N/A
2849N/A if location == STAXServiceMachine:
2788N/A cmd = '%s/bin/javac' % LOCAL_JAVA_HOME
2849N/A env = ['%s' % cp]
2849N/A else:
2849N/A cmd = '%s/bin/javac' % JAVA_HOME
2849N/A env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]
2849N/A
4865N/A if destfolder:
2849N/A cmdOptions = '-d %s' % destfolder
4865N/A </script>
2849N/A
2849N/A <call function="'listFolderByExtension'" >
2849N/A {
2849N/A 'location' : location ,
2849N/A 'foldername' : foldername ,
2849N/A 'extension' : 'java'
2849N/A }
2849N/A </call>
2849N/A
2788N/A <script>
2849N/A cmdResult = STAXResult
2849N/A </script>
4162N/A
4464N/A <if expr="cmdResult != 'Folder does not exist.'">
4464N/A <sequence>
4464N/A <script>
4162N/A list = ""
4162N/A for file in cmdResult:
4162N/A list = list + " " + file
2849N/A </script>
2849N/A
2849N/A <call function="'runCommand'" >
2788N/A {
2849N/A 'name' : 'Compile Java files' ,
2788N/A 'command' : cmd ,
2849N/A 'arguments' : '-target 1.5 %s %s' % (cmdOptions,list) ,
2788N/A 'location' : location ,
2849N/A 'path' : foldername ,
2849N/A 'envCmd' : env ,
2849N/A 'expectedRC' : expectedRC
3194N/A }
3951N/A </call>
3951N/A </sequence>
3194N/A <else>
4865N/A <tcstatus result="'fail'"></tcstatus>
3194N/A </else>
2849N/A </if>
3194N/A
3194N/A <return>
3194N/A STAXResult
2788N/A </return>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="createJar" scope="local">
2788N/A <function-prolog>
2788N/A This function create a jar file.
2788N/A </function-prolog>
2788N/A <function-map-args>
2788N/A <function-arg-def name="location"
2788N/A type="optional"
2788N/A default="STAXServiceMachine">
2788N/A <function-arg-description>
2788N/A Location of remote host
4153N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="jarname" type="required">
2788N/A <function-arg-description>
2788N/A Name of the jar file to create
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="entrypoint" type="required">
2788N/A <function-arg-description>
2788N/A Path where to find generated class files
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="pathfolder" type="required">
2788N/A <function-arg-description>
2788N/A Execution path
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="manifestpath" type="optional">
2788N/A <function-arg-description>
4865N/A Path to the manifest file
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="expectedRC" type="optional" default="0">
4865N/A <function-arg-description>
2788N/A Expected return code value. Default value is 0.
2788N/A Wildcard 'noCheck' to not check the RC
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A
2788N/A <sequence>
2788N/A
2788N/A <!-- Build the command -->
2788N/A <script>
2788N/A if location == STAXServiceMachine:
4865N/A cmd = '%s/bin/jar' % LOCAL_JAVA_HOME
2788N/A else:
2788N/A cmd = '%s/bin/jar' % JAVA_HOME
2788N/A
2788N/A if manifestpath:
2788N/A cmdOptions = 'cmf %s' % manifestpath
2788N/A else:
2788N/A cmdOptions = 'cf'
2788N/A </script>
2788N/A
2788N/A <!-- Check if the classfolder exists -->
2788N/A <call function="'GetEntry'">
2788N/A {
3406N/A 'location' : location ,
3406N/A 'entry' : '%s/%s' % (pathfolder,entrypoint) ,
3406N/A 'attribute' : 'TYPE'
3406N/A }
3406N/A </call>
4865N/A <if expr="RC != 48">
3406N/A <sequence>
2788N/A <call function="'runCommand'" >
2788N/A {
2788N/A 'name' : 'Create Jar file' ,
2788N/A 'command' : cmd ,
3611N/A 'arguments' : '%s %s %s' % (cmdOptions,jarname,entrypoint) ,
2788N/A 'location' : location ,
2788N/A 'path' : pathfolder ,
3611N/A 'expectedRC' : expectedRC
3611N/A }
3611N/A </call>
3611N/A </sequence>
3611N/A <else>
3611N/A <tcstatus result="'fail'"></tcstatus>
3611N/A </else>
3611N/A </if>
3611N/A
3611N/A <return>
3816N/A STAXResult
3816N/A </return>
2788N/A </sequence>
4865N/A </function>
2788N/A
2788N/A <function name="getFreePort" scope="local">
2788N/A <function-description>
2788N/A Returns the first free TCP port greater or equal to given number
2788N/A </function-description>
2788N/A <function-map-args>
2788N/A <function-arg-def name="host"
2788N/A type="optional"
2788N/A default="STAXServiceMachine">
2788N/A <function-arg-description>
2788N/A Which machine to look for the free port
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="port" type="required">
2788N/A <function-arg-description>
2788N/A The minimal port number to be returned
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A <sequence>
2788N/A <script>
2788N/A # returns first free port in [port; port+5]
2788N/A # if no free port in this interval, return -1
2788N/A from java.net import Socket
2788N/A from java.net import InetAddress
2788N/A from java.io import IOException
2788N/A
2788N/A hostAddr = InetAddress.getByName(host)
2788N/A i = 0
2788N/A
2788N/A while 1:
2788N/A i = i + 1
2788N/A if i > 5:
2788N/A port = -1
2788N/A break
2788N/A try:
2788N/A s = Socket(hostAddr, port)
2788N/A s.close()
2788N/A port = port + 1
2788N/A except IOException, ioe:
3269N/A break
2788N/A </script>
2788N/A <return>port</return>
2788N/A </sequence>
2788N/A </function>
2788N/A
3406N/A <function name="checkFileExists" scope="local">
3406N/A <function-description>
2788N/A Set testcase result to FAIL if file (as param) does not exist
3269N/A </function-description>
3269N/A <function-map-args>
3269N/A <function-arg-def name="location"
3269N/A type="optional"
3269N/A default="STAXServiceMachine">
2788N/A <function-arg-description>
2788N/A Location of target host
2788N/A </function-arg-description>
4865N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
3269N/A <function-arg-def name="file" type="required">
2788N/A <function-arg-description>
2788N/A The file to check existence
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A </function-map-args>
4865N/A <sequence>
4865N/A <call function="'GetEntry'">
4865N/A {
3406N/A 'location' : STAF_REMOTE_HOSTNAME ,
3406N/A 'entry' : file ,
4865N/A 'attribute' : 'TYPE'
4865N/A }
2788N/A </call>
2788N/A <if expr="RC == 48">
2788N/A <sequence>
2788N/A <tcstatus result="'fail'"/>
2788N/A <message log="1" level="'Error'">
2788N/A 'ERROR : File %s does not exist' % file
2788N/A </message>
2788N/A </sequence>
2788N/A </if>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <function name="checkFileNotExists" scope="local">
2788N/A <function-description>
2788N/A Set testcase result to FAIL if file (as param) exists
2788N/A </function-description>
2788N/A <function-map-args>
4153N/A <function-arg-def name="location"
2788N/A type="optional"
2788N/A default="STAXServiceMachine">
2788N/A <function-arg-description>
2788N/A Location of target host
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="hostname"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="file" type="required">
2788N/A <function-arg-description>
2788N/A The file to check absence
2788N/A </function-arg-description>
2788N/A </function-arg-def>
2788N/A </function-map-args>
2788N/A <sequence>
2788N/A <call function="'GetEntry'">
2788N/A {
2788N/A 'location' : STAF_REMOTE_HOSTNAME ,
2788N/A 'entry' : file ,
2788N/A 'attribute' : 'TYPE'
2788N/A }
2788N/A </call>
2788N/A <if expr="RC != 48">
4865N/A <sequence>
2788N/A <tcstatus result="'fail'"/>
2788N/A <message log="1" level="'Error'">
2788N/A 'ERROR : File %s does not exist' % file
2788N/A </message>
2788N/A </sequence>
4865N/A </if>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A
2788N/A <function name="ldclt">
2788N/A <function-prolog>
4865N/A This function execute the ldclt tools.
4865N/A </function-prolog>
4865N/A <function-map-args>
4865N/A <function-arg-def name="location"
4865N/A type="optional"
4865N/A default="STAF_CLIENT_HOSTNAME">
4865N/A <function-arg-description>
4865N/A Location of target host
4865N/A </function-arg-description>
4865N/A <function-arg-property name="type" value="hostname"/>
4865N/A </function-arg-def>
4865N/A <function-arg-def name="dsInstanceHost"
4865N/A type="optional"
4865N/A default="DIRECTORY_INSTANCE_HOST">
4865N/A <function-arg-description>
4865N/A Directory server hostname or IP address
3406N/A </function-arg-description>
3406N/A <function-arg-property name="type" value="hostname"/>
3406N/A </function-arg-def>
3406N/A <function-arg-def name="dsInstancePort"
3406N/A type="optional"
4865N/A default="DIRECTORY_INSTANCE_PORT">
3406N/A <function-arg-description>
2788N/A Directory server port number
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="Port number"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="dsInstanceDn"
2788N/A type="optional"
2788N/A default="DIRECTORY_INSTANCE_DN">
2788N/A <function-arg-description>
3611N/A Bind DN
3611N/A </function-arg-description>
3611N/A <function-arg-property name="type" value="DN"/>
3611N/A </function-arg-def>
3611N/A <function-arg-def name="dsInstancePswd"
3611N/A type="optional"
3611N/A default="DIRECTORY_INSTANCE_PSWD">
3611N/A <function-arg-description>
3611N/A Bind password
3611N/A </function-arg-description>
3816N/A <function-arg-property name="type" value="string"/>
3816N/A </function-arg-def>
2788N/A <function-arg-def name="dsBaseDn"
4865N/A type="optional"
2788N/A default="DIRECTORY_INSTANCE_SFX">
2788N/A <function-arg-description>
2788N/A The baseDN for the LDAP operation
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="dn"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="ldcltOptions"
2788N/A type="required">
2788N/A <function-arg-description>
2788N/A The ldclt options
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="dn"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="outputFile"
2788N/A type="required">
2788N/A <function-arg-description>
2788N/A File containing output from the command
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="file"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="outputPath"
2788N/A type="optional"
2788N/A default="remote.temp">
2788N/A <function-arg-description>
2788N/A Path containing outputFile
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filepath"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="expectedRC" type="optional" default="0">
2788N/A <function-arg-description>
2788N/A Expected return code value. Default value is 0
2788N/A Wildcard 'noCheck' to not check the RC
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="integer"/>
2788N/A </function-arg-def>
3269N/A <function-arg-def name="knownIssue"
2788N/A type="optional"
2788N/A default="None">
2788N/A <function-arg-description>
2788N/A Known issue. Corresponds to an issue number.
2788N/A </function-arg-description>
3406N/A <function-arg-property name="type" value="string"/>
3406N/A </function-arg-def>
2788N/A </function-map-args>
3269N/A
3269N/A <sequence>
3269N/A <script>
3269N/A STAFCmdParamsList=[]
4865N/A STAFCmdParams=''
4865N/A
4865N/A STAFCmd='%s/bin/ldclt' % LDCLT_DIR
5061N/A
5061N/A if dsInstanceHost:
5061N/A STAFCmdParamsList.append('-h %s' % dsInstanceHost)
5061N/A
5061N/A if dsInstanceHost:
5061N/A STAFCmdParamsList.append('-p %s' % dsInstancePort)
5061N/A
5061N/A if dsInstanceDn:
5061N/A STAFCmdParamsList.append('-D "%s"' % dsInstanceDn)
5061N/A
5061N/A if dsInstancePswd:
5061N/A STAFCmdParamsList.append('-w %s' % dsInstancePswd)
5061N/A
5061N/A if dsBaseDn:
5061N/A STAFCmdParamsList.append('-b "%s"' % dsBaseDn)
5061N/A
5061N/A STAFCmdParamsList.append(ldcltOptions)
5061N/A
4865N/A STAFCmdParams=' '.join(STAFCmdParamsList)
4865N/A
2788N/A ld = 'LD_LIBRARY_PATH=%s/lib' % LDCLT_DIR
2788N/A env = ['%s' % ld]
2788N/A </script>
2788N/A
2788N/A <call function="'runCommand'" >
2788N/A {
2788N/A 'name' : 'LDCLT Script' ,
2788N/A 'command' : STAFCmd ,
2788N/A 'arguments' : STAFCmdParams ,
2788N/A 'location' : location ,
2788N/A 'path' : LDCLT_DIR ,
2788N/A 'envCmd' : env ,
2788N/A 'outputFile' : '%s/%s' % (outputPath, outputFile) ,
2788N/A 'expectedRC' : expectedRC ,
2788N/A 'logStderr' : True ,
2788N/A 'knownIssue' : knownIssue
2788N/A }
4153N/A </call>
2788N/A
2788N/A <return>
2788N/A STAXResult
2788N/A </return>
2788N/A </sequence>
2788N/A </function>
2788N/A
2788N/A <!-- This function uses make ldif to generate LDIF data files -->
2788N/A <function name="MakeALdcltTemplate">
2788N/A <function-prolog>
2788N/A This function makes a ldclt template file
2788N/A </function-prolog>
2788N/A
2788N/A <function-map-args>
2788N/A <function-arg-def name="templateFile" type="required">
2788N/A <function-arg-description>
2788N/A Template file name
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filename"/>
2788N/A </function-arg-def>
2788N/A <function-arg-def name="templateLocation"
2788N/A type="optional"
4865N/A default="STAF_CLIENT_HOSTNAME">
2788N/A <function-arg-description>
2788N/A Template file location
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="filename"/>
2788N/A </function-arg-def>
4865N/A <function-arg-def name="extraLine" type="optional">
2788N/A <function-arg-description>
2788N/A Extra line to add to the mkae-ldif template
2788N/A </function-arg-description>
2788N/A <function-arg-property name="type" value="string"/>
2788N/A </function-arg-def>
2788N/A </function-map-args>
3406N/A <sequence>
3406N/A <!-- Build the import task configuration object -->
3406N/A <script>
3406N/A ldifLines=[]
3406N/A
4865N/A ldifLines.append('objectClass: top')
3406N/A ldifLines.append('objectClass: person')
2788N/A ldifLines.append('objectClass: organizationalPerson')
2788N/A ldifLines.append('objectClass: inetOrgPerson')
2788N/A ldifLines.append('givenName: [A=RNDFROMFILE(%s/ldap/lib/names/Firstname.txt)]' % LDCLT_DIR)
2788N/A ldifLines.append('sn: [B=RNDFROMFILE(%s/ldap/lib/names/Lastname.txt)]' % LDCLT_DIR)
2788N/A ldifLines.append('employeeNumber: [C]')
2788N/A ldifLines.append('cn: [A] [B] [C]')
2788N/A ldifLines.append('mail: user.[C]@example.com')
2788N/A ldifLines.append('initials: [A][B]')
3611N/A ldifLines.append('homePhone: 0[RNDN(1;5;1)] [RNDN(0;99;2)] [RNDN(0;99;2)] [RNDN(0;99;2)] [RNDN(0;99;2)]')
3611N/A ldifLines.append('mobile: 06 [RNDN(0;99;2)] [RNDN(0;99;2)] [RNDN(0;99;2)] [RNDN(0;99;2)]')
3611N/A ldifLines.append('street: [D=RNDFROMFILE(%s/ldap/lib/names/Firstname.txt)]' % LDCLT_DIR)
3611N/A ldifLines.append('l: [E=RNDFROMFILE(%s/ldap/lib/names/Lastname.txt)]' % LDCLT_DIR)
3611N/A ldifLines.append('st: [F=RNDFROMFILE(%s/ldap/lib/names/Firstname.txt)]' % LDCLT_DIR)
3611N/A ldifLines.append('postalCode: [G=RNDN(0;80000;5)]')
3611N/A ldifLines.append('postalAddress: [A] [B] [C][D][E], [F] [G]')
3611N/A ldifLines.append('telephoneNumber: 0[RNDN(1;5;1)] [RNDN(0;99;2)] [RNDN(0;99;2)] [RNDN(0;99;2)] [RNDN(0;99;2)]')
3611N/A ldifLines.append('description: This is the description for user.[C].')
3611N/A </script>
3816N/A
3816N/A <!-- Write out the make-ldif template file -->
2788N/A <script>
4865N/A tmpTemplateFile = '%s/tempLdcltTemplateFile' % local.temp
2788N/A outfile = open(tmpTemplateFile,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A </script>
2788N/A <script>
2788N/A STAXCode=RC
2788N/A STAXReason=STAXResult
2788N/A </script>
2788N/A <if expr="STAXCode != 0">
2788N/A <sequence>
2788N/A <message level="'error'">
2788N/A 'creation of a ldclt template failed (Code=%s,Reason=%s).' % (STAXCode,STAXReason)
2788N/A </message>
2788N/A </sequence>
2788N/A </if>
2788N/A <call function="'checktestRC'">
2788N/A { 'returncode' : STAXCode ,
2788N/A 'result' : STAXReason }
2788N/A </call>
2788N/A
2788N/A <call function="'copyFile'">
2788N/A { 'location' : STAXServiceMachine,
2788N/A 'srcfile' : tmpTemplateFile,
2788N/A 'destfile' : templateFile,
2788N/A 'remotehost' : templateLocation }
2788N/A </call>
2788N/A
2788N/A <call function="'checktestRC'">
2788N/A {
2788N/A 'returncode' : RC ,
2788N/A 'result' : STAXResult
2788N/A }
3269N/A </call>
2788N/A
2788N/A <return>[RC, STAXResult]</return>
2788N/A
2788N/A </sequence>
2788N/A </function>
3406N/A
3406N/A</stax>
2788N/A