def tearDown(self):
        self.comp.releaseObject()
        sb.release()

        # Try to clean up the event channel, if it was created
        context = None
        try:
            channel = self._root.resolve(
                URI.stringToName('TEST_APPENDER/TEST_EVT_CH1'))
            channel = channel._narrow(CosEventChannelAdmin.EventChannel)
            channel.destroy()
        except:
            pass

        # Clean up naming context, too
        try:
            context = self._root.resolve(URI.stringToName('TEST_APPENDER'))
            context = context._narrow(CosNaming.NamingContext)
            self._root.unbind(URI.stringToName('TEST_APPENDER'))
            context.destroy()
        except:
            pass

        # Do all application shutdown before calling the base class tearDown,
        # or failures will probably occur.
        scatest.CorbaTestCase.tearDown(self)
    def test_MultipleDevicesWithSameName(self):
        # Test that two different device managers can start devices with the same name

        # TODO We should check that these two actually have a device that has the same name
        # because, if someone changes the XML unwittingly then this test will pass
        # without really testing anything
        nb1, devMgr1 = self.launchDeviceManager(
            "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml",
            debug=self.debuglevel)
        nb2, devMgr2 = self.launchDeviceManager(
            "/nodes/test_BasicTestDevice2_node/DeviceManager.dcd.xml",
            debug=self.debuglevel)

        self.assertEqual(len(self._domMgr._get_deviceManagers()), 2)
        for devMgr in self._domMgr._get_deviceManagers():
            self.assertEqual(len(devMgr._get_registeredDevices()), 1)

        # Although nothing in the spec specifies where a device is to be bound
        # ossie does /DomainName/DevicemgrName/DeviceName, so let's check that now
        # to ensure the behavior remains consistent
        dev1Name = URI.stringToName(scatest.getTestDomainName() +
                                    "/BasicTestDevice_node/BasicTestDevice1")
        dev2Name = URI.stringToName(scatest.getTestDomainName() +
                                    "/BasicTestDevice2_node/BasicTestDevice1")

        dev1 = self._root.resolve(dev1Name)._narrow(CF.Device)
        dev2 = self._root.resolve(dev2Name)._narrow(CF.Device)
        self.assertNotEqual(dev1, None)
        self.assertNotEqual(dev2, None)
예제 #3
0
    def test_RestartDomainConnectEvents(self):
        # launch DomainManager
        self._nb_domMgr, self._domMgr = self.launchDomainManager()
        self.assertNotEqual(self._domMgr, None)
        # get domain name
        domain_name = self._domMgr._get_name()
        self.assertNotEqual(domain_name, None)

        # check ODM/IDM channel
        ns_ODM = URI.stringToName("%s/%s" % (domain_name, "ODM_Channel"))
        ns_IDM = URI.stringToName("%s/%s" % (domain_name, "IDM_Channel"))
        orig_ODM_ref = self._root.resolve(ns_ODM)
        orig_IDM_ref = self._root.resolve(ns_IDM)
        self.assertNotEqual(orig_ODM_ref, None)
        self.assertNotEqual(orig_IDM_ref, None)

        ## kill domain manager
        os.kill(self._nb_domMgr.pid, signal.SIGKILL)
        if not self.waitTermination(self._nb_domMgr, 5.0):
            self.fail("Domain Manager Failed to Die")

        # remove old log file
        try:
            os.remove("./sdr/domtest.log")
        except:
            pass

        # restart domain manager
        self._nb_domMgr, self._domMgr = self.launchDomainManager(
            loggingURI='file://' + os.getcwd() + '/domtest.cfg', debug=3)
        self.assertNotEqual(self._domMgr, None)
        # get domain name
        domain_name = self._domMgr._get_name()
        self.assertNotEqual(domain_name, None)

        # check ODM/IDM channel
        ns_ODM = URI.stringToName("%s/%s" % (domain_name, "ODM_Channel"))
        ns_IDM = URI.stringToName("%s/%s" % (domain_name, "IDM_Channel"))
        orig_ODM_ref = self._root.resolve(ns_ODM)
        orig_IDM_ref = self._root.resolve(ns_IDM)
        self.assertNotEqual(orig_ODM_ref, None)
        self.assertNotEqual(orig_IDM_ref, None)

        # check for failed create channel message
        cnt = -1
        try:
            f = open("./sdr/domtest.log")
            cnt = 0
            for x in f.readlines():
                if re.search('.*[ODM|IDM] Channel create FAILED.*', x):
                    cnt += 1
        except:
            pass

        self.assertEqual(cnt, 0)
    def _test_BasicService(self, node, expected_name):
        devmgr_nb, devMgr = self.launchDeviceManager("/nodes/" + node +
                                                     "/DeviceManager.dcd.xml",
                                                     debug=1)
        self.assertEqual(len(devMgr._get_registeredServices()), 1)
        svc = devMgr._get_registeredServices()[0]
        self.assertNotEqual(svc, None)
        self.assertEqual(svc.serviceName, expected_name)
        self.assertNotEqual(svc.serviceObject, None)
        obj = svc.serviceObject
        obj = obj._narrow(CF.PropertySet)
        self.assertNotEqual(obj, None)

        # Check the name service to ensure the service is properly bound
        svcName = URI.stringToName(scatest.getTestDomainName() + "/" +
                                   expected_name)
        svcobj = self._root.resolve(svcName)._narrow(CF.PropertySet)
        self.assertNotEqual(svcobj, None)
        self.assert_(obj._is_equivalent(svcobj))

        # Check that all the parameters got set correctly
        props = obj.query([])
        d = dict([(p.id, any.from_any(p.value)) for p in props])
        self.assertEqual(d["SERVICE_NAME"], expected_name)
        self.assertEqual(d["DEVICE_MGR_IOR"],
                         self._orb.object_to_string(devMgr))
        self.assertEqual(d["PARAM1"], "ABCD")
        self.assertEqual(d["PARAM2"], 42)
        self.assertAlmostEqual(d["PARAM3"], 3.1459)
        self.assertEqual(d["PARAM4"], False)
        self.assertEqual(d["PARAM5"], "Hello World")
        self.assertEqual(d.has_key("PARAM6"), False)

        # Check that we unregister correctly
        os.kill(devmgr_nb.pid, signal.SIGTERM)

        svcName = URI.stringToName(scatest.getTestDomainName() + "/" +
                                   expected_name)
        time_begin = time.time()
        time_end = time.time()
        name_found = True
        while ((time_end - time_begin) < 2) and name_found:
            time_end = time.time()
            # Don't use assertRaises, so we can simplify things
            try:
                self._root.resolve(svcName)._narrow(CF.PropertySet)
                time.sleep(0.1)
            except CosNaming.NamingContext.NotFound:
                name_found = False
        if name_found:
            self.fail("Expected service to not exist in the naming service")
    def test_EventDevicePortConnection(self):
        self.localEvent = threading.Event()
        self.eventFlag = False
        
        self._devBooter, self._devMgr = self.launchDeviceManager("/nodes/test_EventPortTestDevice_node/DeviceManager.dcd.xml", self._domMgr, debug=self.debuglevel)
        time.sleep(1)   # this sleep is here for the connections to be established to the event service

        domainName = scatest.getTestDomainName()

        channelName = URI.stringToName("%s/%s" % (domainName, 'deviceEvent'))
        try:
            devChannel = self._root.resolve(channelName)._narrow(CosEventChannelAdmin__POA.EventChannel)
        except:
            self.assertEqual(False, True)
        else:
            self.assertEqual(True, True)

        # resolve the producer for the event
        supplier_admin = devChannel.for_suppliers()
        _proxy_consumer = supplier_admin.obtain_push_consumer()
        _supplier = Supplier_i()
        _proxy_consumer.connect_push_supplier(_supplier._this())

        # resolve the consumer for the event
        consumer_admin = devChannel.for_consumers()
        _proxy_supplier = consumer_admin.obtain_push_supplier()
        _consumer = ConsumerDevice_i(self)
        _proxy_supplier.connect_push_consumer(_consumer._this())

        _proxy_consumer.push(any.to_any("message device"))
        self.localEvent.wait(5.0)
        self.assertEqual(self.eventFlag, True)
    def test_EventAppPortConnection(self):
        self.localEvent = threading.Event()
        self.eventFlag = False
        
        self._devBooter, self._devMgr = self.launchDeviceManager("/nodes/test_EventPortTestDevice_node/DeviceManager.dcd.xml", self._domMgr, debug=self.debuglevel)
        domainName = scatest.getTestDomainName()
        self._domMgr.installApplication("/waveforms/PortConnectFindByDomainFinderEvent/PortConnectFindByDomainFinderEvent.sad.xml")
        appFact = self._domMgr._get_applicationFactories()[0]
        app = appFact.create(appFact._get_name(), [], [])
        app.start()
        channelName = URI.stringToName("%s/%s" % (domainName, 'anotherChannel'))
        try:
            appChannel = self._root.resolve(channelName)._narrow(CosEventChannelAdmin__POA.EventChannel)
        except:
            self.assertEqual(False, True)
        else:
            self.assertEqual(True, True)

        # resolve the producer for the event
        supplier_admin = appChannel.for_suppliers()
        _proxy_consumer = supplier_admin.obtain_push_consumer()
        _supplier = Supplier_i()
        _proxy_consumer.connect_push_supplier(_supplier._this())

        # resolve the consumer for the event
        consumer_admin = appChannel.for_consumers()
        _proxy_supplier = consumer_admin.obtain_push_supplier()
        _consumer = Consumer_i(self)
        _proxy_supplier.connect_push_consumer(_consumer._this())

        _proxy_consumer.push(any.to_any("message"))
        self.localEvent.wait(5.0)
        self.assertEqual(self.eventFlag, True)

        app.releaseObject()
    def test_DeviceManagerSurprise(self):
        self._nb_domMgr, self._domMgr = self.launchDomainManager(
            endpoint="giop:tcp::5679", dbURI=self._dbfile)
        self.assertEqual(len(self._domMgr._get_deviceManagers()), 0)

        # Kill the domainMgr
        os.kill(self._nb_domMgr.pid, signal.SIGKILL)
        if not self.waitTermination(self._nb_domMgr):
            self.fail("Domain Manager Failed to Die")

        self._nb_devMgr, devMgr = self.launchDeviceManager(
            "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml",
            wait=False)
        # this sleep is needed to allow the Device Manager to figure out that the Domain Manager is not available
        time.sleep(1)

        # Start the domainMgr again
        self._nb_domMgr, newDomMgr = self.launchDomainManager(
            endpoint="giop:tcp::5679", dbURI=self._dbfile)
        time.sleep(
            1
        )  # sleep needed to make sure that the Device Manager has registered with the Domain Manager

        node_name = 'BasicTestDevice_node'
        domainName = scatest.getTestDomainName()
        devMgrURI = URI.stringToName("%s/%s/BasicTestDevice1" %
                                     (domainName, node_name))
        dev = self._root.resolve(devMgrURI)
        self.assertNotEqual(dev, None)

        self.assertEqual(len(self._domMgr._get_deviceManagers()), 1)
 def test_EventDevicePortConnection(self):
     self.localEvent = threading.Event()
     self.eventFlag = False
     
     self._devBooter, self._devMgr = self.launchDeviceManager("/nodes/test_EventPortTestDevice_node/DeviceManager.dcd.xml", self._domMgr, debug=9)
     time.sleep(1)   # this sleep is here for the connections to be established to the event service
     
     domainName = scatest.getTestDomainName()
     
     channelName = URI.stringToName("%s/%s" % (domainName, 'deviceEvent'))
     try:
         devChannel = self._root.resolve(channelName)._narrow(CosEventChannelAdmin__POA.EventChannel)
     except:
         self.assertEqual(False, True)
     else:
         self.assertEqual(True, True)
     
     # resolve the producer for the event
     supplier_admin = devChannel.for_suppliers()
     _proxy_consumer = supplier_admin.obtain_push_consumer()
     _supplier = Supplier_i()
     _proxy_consumer.connect_push_supplier(_supplier._this())
     
     # resolve the consumer for the event
     consumer_admin = devChannel.for_consumers()
     _proxy_supplier = consumer_admin.obtain_push_supplier()
     _consumer = ConsumerDevice_i(self)
     _proxy_supplier.connect_push_consumer(_consumer._this())
     
     _proxy_consumer.push(any.to_any("message device"))
     self.localEvent.wait(5.0)
     self.assertEqual(self.eventFlag, True)
 def test_EventAppPortConnection(self):
     self.localEvent = threading.Event()
     self.eventFlag = False
     
     self._devBooter, self._devMgr = self.launchDeviceManager("/nodes/test_EventPortTestDevice_node/DeviceManager.dcd.xml", self._domMgr, debug=9)
     domainName = scatest.getTestDomainName()
     self._domMgr.installApplication("/waveforms/PortConnectFindByDomainFinderEvent/PortConnectFindByDomainFinderEvent.sad.xml")
     appFact = self._domMgr._get_applicationFactories()[0]
     app = appFact.create(appFact._get_name(), [], [])
     app.start()
     channelName = URI.stringToName("%s/%s" % (domainName, 'anotherChannel'))
     try:
         appChannel = self._root.resolve(channelName)._narrow(CosEventChannelAdmin__POA.EventChannel)
     except:
         self.assertEqual(False, True)
     else:
         self.assertEqual(True, True)
     
     # resolve the producer for the event
     supplier_admin = appChannel.for_suppliers()
     _proxy_consumer = supplier_admin.obtain_push_consumer()
     _supplier = Supplier_i()
     _proxy_consumer.connect_push_supplier(_supplier._this())
     
     # resolve the consumer for the event
     consumer_admin = appChannel.for_consumers()
     _proxy_supplier = consumer_admin.obtain_push_supplier()
     _consumer = Consumer_i(self)
     _proxy_supplier.connect_push_consumer(_consumer._this())
     
     _proxy_consumer.push(any.to_any("message"))
     self.localEvent.wait(5.0)
     self.assertEqual(self.eventFlag, True)
     
     app.releaseObject()
    def test_nodeBooterDomainNameOverride(self):
        """Test that we can allow the user to override the domainname with the --domainname argument."""
        domainName = scatest.getTestDomainName()
        domainMgrURI = URI.stringToName("%s/%s" % (domainName, domainName))
        # Test that we don't already have a bound domain
        try:
            domMgr = self._root.resolve(domainMgrURI)
            self.assertEqual(domMgr, None)
        except CosNaming.NamingContext.NotFound:
            pass # This exception is expected

        nb = Popen("../../control/framework/nodeBooter -D --domainname %s -debug 9 --nopersist" % (domainName), cwd=scatest.getSdrPath(), shell=True)
        time.sleep(5)

        # Test that the name exists and is a DomainManager
        domMgr = self._root.resolve(domainMgrURI)._narrow(CF.DomainManager)
        self.assertNotEqual(domMgr, None)

        # Kill the nodebooter
        os.kill(nb.pid, signal.SIGINT)
        time.sleep(5) # Give it time to shutdown
        self.assertEqual(nb.poll(), 0)

        # Test that we cleaned up the name; this should be automatic because
        # the naming context should be empty.
        try:
            domMgr = self._root.resolve(domainMgrURI)
            self.assertEqual(domMgr, None)
        except CosNaming.NamingContext.NotFound:
            pass # This exception is expected
