def setUp(self):
        """
        Set up driver integration support.
        Start port agent, add port agent cleanup.
        Start container.
        Start deploy services.
        Define agent config.
        """
        self._ia_client = None

        log.info('Creating driver integration test support:')
        log.info('driver uri: %s', DRV_URI)
        log.info('device address: %s', DEV_ADDR)
        log.info('device port: %s', DEV_PORT)
        log.info('log delimiter: %s', DELIM)
        log.info('work dir: %s', WORK_DIR)
        self._support = DriverIntegrationTestSupport(None, None, DEV_ADDR,
                                                     DEV_PORT, DATA_PORT,
                                                     CMD_PORT, PA_BINARY,
                                                     DELIM, WORK_DIR)

        # Start port agent, add stop to cleanup.
        self._start_pagent()
        self.addCleanup(self._support.stop_pagent)

        # Start container.
        log.info('Staring capability container.')
        self._start_container()

        # Bring up services in a deploy file (no need to message)
        log.info('Staring deploy services.')
        self.container.start_rel_from_url('res/deploy/r2deploy.yml')

        log.info('building stream configuration')
        # Setup stream config.
        self._build_stream_config()

        # Create agent config.
        self._agent_config = {
            'driver_config': DVR_CONFIG,
            'stream_config': self._stream_config,
            'agent': {
                'resource_id': IA_RESOURCE_ID
            },
            'test_mode': True,
            'forget_past': False,
            'enable_persistence': True,
            'aparam_pubrate_config': {
                'raw': 2,
                'parsed': 2
            }
        }

        self._ia_client = None
        self._ia_pid = '1234'

        self.addCleanup(self._verify_agent_reset)
        self.addCleanup(self.container.state_repository.put_state,
                        self._ia_pid, {})
 def start_agent(self):
     """
     Start an instrument agent and client.
     """
     
     log.info('Creating driver integration test support:')
     log.info('driver module: %s', DRV_MOD)
     log.info('driver class: %s', DRV_CLS)
     log.info('device address: %s', DEV_ADDR)
     log.info('device port: %s', DEV_PORT)
     log.info('log delimiter: %s', DELIM)
     log.info('work dir: %s', WORK_DIR)        
     self._support = DriverIntegrationTestSupport(DRV_MOD,
                                                  DRV_CLS,
                                                  DEV_ADDR,
                                                  DEV_PORT,
                                                  DATA_PORT,
                                                  CMD_PORT,
                                                  PA_BINARY,
                                                  DELIM,
                                                  WORK_DIR)
     
     # Start port agent, add stop to cleanup.
     port = self._support.start_pagent()
     log.info('Port agent started at port %i',port)
     
     # Configure driver to use port agent port number.
     DVR_CONFIG['comms_config'] = {
         'addr' : 'localhost',
         'port' : port,
         'cmd_port' : CMD_PORT
     }
     self.addCleanup(self._support.stop_pagent)    
                     
     # Create agent config.
     agent_config = {
         'driver_config' : DVR_CONFIG,
         'stream_config' : {},
         'agent'         : {'resource_id': IA_RESOURCE_ID},
         'test_mode' : True
     }
 
     # Start instrument agent.
     log.debug("Starting IA.")
     container_client = ContainerAgentClient(node=self.container.node,
         name=self.container.name)
 
     ia_pid = container_client.spawn_process(name=IA_NAME,
         module=IA_MOD,
         cls=IA_CLS,
         config=agent_config)
 
     log.info('Agent pid=%s.', str(ia_pid))
 
     # Start a resource agent client to talk with the instrument agent.
 
     self._ia_client = ResourceAgentClient(IA_RESOURCE_ID, process=FakeProcess())
     log.info('Got ia client %s.', str(self._ia_client))                
