Hi ,
I am encountering the following error :
"AttributeError: 'None' object has no attribute 'getNodeName'" on parsing a
xml file."
This a new problem i am getting , never earlier got this problem .
The xml file to be parsed is :
=====================
<?xml version="1.0" encoding="utf-8"?>
<operating_system>
<unix_r12>
<tests type="quickSanityTest">
<prerequisitescript>update.exp</prerequisitescript>
<acbuildpath>/CR_80SP1/80_builds/Unix/CR16/TestFix</acbuildpath>
<testsuitscript>runQuickSanity.sh</testsuitscript>
<testdir>/testQuickSanity</testdir>
<testconfig>BlueExpress.tar</testconfig>
<reportname>BATReport</reportname>
</tests>
<machine_name>etr6506l3-sun66.ca.com</machine_name>
</unix_r12>
</operating_system>
Attached is the exact file that i am using to parse:
The staf job file "parsejob.xml is also attached here:
I get the error :
20100315-15:09:48 STAXPythonEvaluationError signal raised. Terminating job.
===== XML Information =====
File: C:\STAF\stax_jobs\parsejob.xml, Machine: baksa03-xp.ca.com
Line 403: Error in element type "script".
===== Python Error Information =====
com.ibm.staf.service.stax.STAXPythonEvaluationException:
Traceback (innermost last):
File "<pyExec string>", line 157, in ?
AttributeError: 'None' object has no attribute 'getNodeName'
===== Call Stack for STAX Thread 1 =====
[
function: Main (Line: 8, File: C:\STAF\stax_jobs\parsejob.xml, Machine:
baksa03-xp.ca.com)
sequence: 1/31 (Line: 10, File: C:\STAF\stax_jobs\parsejob.xml, Machine:
baksa03-xp.ca.com)
function: parseXML (Line: 383, File: C:\STAF\stax_jobs\parsejob.xml,
Machine: baksa03-xp.ca.com)
sequence: 2/4 (Line: 391, File: C:\STAF\stax_jobs\parsejob.xml, Machine:
baksa03-xp.ca.com)
]
I have validated the xml file to be valid by MSXML valid . It is valid .
Now the same xml file gets read if i Ctrl-x the following in the xml file :
<tests type="quickSanityTest">
<prerequisitescript>update.exp</prerequisitescript>
<acbuildpath>/CR_80SP1/80_builds/Unix/CR16/TestFix</acbuildpath>
<testsuitscript>runQuickSanity.sh</testsuitscript>
<testdir>/testQuickSanity</testdir>
<testconfig>BlueExpress.tar</testconfig>
<reportname>BATReport</reportname>
and paste it again at the same location in the xml file. The xml file then
gets parsed through the staf job as i have attched.
Please suggest , i am not understanding this problem .
Regards
Sangram
<?xml version="1.0" encoding="utf-8"?>
<operating_system><unix_r12><tests type="quickSanityTest"><prerequisitescript>update.exp</prerequisitescript><acbuildpath>/CR_80SP1/80_builds/Unix/CR16/TestFix</acbuildpath><testsuitscript>runQuickSanity.sh</testsuitscript><testdir>/testQuickSanity</testdir><testconfig>BlueExpress.tar</testconfig><reportname>BATReport</reportname></tests><machine_name>etr6506l3-sun66.ca.com</machine_name></unix_r12></operating_system>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="Main"/>
<function name="Main">
<sequence>
<!-- Assign the file name of a STAX xml document you want to parse -->
<call function="'parseXML'">'c:/config.xml'</call>
<script>
[machname,vmware_value,vmware_attr,vmwaren_attr,vmwaren_value,preqscript,acbpath,rtstscript,tdir,rname,cs,ver] = STAXResult
</script>
<script>
from com.ibm.staf import STAFUtil
dir_name_source='/sangram/test.out'
store_dir ='/sangram'
dir_name_dest='C:/STAF/stax_jobs'
machList = ['baksa03-xp.ca.com']
vmware_exists = len(vmware_attr)
machine_exists = len(machname)
gPingFailList = STAXGlobal([])
makedir = 'mkdir'
tempdir = '/build'
actionrun = '/testQuickSanity/update.exp'
chmod = 'chmod 777'
</script>
<!-- Log the parsed data -->
<log message="1">'vmware_attr=%s' % (vmware_attr)</log>
<log message="1">'machname=%s' % (machname)</log>
<log message="1">'vmware_value=%s' % (vmware_value)</log>
<log message="1">'preqscript=%s' % (preqscript)</log>
<log message="1">'acbpath=%s' % (acbpath)</log>
<log message="1">'rtstscript=%s' % (rtstscript)</log>
<log message="1">'tdir=%s' % (tdir)</log>
<log message="1">'cs=%s' % (cs)</log>
<log message="1">'ver=%s' % (ver)</log>
<!-- Check if vwmares are selected for tests to run ,log message that vmwares exists -->
<if expr="vmware_exists>0">
<message log="1">'VMwares exists!!!! - VMware: %s' % (vmware_attr)</message>
</if>
<if expr="vmware_exists==0">
<message log="1">'VMwares Does Not Exists..Tests Not Running on VMwares!!!! - VMware: %s' % (vmware_attr)</message>
</if>
<!-- Check if machines are selected from user to run tests , log message machines exists -->
<if expr="machine_exists>0">
<message log="1">'Machines Exists!!!! - Machines : %s' % (machname)</message>
</if>
<if expr="machine_exists==0">
<message log="1">'Machines Does Not Exists..Tests Cannot Run!!!! - Machines: %s' % (machname)</message>
</if>
<!-- Ping all machines list to verify if they are Reachable -->
<paralleliterate var="testMach" in="machname">
<sequence>
<stafcmd>
<location>testMach</location>
<service>'PING'</service>
<request>'PING'</request>
</stafcmd>
<if expr="RC != 0">
<script>gPingFailList.append(testMach)</script>
</if>
<if expr="RC==0">
<message log="1">'Successfully Pinged Machine !!!! : %s' % (testMach)</message>
</if>
</sequence>
</paralleliterate>
<if expr="len(gPingFailList) != 0">
<message>
'Could not ping the following machines: %s' % (gPingFailList.get())
</message>
</if>
<!-- Some Small Delay After Pinging Machines -->
<stafcmd name = "'Delaying for 100 seconds AAAAAAAA'">
<location>machList[0]</location>
<service>'delay'</service>
<request>'delay 10000'</request>
</stafcmd>
<!-- Create the Test Directory on all the test machines to keep test related modules there -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<stafcmd name ="'Start Creating directory ..... '">
<location>testMach</location>
<service>'FS'</service>
<request>'CREATE DIRECTORY %s' % (tdir)</request>
</stafcmd>
<if expr="RC == 0">
<message log="1">'Directory Successfully Created !!!! - RC: %s, Result: %s' % (RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'Directory Creation failed !!!! - RC: %s, Result: %s' % (RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!-- Copy 1: Start Copying Config files from Master Machine to all Tests machines in the required machines -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<stafcmd name ="'Start Copying Test related files to test machine locations........'">
<location>machList[0]</location>
<service>'FS'</service>
<request>'COPY FILE c:/%s%s/%s TODIRECTORY %s TOMACHINE %s' % (ver,tdir,cs,tdir,testMach)</request>
</stafcmd>
<if expr="RC == 0">
<message log="1">'Successfully Transfered File: %s !!!! - RC: %s, Result: %s' % (cs,RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'File Transfer Failed for File : %s !!!! - RC: %s, Result: %s' % (cs,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!-- Delaying for a few moments after transferring files -->
<stafcmd name="'Delaying for 100 seconds AAAAAAAA'">
<location>machList[0]</location>
<service>'delay'</service>
<request>'delay 10000'</request>
</stafcmd>
<!--Copy 2: Start Copying Test Execute Script files from Master Machine to all Tests machines in the required machines -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<stafcmd name ="'Start Copying Test related files to test machine locations........'">
<location>machList[0]</location>
<service>'FS'</service>
<request>'COPY FILE c:/%s%s/%s TODIRECTORY %s TOMACHINE %s' % (ver,tdir,rtstscript,tdir,testMach)</request>
</stafcmd>
<if expr="RC == 0">
<message log="1">'File Successfully Transfered File: %s !!!! - RC: %s, Result: %s' % (rtstscript,RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'File Transfer failed for file : %s !!!! - RC: %s, Result: %s' % (rtstscript,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!-- Delaying for a few moments after transferring files to Test machines -->
<stafcmd name="'Delaying for 100 seconds AAAAAAAA'">
<location>machList[0]</location>
<service>'delay'</service>
<request>'delay 10000'</request>
</stafcmd>
<!--Copy 3: Start Copying Pre-requisite script from Master Machine to all Tests machines in the required machines -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<stafcmd name ="'Start Copying Test related files to test machine locations........'">
<location>machList[0]</location>
<service>'FS'</service>
<request>'COPY FILE c:/%s%s/%s TODIRECTORY %s TOMACHINE %s' % (ver,tdir,preqscript,tdir,testMach)</request>
</stafcmd>
<if expr="RC == 0">
<message log="1">'File Successfully Transfered File: %s !!!! - RC: %s, Result: %s' % (preqscript,RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'File Transfer failed for file : %s !!!! - RC: %s, Result: %s' % (preqscript,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!-- Delaying for a few moments after transferring files -->
<stafcmd name="'Delaying time'">
<location>machList[0]</location>
<service>'delay'</service>
<request>'delay 1000'</request>
</stafcmd>
<!-- Give Execute Permissions to files in testdirectory -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<process name="'Giving Execute Permissions for PreScript on %s.....' % testMach">
<location>testMach</location>
<command mode="'shell'">'%s %s/%s' % (chmod ,tdir,preqscript) </command>
</process>
<if expr="RC == 0">
<message log="1">'Prerequisite Given Execute Perm %s !!!! - RC: %s, Result: %s' % (preqscript,RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'Failed to give Execute Perm to %s !!!! - RC: %s, Result: %s' % (preqscript,RC, STAFResult)</message>
</if>
<process name="'Give Execute Permission to Run Test Script on machine %s.....' % testMach">
<location>testMach</location>
<command mode="'shell'">'%s %s/%s' % (chmod ,tdir,rtstscript) </command>
</process>
<if expr="RC == 0">
<message log="1">'Execute Perm given to %s !!!! - RC: %s, Result: %s' % (rtstscript,RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'Failed to give Execute Perm to %s !!!! - RC: %s, Result: %s' % (rtstscript,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!--Execute 1: Execute Pre-requisite script to make machines Test Ready -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<process name="'Starting Running Prerequiste script on machine %s.....' % testMach">
<location>testMach</location>
<command mode="'shell'">'%s/%s %s' % (tdir,preqscript,acbpath) </command>
</process>
<if expr="RC == 0">
<message log="1">'Prerequisite script Successfully Run %s !!!! - RC: %s, Result: %s' % (preqscript,RC, STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'Failed to run Prerequisite script %s !!!! - RC: %s, Result: %s' % (preqscript,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!-- Delaying for a few moments after Executing Prerequisite Script -->
<stafcmd name="'Delaying for Small time after running Prequite Script'">
<location>machList[0]</location>
<service>'delay'</service>
<request>'delay 10000'</request>
</stafcmd>
<!--Execute 2: Start the Tests in the required machines -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<process name="'Starting Test on machine %s.....' % testMach">
<location>testMach</location>
<command mode="'shell'">'%s/%s ' % (tdir,rtstscript) </command>
<stdout>'%s/%s_%s' % (tdir,rname,testMach)</stdout>
</process>
<if expr="RC == 0">
<message log="1">'Test Succeeded Run on %s !!!! - RC: %s, Result: %s' % (testMach,RC,STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'Failed to run Test on %s !!!! - RC: %s, Result: %s' % (testMach,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
<!-- Get the Tests Reports from the test machines -->
<paralleliterate var="testMach" in="machname" indexvar="i">
<sequence>
<stafcmd name ="'Start Copying Test Report from remote machine ..... '">
<location>testMach</location>
<service>'FS'</service>
<request>'COPY FILE %s/%s_%s TODIRECTORY c:/STAF/stax_jobs' % (tdir,rname,testMach)</request>
</stafcmd>
<if expr="RC == 0">
<message log="1">'Transferred Report on %s !!!! - RC: %s, Result: %s' % (testMach,RC,STAFResult)</message>
</if>
<if expr="RC != 0">
<message log="1">'Failed to Transfer report on %s !!!! - RC: %s, Result: %s' % (testMach,RC, STAFResult)</message>
</if>
</sequence>
</paralleliterate>
</sequence>
</function>
<!-- ******************************************************************* -->
<!-- Following function is used to parse an XML file and return the DOM -->
<!-- document object -->
<!-- ******************************************************************* -->
<function name="parseXML" scope="local">
<function-list-args>
<function-required-arg name="xmlFileName">
Name of file containing XML to be parsed
</function-required-arg>
</function-list-args>
<sequence>
<!-- Parse the XML -->
<script>
factory = DocumentBuilderFactory.newInstance();
factory.setValidating(1)
factory.setIgnoringElementContentWhitespace(0)
builder = factory.newDocumentBuilder()
document = builder.parse(xmlFileName)
</script>
<script>
machname = []
vmware_value = []
vmware_attr = []
vmwaren_attr = []
vmwaren_value = []
preqscript = None
acbpath = None
rtstscript = None
tdir = None
rname = None
cs = None
nodeList = document.getElementsByTagName("machine_name")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("machine_name")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
machname.append( thisChild.getNodeValue())
nodeList = document.getElementsByTagName("vmware")
if nodeList.getLength():
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
id = ""
attrList = node.getAttributes()
for k in range(attrList.getLength()):
thisAttr = attrList.item(k)
if thisAttr.getNodeName() == "id":
id = thisAttr.getNodeValue()
vmware_attr.append(id)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
vmware_value.append(thisChild.getNodeValue())
nodeList = document.getElementsByTagName("prerequisitescript")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("prerequisitescript")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
preqscript = thisChild.getNodeValue()
nodeList = document.getElementsByTagName("acbuildpath")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("acbuildpath")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
acbpath = thisChild.getNodeValue()
nodeList = document.getElementsByTagName("testsuitscript")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("testsuitscript")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
rtstscript = thisChild.getNodeValue()
nodeList = document.getElementsByTagName("vmwarename")
if nodeList.getLength():
nodeList = document.getElementsByTagName("vmwarename")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
id = ""
attrList = node.getAttributes()
for k in range(attrList.getLength()):
thisAttr = attrList.item(k)
if thisAttr.getNodeName() == "id":
id = thisAttr.getNodeValue()
vmwaren_attr.append(id)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
vmwaren_value.append(thisChild.getNodeValue())
nodeList = document.getElementsByTagName("reportname")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("reportname")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
rname = thisChild.getNodeValue()
nodeList = document.getElementsByTagName("testdir")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("testdir")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
tdir = thisChild.getNodeValue()
nodeList = document.getElementsByTagName("testconfig")
x = nodeList.getLength()
if nodeList.getLength():
nodeList = document.getElementsByTagName("testconfig")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
cs = thisChild.getNodeValue()
ver = None
begin = document.getDocumentElement()
nodebegin = begin.getChildNodes()
ver = nodebegin.item(1).getNodeName()
</script>
<script>
</script>
<return>[machname,vmware_value,vmware_attr,vmwaren_attr,vmwaren_value,preqscript,acbpath,rtstscript,tdir,rname,cs,ver]
</return>
</sequence>
</function>
<script>
# These imports only need to be done once per job, no matter
# how many xml documents are parsed
from java.io import File
from java.io import StringReader
from org.xml.sax import InputSource
from org.xml.sax import SAXParseException
from org.xml.sax.helpers import DefaultHandler
from javax.xml.parsers import DocumentBuilderFactory
from javax.xml.parsers import DocumentBuilder
from org.w3c.dom import Document
from org.w3c.dom import Element
from org.w3c.dom import Node
from org.w3c.dom import NodeList
</script>
</stax>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users