예제 #11
0
    def createEventChannel(self, eventChannelName, domainName=None, force=False):
        """
        Creates an event channel, if it already exists return it. The
        event channel is bound into the name service as 'eventChannelName',
        in the context specified by 'domainName', or the root naming context
        if 'domainName' is not given.

        If force == True and the event channel already exists, destroy it and create a new one.
        """
        eventChannel = self.getEventChannel(eventChannelName, domainName)
        if eventChannel:
            if force or eventChannel._non_existent():
                self.destroyEventChannel(eventChannelName, domainName)
            else:
                return eventChannel._narrow(CosEventChannelAdmin.EventChannel)

        factory = self.getEventChannelFactory()
        if not factory:
            return None

        name = self._getEventChannelName(eventChannelName, domainName)
        key = [CosNaming.NameComponent("EventChannel","object interface")]
        criteria = [CosLifeCycle.NameValuePair(name="InsName",value=any.to_any(name))]

        try:
            eventChannel = factory.create_object(key,criteria)._narrow(CosEventChannelAdmin.EventChannel)
        except:
            return None

        bindingName = URI.stringToName(name)
        self.rootContext.rebind(bindingName, eventChannel)

        return eventChannel
예제 #12
0
    def test_cpp_DirectoryLoad(self):
        self.assertNotEqual(self._domMgr, None)

        # Verify in the devices cache is emtpy
        componentDir = os.path.join(scatest.getSdrPath(), "dom", "components",
                                    "CommandWrapperWithDirectoryLoad")
        deviceCacheDir = os.path.join(scatest.getSdrCache(),
                                      ".ExecutableDevice_node",
                                      "ExecutableDevice1", "components",
                                      "CommandWrapperWithDirectoryLoad")
        if os.path.exists(deviceCacheDir):
            os.system("rm -rf %s" % deviceCacheDir)

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.installApplication(
            "/waveforms/CommandWrapperWithDirectoryLoad/CommandWrapper.sad.xml"
        )
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Ensure the expected device is available
        devBooter, devMgr = self.launchDeviceManager(
            "/nodes/test_ExecutableDevice_node/DeviceManager.dcd.xml")
        self.assertNotEqual(devMgr, None)
        self.assertEqual(len(devMgr._get_registeredDevices()), 1)
        device = devMgr._get_registeredDevices()[0]

        appFact = self._domMgr._get_applicationFactories()[0]

        app = appFact.create(appFact._get_name(), [], [])  # LOOK MA, NO DAS!

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 1)

        # Verify that properties have been changed from their defaults
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(
            compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        cmd = comp.query([
            CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e",
                        value=any.to_any(None))
        ])[0]
        args = comp.query([
            CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53",
                        value=any.to_any(None))
        ])[0]
        self.assertEqual(cmd.value._v, "/bin/echo")
        self.assertEqual(args.value._v, ["Hello World"])

        app.stop()
        app.releaseObject()
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.uninstallApplication(appFact._get_identifier())
    def test_nodeBooterDomainNameOverride(self):
        """Test that we can allow the user to override the domainname with the --domainname argument."""
        domainName = scatest.getTestDomainName()
        domainMgrURI = URI.stringToName("%s/%s" % (domainName, domainName))
        # Test that we don't already have a bound domain
        try:
            domMgr = self._root.resolve(domainMgrURI)
            self.assertEqual(domMgr, None)
        except CosNaming.NamingContext.NotFound:
            pass # This exception is expected
        args = ["../../control/framework/nodeBooter","-D", "--domainname", domainName, "-debug", "9","--nopersist" ]
        nb = Popen(args, cwd=scatest.getSdrPath() )
        domMgr = self.waitDomainManager(domainMgrURI)
        self.assertNotEqual(domMgr, None)

        # Kill the nodebooter
        os.kill(nb.pid, signal.SIGINT)
        self.assertPredicateWithWait(lambda: nb.poll() == 0)

        # Test that we cleaned up the name; this should be automatic because
        # the naming context should be empty.
        try:
            domMgr = self._root.resolve(domainMgrURI)
            self.assertEqual(domMgr, None)
        except CosNaming.NamingContext.NotFound:
            pass # This exception is expected