Esempio n. 3
0
    def setUp(self):
        """
        Set up driver integration support.
        Start port agent, add port agent cleanup.
        Start container.
        Start deploy services.
        Define agent config, start agent.
        Start agent client.
        """
        self._ia_client = None

        log.info('Creating driver integration test support:')
        log.info('driver uri: %s', DRV_URI)
        log.info('device address: %s', DEV_ADDR)
        log.info('device port: %s', DEV_PORT)
        log.info('log delimiter: %s', DELIM)
        log.info('work dir: %s', WORK_DIR)
        self._support = DriverIntegrationTestSupport(None,
                                                     None,
                                                     DEV_ADDR,
                                                     DEV_PORT,
                                                     DATA_PORT,
                                                     CMD_PORT,
                                                     PA_BINARY,
                                                     DELIM,
                                                     WORK_DIR)
        
        # Start port agent, add stop to cleanup.
        self._start_pagent()
        self.addCleanup(self._support.stop_pagent)    
        
        # Start container.
        log.info('Staring capability container.')
        self._start_container()
        
        # Bring up services in a deploy file (no need to message)
        log.info('Staring deploy services.')
        self.container.start_rel_from_url('res/deploy/r2deploy.yml')

        log.info('building stream configuration')
        # Setup stream config.
        self._build_stream_config()

        # Start a resource agent client to talk with the instrument agent.
        log.info('starting IA process')
        self._ia_client = start_instrument_agent_process(self.container, self._stream_config)
        self.addCleanup(self._verify_agent_reset)
        log.info('test setup complete')
Esempio n. 4
0
    def setUp(self):
        """
        Setup test cases.
        """
        self.device_addr = DEV_ADDR
        self.device_port = DEV_PORT
        self.work_dir = WORK_DIR
        self.delim = DELIM

        self.driver_class = DVR_CLS
        self.driver_module = DVR_MOD
        self._support = DriverIntegrationTestSupport(self.driver_module,
                                                     self.driver_class,
                                                     self.device_addr,
                                                     self.device_port,
                                                     self.delim, self.work_dir)

        # Clear driver event list.
        self._events = []

        # The port agent object. Used to start and stop the port agent.
        self._pagent = None

        # The driver process popen object.
        self._dvr_proc = None

        # The driver client.
        self._dvr_client = None

        # Create and start the port agent.
        mi_logger.info('start')
        COMMS_CONFIG['port'] = self._support.start_pagent()
        self.addCleanup(self._support.stop_pagent)

        # Create and start the driver.
        self._support.start_driver()
        self.addCleanup(self._support.stop_driver)

        # Grab some variables from support that we need
        self._dvr_client = self._support._dvr_client
        self._dvr_proc = self._support._dvr_proc
        self._pagent = self._support._pagent
        self._events = self._support._events
Esempio n. 5
0
def start_port_agent(dev_addr=None,
                     dev_port=None,
                     data_port=None,
                     cmd_port=None,
                     pa_binary=None,
                     work_dir=WORK_DIR,
                     delim=DELIM):
    """
    """

    global pagent
    global CFG
    pagent = DriverIntegrationTestSupport(
        None, None, dev_addr or CFG.device.sbe37.host, dev_port
        or CFG.device.sbe37.port, data_port
        or CFG.device.sbe37.port_agent_data_port, cmd_port
        or CFG.device.sbe37.port_agent_cmd_port, pa_binary
        or CFG.device.sbe37.port_agent_binary, delim, work_dir)

    pagent.start_pagent()
