示例#1
0
    def test_unregister_service(self):
        address = "ipc:///tmp/nmos-nodefacade.dummy.for.test"
        srv_type = "dummy_type"
        UUT = Facade(srv_type, address=address)

        UUT.srv_registered = True
        UUT.unregister_service()

        self.assertIsNotNone(UUT.ipc)
        UUT.ipc.srv_unregister.assert_called_once_with(srv_type, mock.ANY)
        self.assertFalse(UUT.srv_registered)
示例#2
0
    def test_unregister_service_bails_when_no_ipc(self):
        address = "ipc:///tmp/nmos-nodefacade.dummy.for.test"
        srv_type = "dummy_type"
        UUT = Facade(srv_type, address=address)

        self.mocks['nmosnode.facade.Proxy'].side_effect = Exception

        UUT.srv_registered = True
        UUT.unregister_service()

        self.assertIsNone(UUT.ipc)
        self.assertTrue(UUT.srv_registered)
示例#3
0
    def test_unregister_service_bails_when_unregister_raises(self):
        address = "ipc:///tmp/nmos-nodefacade.dummy.for.test"
        srv_type = "dummy_type"
        UUT = Facade(srv_type, address=address)

        self.mocks[
            'nmosnode.facade.Proxy'].return_value.srv_unregister.side_effect = Exception

        UUT.srv_registered = True
        UUT.unregister_service()

        self.assertIsNone(UUT.ipc)
        self.mocks[
            'nmosnode.facade.Proxy'].return_value.srv_unregister.assert_called_once_with(
                srv_type, mock.ANY)
        self.assertTrue(UUT.srv_registered)
示例#4
0
class ConnectionManagementService:

    def __init__(self, logger=None):
        self.running = False
        from nmoscommon.logger import Logger
        from nmosnode.facade import Facade
        self.logger = Logger("conmanage")
        self.logger.writeWarning("Could not find ipppython facade")
        self.facade = Facade("{}/{}".format(CONN_APINAME, CONN_APIVERSIONS[-1]),
                             address="ipc:///tmp/ips-nodefacade", logger=self.logger)
        self.logger.writeDebug("Running Connection Management Service")
        self.httpServer = HttpServer(ConnectionManagementAPI, WS_PORT,
                                     '0.0.0.0', api_args=[self.logger])

    def start(self):
        '''Call this to run the API without blocking'''
        if self.running:
            gevent.signal_handler(signal.SIGINT, self.sig_handler)
            gevent.signal_handler(signal.SIGTERM, self.sig_handler)

        self.running = True

        self.httpServer.start()

        while not self.httpServer.started.is_set():
            self.logger.writeDebug('Waiting for httpserver to start...')
            self.httpServer.started.wait()

        if self.httpServer.failed is not None:
            raise self.httpServer.failed

        self.logger.writeDebug("Running on port: {}"
                               .format(self.httpServer.port))

        self.facade.register_service("http://127.0.0.1:{}".format(self.httpServer.port),
                                     "{}{}/".format(CONN_ROOT[1:], CONN_APIVERSIONS[-1]))
        try:
            from nmosconnectiondriver.httpIpstudioDriver import httpIpstudioDriver
            self.logger.writeInfo("Using ipstudio driver")
            # Start the IPStudio driver
            self.driver = httpIpstudioDriver(
                self.httpServer.api,
                self.logger,
                self.facade
            )
        except ImportError:
            # Start the mock driver
            self.driver = NmosDriver(
                self.httpServer.api,
                self.logger,
                self.facade
            )

    def run(self):
        '''Call this to run the API in keep-alive (blocking) mode'''
        self.running = True
        self.start()
        itercount = 0
        while self.running:
            gevent.sleep(1)
            itercount += 1
            if itercount == 5:
                self.facade.heartbeat_service()
                itercount = 0
        self._cleanup()

    def _cleanup(self):
        self.httpServer.stop()
        self.facade.unregister_service()

    def sig_handler(self):
        self.stop()

    def stop(self):
        '''Gracefully shut down the API'''
        self._cleanup()
        self.running = False