예제 #14
0
    def test_nodeBooterDomainNameOverride(self):
        """Test that we can allow the user to override the domainname with the --domainname argument."""
        domainName = scatest.getTestDomainName()
        domainMgrURI = URI.stringToName("%s/%s" % (domainName, domainName))
        # Test that we don't already have a bound domain
        try:
            domMgr = self._root.resolve(domainMgrURI)
            self.assertEqual(domMgr, None)
        except CosNaming.NamingContext.NotFound:
            pass # This exception is expected

        nb = Popen("../../control/framework/nodeBooter -D --domainname %s -debug 9 --nopersist" % (domainName), cwd=scatest.getSdrPath(), shell=True)
        domMgr = self.waitDomainManager(domainMgrURI)
        self.assertNotEqual(domMgr, None)

        # Kill the nodebooter
        os.kill(nb.pid, signal.SIGINT)
        self.assertPredicateWithWait(lambda: nb.poll() == 0)

        # Test that we cleaned up the name; this should be automatic because
        # the naming context should be empty.
        try:
            domMgr = self._root.resolve(domainMgrURI)
            self.assertEqual(domMgr, None)
        except CosNaming.NamingContext.NotFound:
            pass # This exception is expected
예제 #15
0
    def destroyEventChannel(self, eventChannelName, domainName=None):
        """
        Destroys an existing event channel.
        """
        eventChannel = self.getEventChannel(eventChannelName, domainName)
        if not eventChannel:
            return

        # Forcibly unbind the name first.
        nameBinding = URI.stringToName(self._getEventChannelName(eventChannelName, domainName))
        try:
            self.rootContext.unbind(nameBinding)
        except:
            pass

        # Try to destroy the EventChannel, noting that it could be
        # unreachable even if it was found.
        try:
            # omniEvents requires a small pause to allow the EventChannel
            # to be fully destroyed, otherwise a subsequent creation may
            # fail (as though it still existed).
            eventChannel.destroy()
            while not eventChannel._non_existent():
                _time.sleep(0.1)
        except:
            pass
 def _getComponents(self):
     # Get references to the waveform's components.
     components = {}
     for compName in self._app._get_componentNamingContexts():
         usageName = compName.elementId.split('/')[-1]
         components[usageName] = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
     return components
예제 #17
0
 def _getComponents(self):
     # Get references to the waveform's components.
     components = {}
     for compName in self._app._get_componentNamingContexts():
         usageName = compName.elementId.split('/')[-1]
         components[usageName] = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
     return components