Esempio n. 6
0
    def setUp(self):
        """
        Set up driver integration support.
        Start port agent, add port agent cleanup.
        Start container.
        Start deploy services.
        Define agent config.
        """
        self._ia_client = None

        log.info('Creating driver integration test support:')
        log.info('driver uri: %s', DRV_URI)
        log.info('device address: %s', DEV_ADDR)
        log.info('device port: %s', DEV_PORT)
        log.info('log delimiter: %s', DELIM)
        log.info('work dir: %s', WORK_DIR)
        self._support = DriverIntegrationTestSupport(None,
                                                     None,
                                                     DEV_ADDR,
                                                     DEV_PORT,
                                                     DATA_PORT,
                                                     CMD_PORT,
                                                     PA_BINARY,
                                                     DELIM,
                                                     WORK_DIR)
                
        # Start port agent, add stop to cleanup.
        self._start_pagent()
        self.addCleanup(self._support.stop_pagent)    
        
        # Start container.
        log.info('Staring capability container.')
        self._start_container()
        
        # Bring up services in a deploy file (no need to message)
        log.info('Staring deploy services.')
        self.container.start_rel_from_url('res/deploy/r2deploy.yml')

        self._event_count = 0
        self._events_received = []
        self._async_event_result = AsyncResult()

        def consume_event(*args, **kwargs):
            log.debug('Test recieved ION event: args=%s, kwargs=%s, event=%s.',
                     str(args), str(kwargs), str(args[0]))
            
            self._events_received.append(args[0])
            if self._event_count > 0 and \
                self._event_count == len(self._events_received):
                self._async_event_result.set()
                        
        self._event_subscriber = EventSubscriber(
            event_type='DeviceStatusAlertEvent', callback=consume_event,
            origin=IA_RESOURCE_ID)
        
        self._event_subscriber.start()

        def stop_subscriber():
            self._event_subscriber.stop()
            self._event_subscriber = None
        self.addCleanup(stop_subscriber)

        log.info('building stream configuration')
        # Setup stream config.
        self._build_stream_config()

        # Create agent config.
        self._agent_config = {
            'driver_config' : DVR_CONFIG,
            'stream_config' : self._stream_config,
            'agent'         : {'resource_id': IA_RESOURCE_ID},
            'test_mode' : True,
            'aparam_alerts_config' : [state_alert_def, command_alert_def]
        }

        self._ia_client = None
        self._ia_pid = None
        
        self.addCleanup(self._verify_agent_reset)
    def setUp(self):
        """
        Initialize test members.
        Start port agent.
        Start container and client.
        Start streams and subscribers.
        Start agent, client.
        """

        TrhphTestCase.setUp(self)

        self._support = DriverIntegrationTestSupport(DRV_MOD, DRV_CLS,
                                                     self.device_address,
                                                     self.device_port, DELIM,
                                                     WORK_DIR)
        # Start port agent, add stop to cleanup.
        self._pagent = None
        self._start_pagent()
        self.addCleanup(self._support.stop_pagent)

        # Start container.
        self._start_container()

        # Bring up services in a deploy file (no need to message)
        self.container.start_rel_from_url('res/deploy/r2deploy.yml')

        # Start data suscribers, add stop to cleanup.
        # Define stream_config.
        self._no_samples = None
        self._async_data_result = AsyncResult()
        self._data_greenlets = []
        self._stream_config = {}
        self._samples_received = []
        self._data_subscribers = []
        self._start_data_subscribers()
        self.addCleanup(self._stop_data_subscribers)

        # Start event subscribers, add stop to cleanup.
        self._no_events = None
        self._async_event_result = AsyncResult()
        self._events_received = []
        self._event_subscribers = []
        self._start_event_subscribers()
        self.addCleanup(self._stop_event_subscribers)

        # Create agent config.
        agent_config = {
            'driver_config': DVR_CONFIG,
            'stream_config': self._stream_config,
            'agent': {
                'resource_id': IA_RESOURCE_ID
            },
            'test_mode': True
        }

        # Start instrument agent.
        self._ia_pid = None
        log.debug("TestInstrumentAgentWithTrhph.setup(): starting IA.")
        container_client = ContainerAgentClient(node=self.container.node,
                                                name=self.container.name)
        self._ia_pid = container_client.spawn_process(name=IA_NAME,
                                                      module=IA_MOD,
                                                      cls=IA_CLS,
                                                      config=agent_config)
        log.info('Agent pid=%s.', str(self._ia_pid))

        # Start a resource agent client to talk with the instrument agent.
        self._ia_client = ResourceAgentClient(IA_RESOURCE_ID,
                                              process=FakeProcess())
        log.info('Got ia client %s.', str(self._ia_client))

        # make sure the driver is stopped
        self.addCleanup(self._reset)