def test_createApplicationDeviceAssignment(self): """ Tests that createApplication() allows the definition of a Device Assignment sequence """ sadfile = '/waveforms/TestCppProps/TestCppProps.sad.xml' name = 'TestWave' initConfig = {} devAssignment = [] nodebooter, devMgr = self.launchDeviceManager("/nodes/test_ExecutableDevice_node_2/DeviceManager.dcd.xml") devAssignment.append(CF.DeviceAssignmentType('DCE:87f4687e-6b67-458c-a32d-bef8f99a1064','')) self.assertEqual(len(self._rhDom._get_deviceManagers()), 2) dev_1 = self._rhDom.devMgrs[0].devs[0]._get_identifier() dev_2 = self._rhDom.devMgrs[1].devs[0]._get_identifier() devAssignment[0].assignedDeviceId = dev_1 app = self._rhDom.createApplication(sadfile, name, {}, devAssignment) self.assertNotEqual(app, None, 'Application not created') self.assertEquals(app._get_componentDevices()[0].assignedDeviceId, dev_1) app.releaseObject() devAssignment[0].assignedDeviceId = dev_2 app = self._rhDom.createApplication(sadfile, name, {}, devAssignment) self.assertNotEqual(app, None, 'Application not created') self.assertEquals(app._get_componentDevices()[0].assignedDeviceId, dev_2) app.releaseObject()
def test_DASAllocationFail(self): self._domMgr.installApplication( "/waveforms/CapacityUsage/CapacityUsage.sad.xml") # Start the first DeviceManager nb1, node1 = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=self.debuglevel) # Ensure the expected device is available self.assertNotEqual(node1, None) self.assertEqual(len(node1._get_registeredDevices()), 1) device1 = node1._get_registeredDevices()[0] self.assertEqual(self._getBogoMips(device1), 100000000) appFact = self._domMgr._get_applicationFactories()[0] # load the device assignment sequence das = minidom.parse( os.path.join(scatest.getSdrPath(), "dom/waveforms/CapacityUsage/CapacityUsage_DAS.xml")) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName( "deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) # Create two applications to take up the capacity of the first device # first on uses DAS app1 = appFact.create(appFact._get_name(), [], ds) self.assertEqual(self._getBogoMips(device1), 50000000) # second one is sans DAS app2 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 0) # Try to create another app, which should fail due to lack of capacity. # doing this with DAS since it exercises a different piece of code try: failApp = appFact.create(appFact._get_name(), [], ds) failApp.releaseObject() self.fail("Created application with no capacity") except: pass app2.releaseObject() self.assertEqual(self._getBogoMips(device1), 50000000) app1.releaseObject() self.assertEqual(self._getBogoMips(device1), 100000000) self._domMgr.uninstallApplication(appFact._get_identifier())
def buildDevSeq(dasXML): das = xml.dom.minidom.parse(dasXML) ds = [] for x in das.getElementsByTagName( 'deploymentenforcement')[0].getElementsByTagName( 'deviceassignmentsequence')[0].getElementsByTagName( 'deviceassignmenttype'): #print "component id:", x.componentid #print "assignmentdevid:", x.assigndeviceid compid = x.getElementsByTagName('componentid')[0].childNodes[0].data assgnid = x.getElementsByTagName( 'assigndeviceid')[0].childNodes[0].data ds.append(CF.DeviceAssignmentType(str(compid), str(assgnid))) return ds
def buildDevSeq(dasXML, fs): _xmlFile = fs.open(str(dasXML), True) buff = _xmlFile.read(_xmlFile.sizeOf()) _xmlFile.close() das = minidom.parseString(buff) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName( "deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) return ds
def BuildDevSeq(self, dasXML): #doc_das = xml.dom.minidom.parse(dasXML) doc_das = self.getDOM(dasXML) # create node list of "deviceassignmenttype" deviceassignmenttypeNodeList = doc_das.getElementsByTagName( "deviceassignmenttype") ds = [] for n in deviceassignmenttypeNodeList: componentid = n.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = n.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) return ds
def test_BasicOperation(self): nodebooter, domMgr = self.launchDomainManager() self.assertNotEqual(domMgr, None) self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication( "/waveforms/CommandWrapper/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) # Load on the device ID das = minidom.parse( os.path.join( scatest.getSdrPath(), "dom/waveforms/CommandWrapper/CommandWrapper_DAS.xml")) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName( "deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) # Ensure the expected device is available nodebooter, devMgr = self.launchDeviceManager( dcdFile="/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) self.assertEqual(len(ds), 1) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] self.assertEqual(device._get_identifier(), ds[0].assignedDeviceId) # Query the known allocation properties memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) # query all properties, make sure that only 'external' properties show up allProps = device.query([]) # convert props to a dict allProps = dict([(x.id, x.value) for x in allProps]) # This isn't all of them...but a fair amount self.assertEqual( allProps.has_key("DCE:4a23ad60-0b25-4121-a630-68803a498f75"), False) # os_name self.assertEqual( allProps.has_key("DCE:fefb9c66-d14a-438d-ad59-2cfd1adb272b"), False) # processor_name self.assertEqual( allProps.has_key("DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b"), False) # DeviceKind self.assertEqual( allProps.has_key("DCE:64303822-4c67-4c04-9a5c-bf670f27cf39"), False) # RunsAs self.assertEqual( allProps.has_key("DCE:021f10cf-7a05-46ec-a507-04b513b84bd4"), False) # HasXMIDAS appFact = domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], ds) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) self.assertEqual(app._get_started(), False) app.start() self.assertEqual(app._get_started(), True) # Verify that capacity was allocated memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000 - 5000) self.assertEqual(bogoMips.value._v, 100000000 - 1000) app.stop() self.assertEqual(app._get_started(), False) app.releaseObject() self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) # Verify that capacity was deallocated memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) domMgr.uninstallApplication(appFact._get_identifier())
def test_BasicOperation(self): self._nb_domMgr, self._domMgr = self.launchDomainManager( endpoint="giop:tcp::5679", dbURI=self._dbfile) self._nb_devMgr, devMgr = self.launchDeviceManager( "/nodes/test_PortTestDevice_node/DeviceManager.dcd.xml") self._fileMgr = self._domMgr._get_fileMgr() self._files = self._fileMgr.list("/") self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication( "/waveforms/PortConnectProvidesPort/PortConnectProvidesPort.sad.xml" ) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Load on the device ID das = minidom.parse( os.path.join( scatest.getSdrPath(), "dom/waveforms/PortConnectProvidesPort/PortConnectProvidesPort_DAS.xml" )) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName( "deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) # Ensure the expected device is available self.assertNotEqual(devMgr, None) self.assertEqual(len(devMgr._get_registeredDevices()), 2) device1 = None device2 = None for dev in devMgr._get_registeredDevices(): if dev._get_identifier( ) == "DCE:322fb9b2-de57-42a2-ad03-217bcb244262": device1 = dev elif dev._get_identifier( ) == "DCE:47dc45d8-19b5-4b7e-bcd4-b165babe5b84": device2 = dev self.assertNotEqual(device1, None) self.assertNotEqual(device2, None) # Query the known allocation properties memCapacity1 = device1.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips1 = device1.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity1.value._v, 100000000) self.assertEqual(bogoMips1.value._v, 100000000) memCapacity2 = device2.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips2 = device2.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity2.value._v, 100000000) self.assertEqual(bogoMips2.value._v, 100000000) appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], ds) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) app = self._domMgr._get_applications()[0] # cache off some variables for later for testing purposes self.assertEqual(len(app._get_componentNamingContexts()), 2) self.assertEqual(len(app._get_componentProcessIds()), 2) self.assertEqual(len(app._get_componentDevices()), 4) self.assertEqual(len(app._get_componentImplementations()), 2) origNamingContexts = app._get_componentNamingContexts() origProcessIds = app._get_componentProcessIds() origDevices = app._get_componentDevices() origImplementations = app._get_componentImplementations() origQuery = app.query([]) # Verify that capacity was allocated memCapacity1 = device1.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips1 = device1.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity1.value._v, 100000000 - (5000)) self.assertEqual(bogoMips1.value._v, 100000000 - (1000)) memCapacity2 = device2.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips2 = device2.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity2.value._v, 100000000 - (5000)) self.assertEqual(bogoMips2.value._v, 100000000 - (1000)) # Kill the domainMgr os.kill(self._nb_domMgr.pid, signal.SIGTERM) # TODO if SIGKILL is used (simulating a nodeBooter unexpected abort, # the IOR and the newly spawned domain manager do not work if not self.waitTermination(self._nb_domMgr): self.fail("Domain Manager Failed to Die") # Start the domainMgr again self._nb_domMgr, newDomMgr = self.launchDomainManager( endpoint="giop:tcp::5679", dbURI=self._dbfile) # Verify our client reference still is valid newDomMgr._get_identifier() self.assertEqual(False, newDomMgr._non_existent()) #self.assertEqual(self._orb.object_to_string(newDomMgr), self._orb.object_to_string(self._domMgr)) self.assertEqual(False, self._domMgr._non_existent()) # Verify that the file manager is still valid self.new_files = self._fileMgr.list("/") self.assertEqual(len(self._files), len(self.new_files)) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) newDevMgr = self._domMgr._get_deviceManagers()[0] self.assertEqual(self._orb.object_to_string(devMgr), self._orb.object_to_string(newDevMgr)) self.assertEqual(len(devMgr._get_registeredDevices()), 2) newDevice1 = None newDevice2 = None for dev in devMgr._get_registeredDevices(): if dev._get_identifier( ) == "DCE:322fb9b2-de57-42a2-ad03-217bcb244262": newDevice1 = dev elif dev._get_identifier( ) == "DCE:47dc45d8-19b5-4b7e-bcd4-b165babe5b84": newDevice2 = dev self.assertNotEqual(newDevice1, None) self.assertNotEqual(newDevice2, None) self.assertEqual(self._orb.object_to_string(device1), self._orb.object_to_string(newDevice1)) self.assertEqual(self._orb.object_to_string(device2), self._orb.object_to_string(newDevice2)) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) newAppFact = self._domMgr._get_applicationFactories()[0] self.assertEqual(appFact._get_identifier(), newAppFact._get_identifier()) self.assertEqual(appFact._get_name(), newAppFact._get_name()) self.assertEqual(len(self._domMgr._get_applications()), 1) newApp = self._domMgr._get_applications()[0] # Applications are currently not using persistent POAs, so the IORs will change # self.assertEqual(self._orb.object_to_string(app), self._orb.object_to_string(newApp)) newNamingContexts = app._get_componentNamingContexts() newProcessIds = app._get_componentProcessIds() newDevices = app._get_componentDevices() newImplementations = app._get_componentImplementations() # We have to compare elements individually since newDevices == origDevices even when the contents are identical self.assertEqual(len(newDevices), len(origDevices)) for x in xrange(len(newDevices)): self.assertEqual(newDevices[x].componentId, origDevices[x].componentId) self.assertEqual(newDevices[x].assignedDeviceId, origDevices[x].assignedDeviceId) self.assertEqual(len(newProcessIds), len(origProcessIds)) for x in xrange(len(newProcessIds)): self.assertEqual(newProcessIds[x].componentId, origProcessIds[x].componentId) self.assertEqual(newProcessIds[x].processId, origProcessIds[x].processId) self.assertEqual(len(newImplementations), len(origImplementations)) for x in xrange(len(newImplementations)): self.assertEqual(newImplementations[x].componentId, origImplementations[x].componentId) self.assertEqual(newImplementations[x].elementId, origImplementations[x].elementId) self.assertEqual(len(newNamingContexts), len(origNamingContexts)) for x in xrange(len(newNamingContexts)): self.assertEqual(newNamingContexts[x].componentId, origNamingContexts[x].componentId) self.assertEqual(newNamingContexts[x].elementId, origNamingContexts[x].elementId) # Verify that the connection between the CF::Application and the assemblyController was # restored. newQuery = app.query([]) self.assertEqual(len(newQuery), len(origQuery)) for x in xrange(len(newQuery)): self.assertEqual(newQuery[x].id, origQuery[x].id) self.assertEqual(newQuery[x].value._v, origQuery[x].value._v) # app.stop() app.releaseObject() # TODO how can we verify that the ports were disconnected as part of release? time.sleep(1) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Verify that capacity was deallocated memCapacity1 = device1.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips1 = device1.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity1.value._v, 100000000) self.assertEqual(bogoMips1.value._v, 100000000) memCapacity2 = device2.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips2 = device2.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity2.value._v, 100000000) self.assertEqual(bogoMips2.value._v, 100000000) newDevMgr.shutdown() self.assertEqual(len(self._domMgr._get_deviceManagers()), 0) self._domMgr.uninstallApplication(appFact._get_identifier()) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)