예제 #18
0
    def destroyEventChannel(self, eventChannelName, domainName=None):
        """
        Destroys an existing event channel.
        """
        eventChannel = self.getEventChannel(eventChannelName, domainName)
        if not eventChannel:
            return

        # Forcibly unbind the name first.
        nameBinding = URI.stringToName(
            self._getEventChannelName(eventChannelName, domainName))
        try:
            self.rootContext.unbind(nameBinding)
        except:
            pass

        # Try to destroy the EventChannel, noting that it could be
        # unreachable even if it was found.
        try:
            # omniEvents requires a small pause to allow the EventChannel
            # to be fully destroyed, otherwise a subsequent creation may
            # fail (as though it still existed).
            eventChannel.destroy()
            while not eventChannel._non_existent():
                time.sleep(0.1)
        except:
            pass
    def _test_BasicService(self, node, expected_name):
        devmgr_nb, devMgr = self.launchDeviceManager("/nodes/"+node+"/DeviceManager.dcd.xml", debug=1)
        self.assertEqual(len(devMgr._get_registeredServices()), 1)
        svc = devMgr._get_registeredServices()[0]
        self.assertNotEqual(svc, None)
        self.assertEqual(svc.serviceName, expected_name)
        self.assertNotEqual(svc.serviceObject, None)
        obj = svc.serviceObject
        obj = obj._narrow(CF.PropertySet)
        self.assertNotEqual(obj, None)

        # Check the name service to ensure the service is properly bound
        svcName = URI.stringToName(scatest.getTestDomainName() + "/" + expected_name)
        svcobj = self._root.resolve(svcName)._narrow(CF.PropertySet)
        self.assertNotEqual(svcobj, None)
        self.assert_(obj._is_equivalent(svcobj))

        # Check that all the parameters got set correctly
        props = obj.query([])
        d = dict([(p.id, any.from_any(p.value)) for p in props])
        self.assertEqual(d["SERVICE_NAME"], expected_name)
        self.assertEqual(d["DEVICE_MGR_IOR"], self._orb.object_to_string(devMgr))
        self.assertEqual(d["PARAM1"], "ABCD")
        self.assertEqual(d["PARAM2"], 42)
        self.assertAlmostEqual(d["PARAM3"], 3.1459)
        self.assertEqual(d["PARAM4"], False)
        self.assertEqual(d["PARAM5"], "Hello World")
        self.assertEqual(d.has_key("PARAM6"), False)

        # Check that we unregister correctly
        os.kill(devmgr_nb.pid, signal.SIGTERM)

        svcName = URI.stringToName(scatest.getTestDomainName() + "/" + expected_name)
        time_begin = time.time()
        time_end = time.time()
        name_found = True
        while ((time_end - time_begin) < 2) and name_found:
            time_end = time.time()
            # Don't use assertRaises, so we can simplify things
            try:
                self._root.resolve(svcName)._narrow(CF.PropertySet)
                time.sleep(0.1)
            except CosNaming.NamingContext.NotFound:
                name_found = False
        if name_found:
            self.fail("Expected service to not exist in the naming service")
 def test_NSCleanup(self):
     domain_name = self._domMgr._get_name()
     ns_domMgr = URI.stringToName("%s/%s" % (domain_name, domain_name))
     ns_domMgrCtx = URI.stringToName("%s" % (domain_name))
     ns_ODM = URI.stringToName("%s/%s" % (domain_name, "ODM_Channel"))
     ns_IDM = URI.stringToName("%s/%s" % (domain_name, "IDM_Channel"))
     domCtx_ref = self._root.resolve(ns_domMgrCtx)
     domMgr_ref = self._root.resolve(ns_domMgr)
     ODM_ref = self._root.resolve(ns_ODM)
     IDM_ref = self._root.resolve(ns_IDM)
     self.assertNotEqual(domCtx_ref, None)
     self.assertNotEqual(domMgr_ref, None)
     self.assertNotEqual(ODM_ref, None)
     self.assertNotEqual(IDM_ref, None)
     os.kill(self._domainBooter.pid, signal.SIGINT)
     self.waitTermination(self._domainBooter)
     self.assertRaises(CosNaming.NamingContext.NotFound, self._root.resolve, ns_domMgrCtx)
 def test_NSCleanup(self):
     domain_name = self._domMgr._get_name()
     ns_domMgr = URI.stringToName("%s/%s" % (domain_name, domain_name))
     ns_domMgrCtx = URI.stringToName("%s" % (domain_name))
     ns_ODM = URI.stringToName("%s/%s" % (domain_name, "ODM_Channel"))
     ns_IDM = URI.stringToName("%s/%s" % (domain_name, "IDM_Channel"))
     domCtx_ref = self._root.resolve(ns_domMgrCtx)
     domMgr_ref = self._root.resolve(ns_domMgr)
     ODM_ref = self._root.resolve(ns_ODM)
     IDM_ref = self._root.resolve(ns_IDM)
     self.assertNotEqual(domCtx_ref, None)
     self.assertNotEqual(domMgr_ref, None)
     self.assertNotEqual(ODM_ref, None)
     self.assertNotEqual(IDM_ref, None)
     os.kill(self._domainBooter.pid, signal.SIGINT)
     self.waitTermination(self._domainBooter)
     self.assertRaises(CosNaming.NamingContext.NotFound, self._root.resolve, ns_domMgrCtx)
    def test_EventAppPortConnectionSIGQUIT(self):
        self.localEvent = threading.Event()
        self.eventFlag = False

        self._nb_domMgr, domMgr = self.launchDomainManager(endpoint="giop:tcp::5679", dbURI=self._dbfile)
        self._nb_devMgr, devMgr = self.launchDeviceManager("/nodes/test_EventPortTestDevice_node/DeviceManager.dcd.xml")

        domainName = scatest.getTestDomainName()
        domMgr.installApplication("/waveforms/PortConnectFindByDomainFinderEvent/PortConnectFindByDomainFinderEvent.sad.xml")
        appFact = domMgr._get_applicationFactories()[0]
        app = appFact.create(appFact._get_name(), [], [])
        app.start()

        # Kill the domainMgr
        os.kill(self._nb_domMgr.pid, signal.SIGQUIT)
        if not self.waitTermination(self._nb_domMgr, 5.0):
            self.fail("Domain Manager Failed to Die")

        # Restart the Domain Manager (which should restore the old channel)
        self._nb_domMgr, domMgr = self.launchDomainManager(endpoint="giop:tcp::5679", dbURI=self._dbfile)

        newappFact = domMgr._get_applicationFactories()[0]
        app2 = newappFact.create(appFact._get_name(), [], [])
        app2.start()
        channelName = URI.stringToName("%s/%s" % (domainName, 'anotherChannel'))
        try:
            appChannel = self._root.resolve(channelName)._narrow(CosEventChannelAdmin.EventChannel)
        except:
            self.assertEqual(False, True)
        else:
            self.assertEqual(True, True)

        # resolve the producer for the event
        supplier_admin = appChannel.for_suppliers()
        _proxy_consumer = supplier_admin.obtain_push_consumer()
        _supplier = Supplier_i()
        _proxy_consumer.connect_push_supplier(_supplier._this())

        # resolve the consumer for the event
        consumer_admin = appChannel.for_consumers()
        _proxy_supplier = consumer_admin.obtain_push_supplier()
        _consumer = Consumer_i(self)
        _proxy_supplier.connect_push_consumer(_consumer._this())

        # a flag is raised only when two responses come back (one for each running app)
        _proxy_consumer.push(any.to_any("message"))
        self.localEvent.wait(5.0)
        self.assertEqual(self.eventFlag, True)

        self.eventFlag = False
        # this step tests whether the number of subscribers to the channel is restored
        app2.releaseObject()

        self.localEvent.clear()
        _proxy_consumer.push(any.to_any("message"))
        self.localEvent.wait(5.0)
        self.assertEqual(self.eventFlag, True)
        app.releaseObject()
    def test_ApplicationFactoryCreateURIOverride(self):
        domNB, domMgr = self.launchDomainManager(loggingURI="dom/mgr/logging.properties")
        self.assertNotEqual(domMgr, None)

        # Launch a device manager
        devNB, devMgr = self.launchDeviceManager(
            "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", loggingURI="dev/mgr/logging.properties"
        )
        self.assertNotEqual(domMgr, None)

        # Double check the DomainManager LOGGING_CONFIG_URI
        prop = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any(None))
        result = domMgr.query([prop])
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].id, "LOGGING_CONFIG_URI")
        devLoggingConfigURI = result[0].value._v
        expectedDomLoggingConfigUri = "file://" + os.path.join(scatest.getSdrPath(), "dom/mgr/logging.properties")
        self.assertEqual(devLoggingConfigURI, expectedDomLoggingConfigUri)

        # Launch an application
        domMgr.installApplication("/waveforms/CommandWrapper/CommandWrapper.sad.xml")
        self.assertEqual(len(domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(domMgr._get_applications()), 0)

        appFact = domMgr._get_applicationFactories()[0]
        uriOverride = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any("sca:///mgr/logging.properties"))
        app = appFact.create(appFact._get_name(), [uriOverride], [])

        # Get the desired component
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        # Check the components exec params
        execparams = comp.query([CF.DataType(id="DCE:85d133fd-1658-4e4d-b3ff-1443cd44c0e2", value=any.to_any(None))])[0]
        args = any.from_any(execparams.value)
        execparams = {}
        for b in args:
            a = eval(b)
            name = a[0]
            value = a[1]
            execparams[name] = value

        self.assert_(execparams.has_key("LOGGING_CONFIG_URI"))
        self.assertEqual(execparams["LOGGING_CONFIG_URI"].split("?fs=")[0], "sca:///mgr/logging.properties")
        execparamObj = self._orb.string_to_object(execparams["LOGGING_CONFIG_URI"].split("?fs=")[1])
        # Need to compare actual objects since the IOR strings could potentially differ for the same object
        self.assert_(domMgr._get_fileMgr()._is_equivalent(execparamObj))

        # Launch an application with a C++ component to exercise Resource_impl logging configure
        domMgr.installApplication("/waveforms/TestCppProps/TestCppProps.sad.xml")
        self.assertEqual(len(domMgr._get_applicationFactories()), 2)
        for appFact in domMgr._get_applicationFactories():
            if appFact._get_name() == "TestCppProps":
                app = appFact.create(appFact._get_name(), [uriOverride], [])
                break
        self.assertEqual(len(domMgr._get_applications()), 2)
    def _test_py_SharedLibraryLoad(self, node):
        self.assertNotEqual(self._domMgr, None)

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Verify in the devices cache is empty
        componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "pythonSoftpkgDep")
        deviceCacheDir = os.path.join(scatest.getSdrCache(), ".test_GPP_node", "GPP_1", "components", "pythonSoftpkgDep")
        if os.path.exists(deviceCacheDir):
            os.system("rm -rf %s" % deviceCacheDir)

        self._domMgr.installApplication("/waveforms/python_softpkg_deps/python_softpkg_deps.sad.xml")
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Ensure the expected device is available
        devBooter, devMgr = self.launchDeviceManager(node)
        self.assertNotEqual(devMgr, None)
        self.assertEqual(len(devMgr._get_registeredDevices()), 1)
        device = devMgr._get_registeredDevices()[0]

        appFact = self._domMgr._get_applicationFactories()[0]

        app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS!

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 1)

        # Verify that properties have been changed from their defaults
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        cmd = comp.query([CF.DataType(id="prop1", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "hello")
        cmd = comp.query([CF.DataType(id="prop2", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "world")
        cmd = comp.query([CF.DataType(id="prop3", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "helloworld")

        comp.start()
        
        cmd = comp.query([CF.DataType(id="prop1", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "jones")
        cmd = comp.query([CF.DataType(id="prop2", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "goober")
        cmd = comp.query([CF.DataType(id="prop3", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "testing")

        app.stop()
        app.releaseObject()
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.uninstallApplication(appFact._get_identifier())
예제 #25
0
    def test_ApplicationFactoryCreateURIOverride(self):
        domNB, domMgr = self.launchDomainManager(loggingURI="dom/mgr/logging.properties")
        self.assertNotEqual(domMgr, None)

        # Launch a device manager
        devNB, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", loggingURI="dev/mgr/logging.properties")
        self.assertNotEqual(domMgr, None)

        # Double check the DomainManager LOGGING_CONFIG_URI
        prop = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any(None))
        result = domMgr.query([prop])
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].id, "LOGGING_CONFIG_URI")
        devLoggingConfigURI = result[0].value._v
        expectedDomLoggingConfigUri = "file://" + os.path.join(scatest.getSdrPath(), "dom/mgr/logging.properties")
        self.assertEqual(devLoggingConfigURI, expectedDomLoggingConfigUri)

        # Launch an application
        domMgr.installApplication("/waveforms/CommandWrapper/CommandWrapper.sad.xml")
        self.assertEqual(len(domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(domMgr._get_applications()), 0)

        appFact = domMgr._get_applicationFactories()[0]
        uriOverride = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any("sca:///mgr/logging.properties"))
        app = appFact.create(appFact._get_name(), [uriOverride], [])

        # Get the desired component
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        # Check the components exec params
        execparams = comp.query([CF.DataType(id="DCE:85d133fd-1658-4e4d-b3ff-1443cd44c0e2", value=any.to_any(None))])[0]
        args = any.from_any(execparams.value)
        execparams = {}
        for b in args:
            a = eval(b)
            name = a[0]
            value = a[1]
            execparams[name] = value

        self.assert_(execparams.has_key("LOGGING_CONFIG_URI"))
        self.assertEqual(execparams["LOGGING_CONFIG_URI"].split("?fs=")[0], "sca:///mgr/logging.properties")
        execparamObj = self._orb.string_to_object(execparams["LOGGING_CONFIG_URI"].split("?fs=")[1])
        # Need to compare actual objects since the IOR strings could potentially differ for the same object
        self.assert_(domMgr._get_fileMgr()._is_equivalent(execparamObj))

        # Launch an application with a C++ component to exercise Resource_impl logging configure
        domMgr.installApplication("/waveforms/TestCppProps/TestCppProps.sad.xml")
        self.assertEqual(len(domMgr._get_applicationFactories()), 2)
        for appFact in domMgr._get_applicationFactories():
            if appFact._get_name() == "TestCppProps":
                app = appFact.create(appFact._get_name(), [uriOverride], [])
                break
        self.assertEqual(len(domMgr._get_applications()), 2)
예제 #26
0
    def setup (self, domainName, *args):
        self.domainName = domainName
        try:
            self.domMgr = self.inc.resolve(URI.stringToName('/'.join([domainName]*2)))
        except:
            print >>sys.stderr, "Unable to connect to domain manager for domain", domainName
            sys.exit(1)

        print 'Arguments: ', ' '.join(args)
        self.initialize(*args)
예제 #27
0
    def setup(self, domainName, *args):
        self.domainName = domainName
        try:
            self.domMgr = self.inc.resolve(
                URI.stringToName('/'.join([domainName] * 2)))
        except:
            print >> sys.stderr, "Unable to connect to domain manager for domain", domainName
            sys.exit(1)

        print 'Arguments: ', ' '.join(args)
        self.initialize(*args)
예제 #28
0
 def next_one(self):
     b = None
     res = True
     try:
       x = self.keys.pop(0)
       name = URI.stringToName(x)
       b = CosNaming.Binding(name, self.object_table[x][1])
     except:
       res = False
       self.destroy()
     return (res, b)
예제 #29
0
def launchDomain(number, root):
    domainName = scatest.getTestDomainName() + '_' + str(number)
    _domainBooter = scatest.spawnNodeBooter(dmdFile='', domainname=domainName)
    while _domainBooter.poll() == None:
        _domainManager = None
        try:
            _domainManager = root.resolve(URI.stringToName("%s/%s" % (domainName, domainName)))._narrow(CF.DomainManager)
        except:
            _domainManager = None
        if _domainManager:
            break
        time.sleep(0.1)
    return (_domainBooter, _domainManager)
    def test_MultipleDevicesWithSameName(self):
        # Test that two different device managers can start devices with the same name

        # TODO We should check that these two actually have a device that has the same name
        # because, if someone changes the XML unwittingly then this test will pass
        # without really testing anything
        nb1, devMgr1 = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml")
        nb2, devMgr2 = self.launchDeviceManager("/nodes/test_BasicTestDevice2_node/DeviceManager.dcd.xml")

        self.assertEqual(len(self._domMgr._get_deviceManagers()), 2)
        for devMgr in self._domMgr._get_deviceManagers():
            self.assertEqual(len(devMgr._get_registeredDevices()), 1)

        # Although nothing in the spec specifies where a device is to be bound
        # ossie does /DomainName/DevicemgrName/DeviceName, so let's check that now
        # to ensure the behavior remains consistent
        dev1Name = URI.stringToName(scatest.getTestDomainName() + "/BasicTestDevice_node/BasicTestDevice1")
        dev2Name = URI.stringToName(scatest.getTestDomainName() + "/BasicTestDevice2_node/BasicTestDevice1")

        dev1 = self._root.resolve(dev1Name)._narrow(CF.Device)
        dev2 = self._root.resolve(dev2Name)._narrow(CF.Device)
        self.assertNotEqual(dev1, None)
        self.assertNotEqual(dev2, None)
예제 #31
0
    def test_py_BasicOperation(self):
        self.assertNotEqual(self._domMgr, None)

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.installApplication(
            "/waveforms/CommandWrapperOsProcessor/CommandWrapper.sad.xml")
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Ensure the expected device is available
        devBooter, devMgr = self.launchDeviceManager(
            "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml")
        self.assertNotEqual(devMgr, None)
        self.assertEqual(len(devMgr._get_registeredDevices()), 1)
        device = devMgr._get_registeredDevices()[0]

        appFact = self._domMgr._get_applicationFactories()[0]

        app = appFact.create(appFact._get_name(), [], [])  # LOOK MA, NO DAS!

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 1)

        # Verify that properties have been changed from their defaults
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(
            compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        cmd = comp.query([
            CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e",
                        value=any.to_any(None))
        ])[0]
        args = comp.query([
            CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53",
                        value=any.to_any(None))
        ])[0]
        self.assertEqual(cmd.value._v, "/bin/echo")
        self.assertEqual(args.value._v, ["Hello World"])

        app.stop()
        app.releaseObject()
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.uninstallApplication(appFact._get_identifier())
예제 #32
0
 def next_n(self, how_many):
     res = True
     bl = []
     try:
       n_keys = len(self.keys)
       for i in range(n_keys):
         if i < how_many:
             x = self.keys.pop(0)
             name = URI.stringToName(x)
             val = CosNaming.Binding(name, self.object_table[x][1])
             bl.append(val)
     except:
       res = False
       self.destroy()
     return (res, bl)
    def tearDown(self):
        self.comp.releaseObject()

        # Try to clean up the event channel, if it was created
        context = None
        try:
            channel = self._root.resolve(URI.stringToName('TEST_APPENDER/TEST_EVT_CH1'))
            channel = channel._narrow(CosEventChannelAdmin.EventChannel)
            channel.destroy()
        except:
            pass

        # Clean up naming context, too
        try:
            context = self._root.resolve(URI.stringToName('TEST_APPENDER'))
            context = context._narrow(CosNaming.NamingContext)
            self._root.unbind(URI.stringToName('TEST_APPENDER'))
            context.destroy()
        except:
            pass

        # Do all application shutdown before calling the base class tearDown,
        # or failures will probably occur.
        scatest.CorbaTestCase.tearDown(self)
예제 #34
0
def launchDomain(number, root):
    domainName = scatest.getTestDomainName() + '_' + str(number)
    _domainBooter = scatest.spawnNodeBooter(dmdFile='', domainname=domainName)
    while _domainBooter.poll() == None:
        _domainManager = None
        try:
            _domainManager = root.resolve(
                URI.stringToName("%s/%s" % (domainName, domainName)))._narrow(
                    CF.DomainManager)
        except:
            _domainManager = None
        if _domainManager:
            break
        time.sleep(0.1)
    return (_domainBooter, _domainManager)
예제 #35
0
    def getEventChannel(self, eventChannelName, domainName=None):
        """
        Returns a reference to an existing event channel, or None if it
        cannot be located.
        """
        nameBinding = URI.stringToName(self._getEventChannelName(eventChannelName, domainName))

        try:
            channel = self.rootContext.resolve(nameBinding)
        except:
            return None

        if channel and not channel._non_existent():
            return channel._narrow(CosEventChannelAdmin.EventChannel)
        return None
예제 #36
0
    def createEventChannel(self,
                           eventChannelName,
                           domainName=None,
                           force=False):
        """
        Creates an event channel, if it already exists return it. The
        event channel is bound into the name service as 'eventChannelName',
        in the context specified by 'domainName', or the root naming context
        if 'domainName' is not given.

        If force == True and the event channel already exists, destroy it and create a new one.
        """
        eventChannel = self.getEventChannel(eventChannelName, domainName)
        if eventChannel:
            if force or eventChannel._non_existent():
                self.destroyEventChannel(eventChannelName, domainName)
            else:
                return eventChannel._narrow(CosEventChannelAdmin.EventChannel)

        factory = self.getEventChannelFactory()
        if not factory:
            return None

        name = self._getEventChannelName(eventChannelName, domainName)
        key = [CosNaming.NameComponent("EventChannel", "object interface")]
        if domainName != None:
            criteria = [
                CosLifeCycle.NameValuePair(name="InsName",
                                           value=any.to_any(domainName + '.' +
                                                            eventChannelName))
            ]
        else:
            criteria = [
                CosLifeCycle.NameValuePair(name="InsName",
                                           value=any.to_any(eventChannelName))
            ]

        try:
            eventChannel = factory.create_object(key, criteria)._narrow(
                CosEventChannelAdmin.EventChannel)
        except:
            return None

        bindingName = URI.stringToName(name)
        self.rootContext.rebind(bindingName, eventChannel)

        return eventChannel
    def test_cpp_DirectoryLoad(self):
        self.assertNotEqual(self._domMgr, None)

        # Verify in the devices cache is emtpy
        componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "CommandWrapperWithDirectoryLoad")
        deviceCacheDir = os.path.join(scatest.getSdrCache(), ".ExecutableDevice_node", "ExecutableDevice1", "components", "CommandWrapperWithDirectoryLoad")
        if os.path.exists(deviceCacheDir):
            os.system("rm -rf %s" % deviceCacheDir)

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.installApplication("/waveforms/CommandWrapperWithDirectoryLoad/CommandWrapper.sad.xml")
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Ensure the expected device is available
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_ExecutableDevice_node/DeviceManager.dcd.xml")
        self.assertNotEqual(devMgr, None)
        self.assertEqual(len(devMgr._get_registeredDevices()), 1)
        device = devMgr._get_registeredDevices()[0]

        appFact = self._domMgr._get_applicationFactories()[0]

        app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS!

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 1)

        # Verify that properties have been changed from their defaults
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        cmd = comp.query([CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e", value=any.to_any(None))])[0]
        args = comp.query([CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "/bin/echo")
        self.assertEqual(args.value._v, ["Hello World"])

        app.stop()
        app.releaseObject()
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.uninstallApplication(appFact._get_identifier())
예제 #38
0
    def getEventChannel(self, eventChannelName, domainName=None):
        """
        Returns a reference to an existing event channel, or None if it
        cannot be located.
        """
        nameBinding = URI.stringToName(self._getEventChannelName(eventChannelName, domainName))
        try:
            channel = self.rootContext.resolve(nameBinding)
        except:
            return None

        try:
            if channel and not channel._non_existent():
                return channel._narrow(CosEventChannelAdmin.EventChannel)
        except CORBA.Exception:
            return None
        return None
예제 #39
0
    def tearDown(self):
        for devMgr in self._getDeviceManagers():
            try:
                devMgr.shutdown()
            except CORBA.Exception:
                # Ignore all CORBA errors.
                pass

        for devBooter in self._getDeviceBooters():
            self.terminateChild(devBooter)

        if self._domainBooter:
            self.terminateChild(self._domainBooter)

        try:
            self._root.unbind(URI.stringToName(getTestDomainName()))
        except:
            pass
def launchDomain(number, root):
    domainName = scatest.getTestDomainName() + '_' + str(number)
    _domainBooter = scatest.spawnNodeBooter(dmdFile='', domainname=domainName)
    while _domainBooter.poll() == None:
        _domainManager = None
        try:
            _domainManager = root.resolve(
                URI.stringToName("%s/%s" % (domainName, domainName)))._narrow(
                    CF.DomainManager)
        except _CORBA.BAD_INV_ORDER:
            orb = _CORBA.ORB_init(_sys.argv, _CORBA.ORB_ID)
            ns = orb.resolve_initial_references("NameService")
            root = ns._narrow(CosNaming.NamingContext)
        except Exception, e:
            _domainManager = None
        if _domainManager:
            break
        time.sleep(0.1)
예제 #41
0
    def tearDown(self):
        for devMgr in self._getDeviceManagers():
            try:
                devMgr.shutdown()
            except CORBA.Exception:
                # Ignore all CORBA errors.
                pass

        for devBooter in self._getDeviceBooters():
            self.terminateChild(devBooter)

        if self._domainBooter:
            self.terminateChild(self._domainBooter)

        try:
            self._root.unbind(URI.stringToName(getTestDomainName()))
        except:
            pass
예제 #42
0
def ORB_start_fun():
    orb_ref = orb

    # get the POA
    obj_poa = orb_ref.orb.resolve_initial_references("RootPOA")
    poaManager = obj_poa._get_the_POAManager()
    poaManager.activate()
        
    ns_obj = orb_ref.orb.resolve_initial_references("NameService")
    rootContext = ns_obj._narrow(CosNaming.NamingContext)
        
    # create the main component object
    orb_ref.OSSIETalk_Obj = OSSIETalk_i(orb_ref, uuid, label, obj_poa)
    OSSIETalk_var = orb_ref.OSSIETalk_Obj._this()
        
    name = URI.stringToName(label)
    rootContext.rebind(name, OSSIETalk_var)

    orb_ref.orb.run()
예제 #43
0
 def __init__(self, uuid, label):
     # initialize the orb
     self.orb = CORBA.ORB_init()
     
     # get the POA
     obj_poa = self.orb.resolve_initial_references("RootPOA")
     poaManager = obj_poa._get_the_POAManager()
     poaManager.activate()
     
     ns_obj = self.orb.resolve_initial_references("NameService")
     rootContext = ns_obj._narrow(CosNaming.NamingContext)
     
     # create the main component object
     self.__CLASS_NAME___Obj = __CLASS_NAME___i(uuid, label, obj_poa)
     __CLASS_NAME___var = self.__CLASS_NAME___Obj._this()
     
     name = URI.stringToName(label)
     rootContext.rebind(name, __CLASS_NAME___var)
     
     self.orb.run()
예제 #44
0
    def __init__(self, uuid, label):
        # initialize the orb
        self.orb = CORBA.ORB_init()

        # get the POA
        obj_poa = self.orb.resolve_initial_references("RootPOA")
        poaManager = obj_poa._get_the_POAManager()
        poaManager.activate()

        ns_obj = self.orb.resolve_initial_references("NameService")
        rootContext = ns_obj._narrow(CosNaming.NamingContext)

        # create the main component object
        self.pass_data_Obj = pass_data_i(uuid, label, obj_poa)
        pass_data_var = self.pass_data_Obj._this()

        name = URI.stringToName(label)
        rootContext.rebind(name, pass_data_var)

        self.orb.run()
예제 #45
0
 def list(self, how_many):
     rest = None
     bl = []
     for i,x in enumerate(self.object_table):
         if i < how_many:
             name = URI.stringToName(x)
             val = CosNaming.Binding(name, self.object_table[x][1])
             bl.append(val)
         else:
             rest = self.object_table.keys()[how_many:]
 
     if rest:
         bii = BindingIterator_i(self, self.names_poa, rest)
         id = self.names_poa.activate_object(bii)
         bi = self.names_poa.id_to_reference(id)
         self.lock.acquire()
         self.iterators[id] = bii
         self.lock.release()
     else:
         bi = None
     return (bl, bi)
    def test_py_BasicOperation(self):
        self.assertNotEqual(self._domMgr, None)

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.installApplication("/waveforms/CommandWrapperOsProcessor/CommandWrapper.sad.xml")
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Ensure the expected device is available
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml")
        self.assertNotEqual(devMgr, None)
        self.assertEqual(len(devMgr._get_registeredDevices()), 1)
        device = devMgr._get_registeredDevices()[0]

        appFact = self._domMgr._get_applicationFactories()[0]

        app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS!

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 1)

        # Verify that properties have been changed from their defaults
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        cmd = comp.query([CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e", value=any.to_any(None))])[0]
        args = comp.query([CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "/bin/echo")
        self.assertEqual(args.value._v, ["Hello World"])

        app.stop()
        app.releaseObject()
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.uninstallApplication(appFact._get_identifier())
예제 #47
0
    def getEventChannelFactory(self):
        """
        Get the EventChannelFactory for this ORB. An initial reference of
        'EventService' is checked first, then the NameService is queried
        for the factory name. Returns None if one cannot be located.
        """
        try:
            factory = self.orb.resolve_initial_references("EventService")
        except:
            factory = None

        if not factory:
            eventFactoryName = URI.stringToName(self.factoryName)
            try:
                factory = self.rootContext.resolve(eventFactoryName)
            except:
                return None

        if factory:
            return factory._narrow(CosLifeCycle.GenericFactory)
        
        return None
 def test_registerWithEventChannel_creation(self):
     # launch DomainManager
     nodebooter, self._domMgr = self.launchDomainManager()
     self.assertNotEqual(self._domMgr, None)
     self.gotData = False
     # set up consumer
     _consumer = Consumer_i(self)
     channelName = 'testChannel'
     self._domMgr.registerWithEventChannel(_consumer._this(), 'some_id', channelName)
     domainName = scatest.getTestDomainName()
     eventChannelURI = URI.stringToName("%s/%s" % (domainName, channelName))
     channel = self._root.resolve(eventChannelURI)._narrow(CosEventChannelAdmin.EventChannel)
     supplier_admin = channel.for_suppliers()
     proxy_consumer = supplier_admin.obtain_push_consumer()
     proxy_consumer.connect_push_supplier(None)
     proxy_consumer.push(any.to_any(True))
     begin_time = time.time()
     timeout = 5 # maximum of 5 seconds
     while ((time.time() - begin_time) < timeout) and not self.gotData:
         time.sleep(0.1)
     self.assertEqual(self.gotData, True)
     self._domMgr.unregisterFromEventChannel('some_id', channelName)
예제 #49
0
    def getEventChannelFactory(self):
        """
        Get the EventChannelFactory for this ORB. An initial reference of
        'EventService' is checked first, then the NameService is queried
        for the factory name. Returns None if one cannot be located.
        """
        try:
            factory = self.orb.resolve_initial_references("EventService")
        except:
            factory = None

        if not factory:
            eventFactoryName = URI.stringToName(self.factoryName)
            try:
                factory = self.rootContext.resolve(eventFactoryName)
            except:
                return None

        if factory:
            return factory._narrow(CosLifeCycle.GenericFactory)

        return None
 def test_registerWithEventChannel_creation(self):
     # launch DomainManager
     nodebooter, self._domMgr = self.launchDomainManager()
     self.assertNotEqual(self._domMgr, None)
     self.gotData = False
     # set up consumer
     _consumer = Consumer_i(self)
     channelName = 'testChannel'
     self._domMgr.registerWithEventChannel(_consumer._this(), 'some_id', channelName)
     domainName = scatest.getTestDomainName()
     eventChannelURI = URI.stringToName("%s/%s" % (domainName, channelName))
     channel = self._root.resolve(eventChannelURI)._narrow(CosEventChannelAdmin.EventChannel)
     supplier_admin = channel.for_suppliers()
     proxy_consumer = supplier_admin.obtain_push_consumer()
     proxy_consumer.connect_push_supplier(None)
     proxy_consumer.push(any.to_any(True))
     begin_time = time.time()
     timeout = 5 # maximum of 5 seconds
     while ((time.time() - begin_time) < timeout) and not self.gotData:
         time.sleep(0.1)
     self.assertEqual(self.gotData, True)
     self._domMgr.unregisterFromEventChannel('some_id', channelName)
예제 #51
0
    def test_FindByAbsoluteNamingService(self):
        from ossie.utils import sb
        comp = sb.Component('PortTest')
        orb = CORBA.ORB_init()
        obj = orb.resolve_initial_references("NameService")
        rootContext = obj._narrow(CosNaming.NamingContext)
        bindingName = URI.stringToName("PortTest2")
        rootContext.rebind(bindingName, comp.ref)

        self.assertNotEqual(self._domMgr, None)
        self.assertNotEqual(self._devMgr, None)

        sadpath = "/waveforms/PortConnectFindByAbsoluteNamingService/PortConnectFindByAbsoluteNamingService.sad.xml"
        self._domMgr.installApplication(sadpath)
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        appFact = self._domMgr._get_applicationFactories()[0]

        try:
            self._app = appFact.create(appFact._get_name(), [], [])
        except:
            rootContext.unbind(bindingName)
            self.fail(
                "Did not create application PortConnectFindByAbsoluteNamingService"
            )
        components = self._getComponents()

        # Use the TestableObject interface to check that 'PortTest1' has
        # exactly one connection, and that it's connected to 'PortTest2'.
        ids = components['PortTest1'].runTest(0, [])
        if (len(ids) != 1):
            rootContext.unbind(bindingName)
            self.fail("There are more than one connection on PortTest1")
        expectedId = comp.ref._get_identifier()
        if (str(ids[0].value.value()) != expectedId):
            rootContext.unbind(bindingName)
            self.fail("The expected id does not match")
        rootContext.unbind(bindingName)
        sb.domainless._cleanUpLaunchedComponents()
    def test_FindByAbsoluteNamingService(self):
        from ossie.utils import sb
        comp=sb.Component('PortTest')
        orb = CORBA.ORB_init()
        obj = orb.resolve_initial_references("NameService")
        rootContext = obj._narrow(CosNaming.NamingContext)
        bindingName = URI.stringToName("PortTest2")
        rootContext.rebind(bindingName, comp.ref)

        self.assertNotEqual(self._domMgr, None)
        self.assertNotEqual(self._devMgr, None)

        sadpath = "/waveforms/PortConnectFindByAbsoluteNamingService/PortConnectFindByAbsoluteNamingService.sad.xml"
        self._domMgr.installApplication(sadpath)
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        appFact = self._domMgr._get_applicationFactories()[0]

        try:
            self._app = appFact.create(appFact._get_name(), [], [])
        except:
            rootContext.unbind(bindingName)
            self.fail("Did not create application PortConnectFindByAbsoluteNamingService")
        components = self._getComponents()

        # Use the TestableObject interface to check that 'PortTest1' has
        # exactly one connection, and that it's connected to 'PortTest2'.
        ids = components['PortTest1'].runTest(0, [])
        if (len(ids) != 1):
            rootContext.unbind(bindingName)
            self.fail("There are more than one connection on PortTest1")
        expectedId = comp.ref._get_identifier()
        if (str(ids[0].value.value()) != expectedId):
            rootContext.unbind(bindingName)
            self.fail("The expected id does not match")
        rootContext.unbind(bindingName)
        sb.domainless._cleanUpLaunchedComponents()
    def test_ServiceShutdown_DomMgr(self):
        num_services = 5
        num_devices = 1
        # This test makes sure that services are unregistered from the naming service upon shutdown of the DomainManager
        devmgr_nb, devMgr = self.launchDeviceManager("/nodes/test_MultipleService_node/DeviceManager.dcd.xml")
        timeout = 5
        begin_time = time.time()
        done = False
        while not done:
            current_time = time.time()
            if (current_time - begin_time) > timeout:
                break
            if len(devMgr._get_registeredServices()) == num_services:
                break
        self.assertEqual(len(devMgr._get_registeredServices()), num_services)

        # Makes sure that the correct number of processes forked
        self.assertEquals(len(getChildren(devmgr_nb.pid)), num_services + num_devices)

        svcName = URI.stringToName(scatest.getTestDomainName() + "/BasicService1")
        self._root.resolve(svcName)._narrow(CF.PropertySet)

        names = ["BasicService1", "BasicService2", "BasicService3", "BasicService4", "BasicService5"]

        for svc in devMgr._get_registeredServices():
            self.assertNotEqual(svc, None)
            self.assertEqual(svc.serviceName in names, True)
            names.remove(svc.serviceName)
            obj = svc.serviceObject
            obj = obj._narrow(CF.PropertySet)
            self.assertNotEqual(obj, None)

            # Check the name service to ensure the service is properly bound
            svcName = URI.stringToName(scatest.getTestDomainName() + "/" + svc.serviceName)
            svcobj = self._root.resolve(svcName)._narrow(CF.PropertySet)
            self.assertNotEqual(svcobj, None)
            self.assert_(obj._is_equivalent(svcobj))

            # Check that all the parameters got set correctly
            props = obj.query([])
            d = dict([(p.id, any.from_any(p.value)) for p in props])
            self.assertEqual(d["SERVICE_NAME"], svc.serviceName)
            self.assertEqual(d["DEVICE_MGR_IOR"], self._orb.object_to_string(devMgr))
            self.assertEqual(d["PARAM1"], "ABCD")
            self.assertEqual(d["PARAM2"], 42)
            self.assertEqual(d["PARAM3"], 3.1459)
            self.assertEqual(d["PARAM4"], False)
            self.assertEqual(d["PARAM5"], "Hello World")
            self.assertEqual(d.has_key("PARAM6"), False)

        # Check that we unregister correctly
        os.kill(self._domBooter.pid, signal.SIGINT)

        names = ["BasicService1", "BasicService2", "BasicService3", "BasicService4", "BasicService5"]
        svcNames = []
        for n in names:
            svcNames.append(URI.stringToName(scatest.getTestDomainName() + "/" + n))

        # Needs to allow time for unregistering
        self.assert_(self.waitTermination(self._domBooter), "Nodebooter did not die after shutdown")

        # Don't use assertRaises, so we can simplify things
        for name in svcNames:
            try:
                self._root.resolve(name)._narrow(CF.PropertySet)
            except CosNaming.NamingContext.NotFound:
                pass
            else:
                self.fail("Expected service to not exist in the naming service: " + str(name))

        # Makes sure that all children are dead
        self.assertEquals(len(getChildren(devmgr_nb.pid)), 0)
예제 #54
0
def getDomainMgrURI():
    domainName = getTestDomainName()
    return URI.stringToName("%s/%s" % (domainName, domainName))
예제 #55
0
def start_component(componentclass, interactive_callback=None, thread_policy=None, loggerName=None):   
    execparams, interactive = parseCommandLineArgs(componentclass)
    setupSignalHandlers()

    try:
        try:
            orb = createOrb()
            globals()['__orb__'] = orb

            configureLogging(execparams, loggerName, orb)

            componentPOA = getPOA(orb, thread_policy, "componentPOA")
          
            if not execparams.has_key("COMPONENT_IDENTIFIER"):
                if not interactive:
                    logging.warning("No 'COMPONENT_IDENTIFIER' argument provided")
                execparams["COMPONENT_IDENTIFIER"] = ""
            
            if not execparams.has_key("NAME_BINDING"):
                if not interactive:
                    logging.warning("No 'NAME_BINDING' argument provided")
                execparams["NAME_BINDING"] = ""

            # Create the component
            component_Obj = componentclass(execparams["COMPONENT_IDENTIFIER"], execparams)
            componentPOA.activate_object(component_Obj)
            component_Var = component_Obj._this()

            # get the naming context and bind to it
            if execparams.has_key("NAMING_CONTEXT_IOR"):
                rootContext = orb.string_to_object(execparams['NAMING_CONTEXT_IOR'])
                if rootContext == None:
                    logging.error("Failed to lookup naming context")
                    sys.exit(-1)

                rootContext = rootContext._narrow(CosNaming.NamingContext)
                name = URI.stringToName(execparams['NAME_BINDING'])
                rootContext.rebind(name, component_Var)
            else:
                if not interactive:
                    logging.warning("Skipping name-binding because required execparams 'NAMING_CONTEXT_IOR' is missing")

            if not interactive:
                logging.trace("Starting ORB event loop")
                orb.run()
            else:
                logging.trace("Entering interactive mode")
                if callable(interactive_callback):
                    # Pass only the Var to prevent anybody from calling non-CORBA functions
                    interactive_callback(component_Obj)
                else:
                    print orb.object_to_string(component_Obj._this())
                    orb.run()
        except SystemExit:
            pass
        except KeyboardInterrupt:
            pass
        except:
            logging.exception("Unexpected Error")
    finally:
        if orb:
            orb.destroy()
        # ORB initialization
        orb = CORBA.ORB_init()
        obj_poa = orb.resolve_initial_references("RootPOA")
        poaManager = obj_poa._get_the_POAManager()
        poaManager.activate()

        if execparams["FAIL_AT"] == "PreServantCreation":
            raise StandardError

        # Create the component servant object
        component_Obj = FailStartup(execparams)
        component_Var = component_Obj._this()

        if execparams["FAIL_AT"] == "PreNameBinding":
            raise StandardError

        # Bind it to the naming context
        rootContext = orb.string_to_object(execparams['NAMING_CONTEXT_IOR'])
        if rootContext == None:
            raise SystemExit, "Failed to lookup naming context"
        rootContext = rootContext._narrow(CosNaming.NamingContext)
        name = URI.stringToName(execparams['NAME_BINDING'])
        rootContext.rebind(name, component_Var)

        if execparams["FAIL_AT"] == "PreOrbRun":
            raise StandardError
        orb.run()
    finally:
        if orb:
            orb.destroy()
    def test_ExternalServices(self):
        devmgr_nb, devMgr = self.launchDeviceManager("/nodes/test_MultipleService_node/DeviceManager.dcd.xml")
        import ossie.utils.popen as _popen

        serviceName = "BasicService10"

        args = []
        args.append("sdr/dev/services/BasicService/BasicService.py")
        args.append("DEVICE_MGR_IOR")
        args.append(self._orb.object_to_string(devMgr))
        args.append("SERVICE_NAME")
        args.append(serviceName)
        args.append("LOGGING_CONFIG_URI")
        args.append("runtest.props")
        args.append("PARAM1")
        args.append("ABCD")
        args.append("PARAM2")
        args.append("42")
        args.append("PARAM3")
        args.append("3.1459")
        args.append("PARAM4")
        args.append("False")
        args.append("PARAM5")
        args.append("Hello World")
        exec_file = "sdr/dev/services/BasicService/BasicService.py"
        external_process = _popen.Popen(args, executable=exec_file, cwd=os.getcwd(), preexec_fn=os.setpgrp)

        serviceName2 = "BasicService11"
        args[4] = serviceName2
        exec_file = "sdr/dev/services/BasicService/BasicService.py"
        external_process2 = _popen.Popen(args, executable=exec_file, cwd=os.getcwd(), preexec_fn=os.setpgrp)

        time.sleep(1)

        names = ["BasicService1", "BasicService2", "BasicService3", "BasicService4", "BasicService5", serviceName, serviceName2]

        # Makes sure external service registered
        for svc in devMgr._get_registeredServices():
            self.assertNotEqual(svc, None)
            self.assertEqual(svc.serviceName in names, True)

            names.remove(svc.serviceName)
            obj = svc.serviceObject
            obj = obj._narrow(CF.PropertySet)
            self.assertNotEqual(obj, None)

            # Check the name service to ensure the service is properly bound
            svcName = URI.stringToName(scatest.getTestDomainName() + "/" + svc.serviceName)
            svcobj = self._root.resolve(svcName)._narrow(CF.PropertySet)
            self.assertNotEqual(svcobj, None)
            self.assert_(obj._is_equivalent(svcobj))

            # Check that all the parameters got set correctly
            props = obj.query([])
            d = dict([(p.id, any.from_any(p.value)) for p in props])
            self.assertEqual(d["SERVICE_NAME"], svc.serviceName)
            self.assertEqual(d["DEVICE_MGR_IOR"], self._orb.object_to_string(devMgr))
            self.assertEqual(d["PARAM1"], "ABCD")
            self.assertEqual(d["PARAM2"], 42)
            self.assertEqual(d["PARAM3"], 3.1459)
            self.assertEqual(d["PARAM4"], False)
            self.assertEqual(d["PARAM5"], "Hello World")
            self.assertEqual(d.has_key("PARAM6"), False)

        # Make sure a component can communicate with the Service
        self._domMgr.installApplication("/waveforms/ServiceConnection/ServiceConnection.sad.xml")
        self.assertEquals(len(self._domMgr._get_applicationFactories()), 1)
        factory = self._domMgr._get_applicationFactories()[0]
        app = factory.create(factory._get_name(), [], [])
        self.assertEquals(len(self._domMgr._get_applications()), 1)

        # Make sure an app that uses external services can launch
        app.start()
        port = app._get_registeredComponents()[0].componentObject.getPort("output")
        app.releaseObject()

        # Kill the 2 external services
        os.kill(external_process.pid, signal.SIGINT)
        os.kill(external_process2.pid, signal.SIGINT)

        # Give time for kill signals to be caught
        time.sleep(1)
        os.kill(devmgr_nb.pid, signal.SIGINT)

        # Make sure services are no longer register with the domain manager
        names = ["BasicService1", "BasicService2", "BasicService3", "BasicService4", "BasicService5", serviceName, serviceName2]
        svcNames = []
        for n in names:
            svcNames.append(URI.stringToName(scatest.getTestDomainName() + "/" + n))

        # Needs to allow time for unregistering
        self.assert_(self.waitTermination(devmgr_nb), "Nodebooter did not die after shutdown")

        # Don't use assertRaises, so we can simplify things
        for name in svcNames:
            try:
                self._root.resolve(name)._narrow(CF.PropertySet)
            except CosNaming.NamingContext.NotFound:
                pass
            else:
                self.fail("Expected service to not exist in the naming service")

        # Makes sure all children are cleaned
        self.assertEquals(len(getChildren(devmgr_nb.pid)), 0)
    def test_ComponentLoggingRedirect(self):
        logfile = '/var/tmp/commandwrapper.log'
        fp=open(logfile,'w')
        fp.close()

        domNB, domMgr = self.launchDomainManager(loggingURI="dom/mgr/logging_2.properties")
        self.assertNotEqual(domMgr, None)

        # Launch a device manager
        devNB, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", loggingURI="dev/mgr/logging.properties")
        self.assertNotEqual(domMgr, None)

        # Double check the DomainManager LOGGING_CONFIG_URI
        prop = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any(None))
        result = domMgr.query([prop])
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].id, "LOGGING_CONFIG_URI")
        devLoggingConfigURI = result[0].value._v
        expectedDomLoggingConfigUri = "file://" + os.path.join(scatest.getSdrPath(), "dom/mgr/logging_2.properties")
        self.assertEqual(devLoggingConfigURI, expectedDomLoggingConfigUri)

        # Launch an application
        domMgr.installApplication("/waveforms/CommandWrapper/CommandWrapper.sad.xml")
        self.assertEqual(len(domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(domMgr._get_applications()), 0)

        appFact = domMgr._get_applicationFactories()[0]
        uriOverride = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any("sca:///mgr/logging_2.properties"))
        app = appFact.create(appFact._get_name(), [uriOverride], [])

        # Get the desired component
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        # Check the components exec params
        execparams = comp.query([CF.DataType(id="DCE:85d133fd-1658-4e4d-b3ff-1443cd44c0e2", value=any.to_any(None))])[0]
        args = any.from_any(execparams.value)
        execparams = {}
        for a in args:
            name = a[0]
            value = a[1]
            execparams[name] = value

        app.start()
        app.stop()

        app.releaseObject()

        fp=open(logfile,'r')
        log_contents=fp.read()
        fp.close()
        count_debugs=log_contents.count('DEBUG:')
        count_command=log_contents.count('DEBUG:CommandWrapper')
        self.assertEqual(count_debugs,count_command)

        # Launch an application with a C++ component to exercise Resource_impl logging configure
        domMgr.installApplication("/waveforms/TestCppProps/TestCppProps.sad.xml")
        self.assertEqual(len(domMgr._get_applicationFactories()), 2)
        for appFact in domMgr._get_applicationFactories():
            if appFact._get_name() == "TestCppProps":
                app = appFact.create(appFact._get_name(), [uriOverride], [])
                break
        self.assertEqual(len(domMgr._get_applications()), 1)
    def test_py_DirectoryLoad(self):
        self.assertNotEqual(self._domMgr, None)

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Verify in the devices cache is emtpy
        componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "CommandWrapperWithDirectoryLoad")
        deviceCacheDir = os.path.join(scatest.getSdrCache(), ".BasicTestDevice_node", "BasicTestDevice1", "components", "CommandWrapperWithDirectoryLoad")
        if os.path.exists(deviceCacheDir):
            os.system("rm -rf %s" % deviceCacheDir)

        self._domMgr.installApplication("/waveforms/CommandWrapperWithDirectoryLoad/CommandWrapper.sad.xml")
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        # Ensure the expected device is available
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml")
        self.assertNotEqual(devMgr, None)
        self.assertEqual(len(devMgr._get_registeredDevices()), 1)
        device = devMgr._get_registeredDevices()[0]

        appFact = self._domMgr._get_applicationFactories()[0]

        app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS!

        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 1)

        # Verify that properties have been changed from their defaults
        self.assertEqual(len(app._get_componentNamingContexts()), 1)
        compName = app._get_componentNamingContexts()[0]
        comp = self._root.resolve(URI.stringToName(compName.elementId))._narrow(CF.Resource)
        self.assertNotEqual(comp, None)

        cmd = comp.query([CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e", value=any.to_any(None))])[0]
        args = comp.query([CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53", value=any.to_any(None))])[0]
        self.assertEqual(cmd.value._v, "/bin/echo")
        self.assertEqual(args.value._v, ["Hello World"])

        # Verify in the devices cache that the directory structure was mirrored exactly
        for root, dirs, files in os.walk(componentDir):
            # turn the abs path in to a relative path
            rel_root = root[len(componentDir)+1:]
            for dir in dirs:
                # Hidden files aren't loaded
                if dir[0] != ".":
                    expectedDir = os.path.join(deviceCacheDir, rel_root, dir)
                    self.assertEqual(os.path.isdir(expectedDir), True, "Dir %s not found at %s" % (dir, expectedDir))
                else:
                    # Don't descend into hidden sub-dirs
                    dirs.remove(dir)
            for f in files:
                # Hidden files aren't loaded
                if f[0] != ".":
                    expectedFile = os.path.join(deviceCacheDir, rel_root, f)
                    self.assertEqual(os.path.isfile(expectedFile), True, "File %s not found at %s" % (f, expectedFile))

        app.stop()
        app.releaseObject()
        self.assertEqual(len(self._domMgr._get_applicationFactories()), 1)
        self.assertEqual(len(self._domMgr._get_applications()), 0)

        self._domMgr.uninstallApplication(appFact._get_identifier())