def execute(self, runid): """Invoke each of the extractors in the chain. Keyword arguments: runid -- A UTC ID string which identifies the run. An empty run node is created as an instance of Extract.Node and passed to the handlerunnode() method of each extractor in the chain. An empty job node is created, as a subnode of the run node, for each job in the jobtree directory named by the runid, e.g. /2007-06-25_09.18.46, and passed to the handlejobnode() method of each extractor in the chain. The run node is saved as XML to the configurable BaseExtractor_XmlFile, replacing ${runid} with the current run id. e.g. ~/gangadir/robot/extract/${runid}.xml """ logger.info("Extracting data for run '%s'.", runid) runnode = Node('run') for extractor in self.chain: extractor.handlerunnode(runnode, runid) path = Utility.jobtreepath(runid) ids = jobtree.listjobs(path) ids.sort() for id in ids: jobnode = Node('job') job = jobs(id) for extractor in self.chain: extractor.handlejobnode(jobnode, job) runnode.nodes.append(jobnode) self._saveextract(runnode, runid) logger.info('Extract data saved.')
def setUp(self): """Create test extract data.""" super(TestExtract, self).setUp() #testnode run = Node('run') run_core = run.addnode('core') run_core.addnode('id', 'Run_Id') job = run.addnode('job') job_core = job.addnode('core') job_core.addnode('id', 1) job_core.addnode('name', 'Core_1') job_core.addnode('status', 'completed') job = run.addnode('job') job_core = job.addnode('core') job_core.addnode('id', 2) job_core.addnode('name', 'Core_2') job_core.addnode('status', 'failed') job = run.addnode('job') job_core = job.addnode('core') job_core.addnode('id', 3) job_core.addnode('name', 'Core_3') job_core.addnode('status', 'completed') self.testnode = run #testxml self.testxml = """<?xml version="1.0" ?><run><core><id>Run_Id</id></core><job><core><id>1</id><name>Core_1</name><status>completed</status></core></job><job><core><id>2</id><name>Core_2</name><status>failed</status></core></job><job><core><id>3</id><name>Core_3</name><status>completed</status></core></job></run>""" #testdom self.testdom = minidom.parseString(self.testxml)
def test_constructor(self): """Test __init__() creates a node.""" expected = Node.fromxml('<my-node/>') actual = Node('my-node') assert equal(expected, actual), 'created node is not as expected'
def test_fromxml(self): """Test fromxml() creates a node from XML string.""" expected = self.testnode actual = Node.fromxml(self.testxml) assert equal(expected, actual), 'node does not convert from xml as expected'
def test_fromdom(self): """Test fromdom() creates a node from XML DOM.""" expected = self.testnode actual = Node.fromdom(self.testdom) assert equal(expected, actual), 'node does not convert from dom as expected'
def test_addnode_value(self): """Test addnode() adds a node with a value.""" expected = Node.fromxml('<my-node><my-sub-node>my-value</my-sub-node></my-node>') actual = Node('my-node') actual.addnode('my-sub-node', 'my-value') assert equal(expected, actual), 'result of adding node is not as expected'
def test_constructor_value(self): """Test __init__() creates a node with a value.""" expected = Node.fromxml('<my-node>my-value</my-node>') actual = Node('my-node', 'my-value') assert equal(expected, actual), 'created node is not as expected'
def _loadextract(self, runid): filename = Utility.expand(self.getoption('BaseExtractor_XmlFile'), runid = runid) content = Utility.readfile(filename) return Node.fromxml(content)
def _loadextract(self, runid): filename = Utility.expand(self.getoption('BaseExtractor_XmlFile'), runid=runid) content = Utility.readfile(filename) return Node.fromxml(content)