Пример #1
0
def main():
    """
    Initializes container
    """
    logging.info("ION CONTAINER initializing... [Start an Instrument Agent]")

    processes = []
    processes.extend(agent_procs)
    processes.extend(service_procs)

    # Start the processes
    sup = yield bootstrap.bootstrap(None, processes)

    eval_start_arguments()

    simulator = Simulator(INSTRUMENT_ID, 9000)
    simulator.start()

    ia_procs = [
        {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent','spawnargs':{'instrument-id':INSTRUMENT_ID}},
    ]
    yield bootstrap.spawn_processes(ia_procs, sup=sup)

    ia_pid = sup.get_child_id('SBE49IA')
    iaclient = InstrumentAgentClient(proc=sup, target=ia_pid)
    yield iaclient.register_resource(INSTRUMENT_ID)
Пример #2
0
    def setUp(self):
        yield self._start_container()

        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        services = [{
            'name': 'pubsub_registry',
            'module': 'ion.services.dm.distribution.pubsub_registry',
            'class': 'DataPubSubRegistryService'
        }, {
            'name': 'pubsub_service',
            'module': 'ion.services.dm.distribution.pubsub_service',
            'class': 'DataPubsubService'
        }, {
            'name': 'SBE49_Driver',
            'module': 'ion.agents.instrumentagents.SBE49_driver',
            'class': 'SBE49InstrumentDriver'
        }]

        self.sup = yield self._spawn_processes(services)

        self.driver_pid = yield self.sup.get_child_id('SBE49_Driver')
        logging.debug("Driver pid %s" % (self.driver_pid))

        self.driver_client = SBE49InstrumentDriverClient(
            proc=self.sup, target=self.driver_pid)
Пример #3
0
    def test_execute(self):
        """
        Test the ability of the SBE49 driver to execute commands through the
        InstrumentAgentClient class
        """
        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        try:

            response = yield self.IAClient.execute_instrument([['start','now', 1],
                                                               ['stop']])
            print "response ", response
            self.assert_(isinstance(response, dict))
            self.assert_('status' in response.keys())
            self.assertEqual(response['status'], 'OK')
            self.assert_('start' in response['value'])
            self.assert_('stop' in response['value'])
            self.assert_(response['status'] == 'OK')

            response = yield self.IAClient.execute_instrument([['badcommand',
                                                                'now','1']])
            self.assert_(isinstance(response, dict))
            self.assertEqual(response['status'], 'ERROR')

            response = yield self.IAClient.execute_instrument([])
            self.assert_(isinstance(response, dict))
            self.assertEqual(response['status'], 'ERROR')

        finally:
            yield self.simulator.stop()
Пример #4
0
def main():
    """
    Initializes container
    """
    logging.info("ION CONTAINER initializing... [LCA Java Integration Demo]")

    processes = []
    processes.extend(agent_procs)
    processes.extend(demo_procs)

    # Start the processes
    sup = yield bootstrap.bootstrap(None, processes)

    simulator = Simulator(INSTRUMENT_ID, 9000)
    simulator.start()

    irc = InstrumentRegistryClient(proc=sup)

    ir1 = InstrumentResource.create_new_resource()
    ir1.name = "Demo_CTD_1"
    ir1.model = "SBE49"
    ir1.serial_num = "12345"
    ir1.fw_version = "1.334"
    ir1.manufactorer = "SeaBird"
    ir1 = yield irc.register_instrument_instance(ir1)
    ir1_ref = ir1.reference(head=True)

    ir2 = InstrumentResource.create_new_resource()
    ir2.name = "Demo_CTD_2"
    ir2.model = "SBE49"
    ir2.serial_num = "12399"
    ir2.fw_version = "1.335"
    ir2.manufactorer = "SeaBird"
    ir2 = yield irc.register_instrument_instance(ir2)

    dprc = DataProductRegistryClient(proc=sup)

    dp1 = DataProductResource.create_new_resource()
    dp1.instrument_ref = ir1_ref
    dp1.name = "Demo_Data_Product_1"
    dp1.dataformat = "binary"
    dp1 = yield dprc.register_data_product(dp1)

    ia_procs = [
        {
            'name': 'SBE49IA',
            'module': 'ion.agents.instrumentagents.SBE49_IA',
            'class': 'SBE49InstrumentAgent',
            'spawnargs': {
                'instrument-id': INSTRUMENT_ID
            }
        },
    ]
    yield bootstrap.spawn_processes(ia_procs, sup=sup)

    ia_pid = sup.get_child_id('SBE49IA')
    iaclient = InstrumentAgentClient(proc=sup, target=ia_pid)
    yield iaclient.register_resource(INSTRUMENT_ID)
Пример #5
0
    def op_start_instrument_agent(self, content, headers, msg):
        """
        Service operation: Starts an instrument agent for a type of
        instrument.
        """
        if 'instrumentID' in content:
            inst_id = str(content['instrumentID'])
        else:
            raise ValueError("Input for instrumentID not present")

        if 'model' in content:
            model = str(content['model'])
        else:
            raise ValueError("Input for model not present")

        if model != 'SBE49':
            raise ValueError("Only SBE49 supported!")

        agent_pid = yield self.get_agent_pid_for_instrument(inst_id)
        if agent_pid:
            raise StandardError("Agent already started for instrument " +
                                str(inst_id))

        simulator = Simulator(inst_id)
        simulator.start()

        topicname = "Inst/RAW/" + inst_id
        topic = PubSubTopicResource.create(topicname, "")

        # Use the service to create a queue and register the topic
        topic = yield self.dpsc.define_topic(topic)

        iagent_args = {}
        iagent_args['instrument-id'] = inst_id
        driver_args = {}
        driver_args['port'] = simulator.port
        driver_args['publish-to'] = topic.RegistryIdentity
        iagent_args['driver-args'] = driver_args

        iapd = ProcessDesc(
            **{
                'name': 'SBE49IA',
                'module': 'ion.agents.instrumentagents.SBE49_IA',
                'class': 'SBE49InstrumentAgent',
                'spawnargs': iagent_args
            })

        iagent_id = yield self.spawn_child(iapd)
        iaclient = InstrumentAgentClient(proc=self, target=iagent_id)
        yield iaclient.register_resource(inst_id)

        yield self.reply_ok(msg, "OK")
Пример #6
0
def main():
    """
    Initializes container
    """
    logging.info("ION CONTAINER initializing... [LCA Java Integration Demo]")

    processes = []
    processes.extend(agent_procs)
    processes.extend(demo_procs)

    # Start the processes
    sup = yield bootstrap.bootstrap(None, processes)

    simulator = Simulator(INSTRUMENT_ID, 9000)
    simulator.start()

    irc = InstrumentRegistryClient(proc=sup)

    ir1 = InstrumentResource.create_new_resource()
    ir1.name = "Demo_CTD_1"
    ir1.model = "SBE49"
    ir1.serial_num = "12345"
    ir1.fw_version = "1.334"
    ir1.manufactorer = "SeaBird"
    ir1 = yield irc.register_instrument_instance(ir1)
    ir1_ref = ir1.reference(head=True)

    ir2 = InstrumentResource.create_new_resource()
    ir2.name = "Demo_CTD_2"
    ir2.model = "SBE49"
    ir2.serial_num = "12399"
    ir2.fw_version = "1.335"
    ir2.manufactorer = "SeaBird"
    ir2 = yield irc.register_instrument_instance(ir2)

    dprc = DataProductRegistryClient(proc=sup)

    dp1 = DataProductResource.create_new_resource()
    dp1.instrument_ref = ir1_ref
    dp1.name = "Demo_Data_Product_1"
    dp1.dataformat = "binary"
    dp1 = yield dprc.register_data_product(dp1)

    ia_procs = [
        {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent','spawnargs':{'instrument-id':INSTRUMENT_ID}},
    ]
    yield bootstrap.spawn_processes(ia_procs, sup=sup)

    ia_pid = sup.get_child_id('SBE49IA')
    iaclient = InstrumentAgentClient(proc=sup,target=ia_pid)
    yield iaclient.register_resource(INSTRUMENT_ID)
    def op_start_instrument_agent(self, content, headers, msg):
        """
        Service operation: Starts an instrument agent for a type of
        instrument.
        """
        if 'instrumentID' in content:
            inst_id = str(content['instrumentID'])
        else:
            raise ValueError("Input for instrumentID not present")

        if 'model' in content:
            model = str(content['model'])
        else:
            raise ValueError("Input for model not present")

        if model != 'SBE49':
            raise ValueError("Only SBE49 supported!")

        agent_pid = yield self.get_agent_pid_for_instrument(inst_id)
        if agent_pid:
            raise StandardError("Agent already started for instrument "+str(inst_id))

        simulator = Simulator(inst_id)
        simulator.start()

        topicname = "Inst/RAW/"+inst_id
        topic = PubSubTopicResource.create(topicname,"")

        # Use the service to create a queue and register the topic
        topic = yield self.dpsc.define_topic(topic)

        iagent_args = {}
        iagent_args['instrument-id'] = inst_id
        driver_args = {}
        driver_args['port'] = simulator.port
        driver_args['publish-to'] = topic.RegistryIdentity
        iagent_args['driver-args'] = driver_args

        iapd = ProcessDesc(**{'name':'SBE49IA',
                  'module':'ion.agents.instrumentagents.SBE49_IA',
                  'class':'SBE49InstrumentAgent',
                  'spawnargs':iagent_args})

        iagent_id = yield self.spawn_child(iapd)
        iaclient = InstrumentAgentClient(proc=self, target=iagent_id)
        yield iaclient.register_resource(inst_id)

        yield self.reply_ok(msg, "OK")
Пример #8
0
    def test_get_set_SBE49_params(self):
        """
        Test the ability of the SBE49 driver to send and receive get, set,
        and other messages. Best called as RPC message pairs.
        """

        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        # Sleep for a while to allow simlator to get set up.
        yield pu.asleep(1)

        try:
            
            response = yield self.IAClient.get_from_instrument(['baudrate',
                                                                'outputformat'])
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['baudrate'], 9600)
            self.assertEqual(response['outputformat'], 0)
    
            response = yield self.IAClient.set_to_instrument({'baudrate': 19200,
                                                'outputformat': 1})
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['baudrate'], 19200)
            self.assertEqual(response['outputformat'], 1)
            
            response = yield self.IAClient.get_from_instrument(['baudrate',
                                                                'outputformat'])
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['baudrate'], 19200)
            self.assertEqual(response['outputformat'], 1)
    
            response = yield self.IAClient.set_to_instrument({'outputformat': 2})
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['outputformat'], 2)
            
            # Try setting something bad
            response = yield self.IAClient.set_to_instrument({'baudrate': 19200,
                                                'badvalue': 1})
            self.assert_(response['status'] == 'ERROR')
            self.assert_('baudrate' not in response)

        finally:
            yield self.simulator.stop()
Пример #9
0
    def setUp(self):
        yield self._start_container()

        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        services = [
            {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'},
            {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'},

            {'name':'SBE49_Driver','module':'ion.agents.instrumentagents.SBE49_driver','class':'SBE49InstrumentDriver'}
            ]

        self.sup = yield self._spawn_processes(services)

        self.driver_pid = yield self.sup.get_child_id('SBE49_Driver')
        logging.debug("Driver pid %s" % (self.driver_pid))

        self.driver_client = SBE49InstrumentDriverClient(proc=self.sup,
                                                         target=self.driver_pid)
    def setUp(self):
        yield self._start_container()

        services = [
            {'name':'instreg','module':'ion.services.coi.agent_registry','class':'AgentRegistryService'},
            {'name':'instreg','module':'ion.services.sa.instrument_registry','class':'InstrumentRegistryService'},
            {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'},
            {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'},
            {'name':'dprodreg','module':'ion.services.sa.data_product_registry','class':'DataProductRegistryService'},
            {'name':'instmgmt','module':'ion.services.sa.instrument_management','class':'InstrumentManagementService'},

            {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent'},
        ]

        sup = yield self._spawn_processes(services)

        #self.agreg_client = AgentRegistryClient(proc=sup)
        #yield self.agreg_client.clear_registry()

        self.ia_pid = sup.get_child_id('SBE49IA')
        self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid)

        self.imc = InstrumentManagementClient(proc=sup)

        self.newInstrument = {'manufacturer' : "SeaBird Electronics",
                 'model' : "unknown model",
                 'serial_num' : "1234",
                 'fw_version' : "1"}

        instrument = yield self.imc.create_new_instrument(self.newInstrument)
        self.inst_id = instrument.RegistryIdentity
        logging.info("*** Instrument created with ID="+str(self.inst_id))

        self.simulator = Simulator(self.inst_id, 9000)
        self.simulator.start()

        yield self.iaclient.register_resource(self.inst_id)
class TestInstMgmtRT(IonTestCase):
    """
    Testing instrument management service in end-to-end roundtrip mode
    """

    @defer.inlineCallbacks
    def setUp(self):
        yield self._start_container()

        services = [
            {'name':'instreg','module':'ion.services.coi.agent_registry','class':'AgentRegistryService'},
            {'name':'instreg','module':'ion.services.sa.instrument_registry','class':'InstrumentRegistryService'},
            {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'},
            {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'},
            {'name':'dprodreg','module':'ion.services.sa.data_product_registry','class':'DataProductRegistryService'},
            {'name':'instmgmt','module':'ion.services.sa.instrument_management','class':'InstrumentManagementService'},

            {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent'},
        ]

        sup = yield self._spawn_processes(services)

        #self.agreg_client = AgentRegistryClient(proc=sup)
        #yield self.agreg_client.clear_registry()

        self.ia_pid = sup.get_child_id('SBE49IA')
        self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid)

        self.imc = InstrumentManagementClient(proc=sup)

        self.newInstrument = {'manufacturer' : "SeaBird Electronics",
                 'model' : "unknown model",
                 'serial_num' : "1234",
                 'fw_version' : "1"}

        instrument = yield self.imc.create_new_instrument(self.newInstrument)
        self.inst_id = instrument.RegistryIdentity
        logging.info("*** Instrument created with ID="+str(self.inst_id))

        self.simulator = Simulator(self.inst_id, 9000)
        self.simulator.start()

        yield self.iaclient.register_resource(self.inst_id)


    @defer.inlineCallbacks
    def tearDown(self):
        yield self.simulator.stop()
        yield Simulator.stop_all_simulators()
        yield self._stop_container()

    @defer.inlineCallbacks
    def test_get_status(self):
        """
        Get status back from instrument agent associated with instrument id
        """
        res = yield self.imc.get_instrument_state(self.inst_id)
        self.assertNotEqual(res, None)
        logging.info("Instrument status: " +str(res))

    @defer.inlineCallbacks
    def test_execute_command(self):
        """
        Execute command through instrument agent associated with instrument id
        """
        res = yield self.imc.execute_command(self.inst_id, 'start', [1])
        logging.info("Command result 1" +str(res))

    @defer.inlineCallbacks
    def test_start_agent(self):
        """
        Start the agent with all
        """
        newInstrument = {'manufacturer' : "SeaBird Electronics",
                 'model' : "SBE49",
                 'serial_num' : "99931",
                 'fw_version' : "1"}

        instrument = yield self.imc.create_new_instrument(newInstrument)
        inst_id1 = instrument.RegistryIdentity
        logging.info("*** Instrument 2 created with ID="+str(inst_id1))

        res = yield self.imc.start_instrument_agent(inst_id1, 'SBE49')
        logging.info("Command result 1" +str(res))
 def tearDown(self):
     yield self.simulator.stop()
     yield Simulator.stop_all_simulators()
     yield self._stop_container()
Пример #13
0
class TestInstMgmtRT(IonTestCase):
    """
    Testing instrument management service in end-to-end roundtrip mode
    """
    @defer.inlineCallbacks
    def setUp(self):
        yield self._start_container()

        services = [
            {
                'name': 'instreg',
                'module': 'ion.services.coi.agent_registry',
                'class': 'AgentRegistryService'
            },
            {
                'name': 'instreg',
                'module': 'ion.services.sa.instrument_registry',
                'class': 'InstrumentRegistryService'
            },
            {
                'name': 'pubsub_registry',
                'module': 'ion.services.dm.distribution.pubsub_registry',
                'class': 'DataPubSubRegistryService'
            },
            {
                'name': 'pubsub_service',
                'module': 'ion.services.dm.distribution.pubsub_service',
                'class': 'DataPubsubService'
            },
            {
                'name': 'dprodreg',
                'module': 'ion.services.sa.data_product_registry',
                'class': 'DataProductRegistryService'
            },
            {
                'name': 'instmgmt',
                'module': 'ion.services.sa.instrument_management',
                'class': 'InstrumentManagementService'
            },
            {
                'name': 'SBE49IA',
                'module': 'ion.agents.instrumentagents.SBE49_IA',
                'class': 'SBE49InstrumentAgent'
            },
        ]

        sup = yield self._spawn_processes(services)

        #self.agreg_client = AgentRegistryClient(proc=sup)
        #yield self.agreg_client.clear_registry()

        self.ia_pid = sup.get_child_id('SBE49IA')
        self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid)

        self.imc = InstrumentManagementClient(proc=sup)

        self.newInstrument = {
            'manufacturer': "SeaBird Electronics",
            'model': "unknown model",
            'serial_num': "1234",
            'fw_version': "1"
        }

        instrument = yield self.imc.create_new_instrument(self.newInstrument)
        self.inst_id = instrument.RegistryIdentity
        logging.info("*** Instrument created with ID=" + str(self.inst_id))

        self.simulator = Simulator(self.inst_id, 9000)
        self.simulator.start()

        yield self.iaclient.register_resource(self.inst_id)

    @defer.inlineCallbacks
    def tearDown(self):
        yield self.simulator.stop()
        yield Simulator.stop_all_simulators()
        yield self._stop_container()

    @defer.inlineCallbacks
    def test_get_status(self):
        """
        Get status back from instrument agent associated with instrument id
        """
        res = yield self.imc.get_instrument_state(self.inst_id)
        self.assertNotEqual(res, None)
        logging.info("Instrument status: " + str(res))

    @defer.inlineCallbacks
    def test_execute_command(self):
        """
        Execute command through instrument agent associated with instrument id
        """
        res = yield self.imc.execute_command(self.inst_id, 'start', [1])
        logging.info("Command result 1" + str(res))

    @defer.inlineCallbacks
    def test_start_agent(self):
        """
        Start the agent with all
        """
        newInstrument = {
            'manufacturer': "SeaBird Electronics",
            'model': "SBE49",
            'serial_num': "99931",
            'fw_version': "1"
        }

        instrument = yield self.imc.create_new_instrument(newInstrument)
        inst_id1 = instrument.RegistryIdentity
        logging.info("*** Instrument 2 created with ID=" + str(inst_id1))

        res = yield self.imc.start_instrument_agent(inst_id1, 'SBE49')
        logging.info("Command result 1" + str(res))
Пример #14
0
 def tearDown(self):
     yield self.simulator.stop()
     yield Simulator.stop_all_simulators()
     yield self._stop_container()
Пример #15
0
    def setUp(self):
        yield self._start_container()

        services = [
            {
                'name': 'instreg',
                'module': 'ion.services.coi.agent_registry',
                'class': 'AgentRegistryService'
            },
            {
                'name': 'instreg',
                'module': 'ion.services.sa.instrument_registry',
                'class': 'InstrumentRegistryService'
            },
            {
                'name': 'pubsub_registry',
                'module': 'ion.services.dm.distribution.pubsub_registry',
                'class': 'DataPubSubRegistryService'
            },
            {
                'name': 'pubsub_service',
                'module': 'ion.services.dm.distribution.pubsub_service',
                'class': 'DataPubsubService'
            },
            {
                'name': 'dprodreg',
                'module': 'ion.services.sa.data_product_registry',
                'class': 'DataProductRegistryService'
            },
            {
                'name': 'instmgmt',
                'module': 'ion.services.sa.instrument_management',
                'class': 'InstrumentManagementService'
            },
            {
                'name': 'SBE49IA',
                'module': 'ion.agents.instrumentagents.SBE49_IA',
                'class': 'SBE49InstrumentAgent'
            },
        ]

        sup = yield self._spawn_processes(services)

        #self.agreg_client = AgentRegistryClient(proc=sup)
        #yield self.agreg_client.clear_registry()

        self.ia_pid = sup.get_child_id('SBE49IA')
        self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid)

        self.imc = InstrumentManagementClient(proc=sup)

        self.newInstrument = {
            'manufacturer': "SeaBird Electronics",
            'model': "unknown model",
            'serial_num': "1234",
            'fw_version': "1"
        }

        instrument = yield self.imc.create_new_instrument(self.newInstrument)
        self.inst_id = instrument.RegistryIdentity
        logging.info("*** Instrument created with ID=" + str(self.inst_id))

        self.simulator = Simulator(self.inst_id, 9000)
        self.simulator.start()

        yield self.iaclient.register_resource(self.inst_id)
Пример #16
0
class TestSBE49(IonTestCase):
    @defer.inlineCallbacks
    def setUp(self):
        yield self._start_container()

        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        services = [{
            'name': 'pubsub_registry',
            'module': 'ion.services.dm.distribution.pubsub_registry',
            'class': 'DataPubSubRegistryService'
        }, {
            'name': 'pubsub_service',
            'module': 'ion.services.dm.distribution.pubsub_service',
            'class': 'DataPubsubService'
        }, {
            'name': 'SBE49_Driver',
            'module': 'ion.agents.instrumentagents.SBE49_driver',
            'class': 'SBE49InstrumentDriver'
        }]

        self.sup = yield self._spawn_processes(services)

        self.driver_pid = yield self.sup.get_child_id('SBE49_Driver')
        logging.debug("Driver pid %s" % (self.driver_pid))

        self.driver_client = SBE49InstrumentDriverClient(
            proc=self.sup, target=self.driver_pid)

    @defer.inlineCallbacks
    def tearDown(self):
        yield self.simulator.stop()

        # stop_SBE49_simulator(self.simproc)
        yield self._stop_container()

    @defer.inlineCallbacks
    def test_create_topic(self):
        #dpsc = DataPubsubClient(self.pubsubSuper)

        dpsc = DataPubsubClient(self.sup)
        # Create and Register a topic
        """
        DHE: not sure the driver should be creating the topic; for right
        now I'll have the test case do it.
        """
        self.topic = PubSubTopicResource.create('SBE49 Topic',
                                                "oceans, oil spill")
        self.topic = yield dpsc.define_topic(self.topic)

        print 'TADA!'

    @defer.inlineCallbacks
    def test_initialize(self):
        result = yield self.driver_client.initialize('some arg')
        print 'TADA!'

    @defer.inlineCallbacks
    def test_driver_load(self):
        config_vals = {'addr': '127.0.0.1', 'port': '9000'}
        result = yield self.driver_client.configure_driver(config_vals)
        self.assertEqual(result['status'], 'OK')
        self.assertEqual(result['addr'], config_vals['addr'])
        self.assertEqual(result['port'], config_vals['port'])

    @defer.inlineCallbacks
    def test_fetch_set(self):
        params = {'outputformat': '2'}
        result = yield self.driver_client.set_params(params)
        self.assertEqual(result['status'], 'OK')

        params = {'baudrate': '19200'}
        result = yield self.driver_client.set_params(params)
        self.assertEqual(result['status'], 'OK')
        """
        params = {'baudrate':'19200', 'outputsal':'N'}
        result = yield self.driver_client.fetch_params(params.keys())
        self.assertNotEqual(params, result)
        result = yield self.driver_client.set_params({})
        self.assertEqual(len(result.keys()), 1)
        self.assertEqual(result['status'], 'OK')
        set_result = yield self.driver_client.set_params(params)
        self.assertEqual(set_result['status'], 'OK')
        self.assertEqual(set_result['baudrate'], params['baudrate'])
        self.assertEqual(set_result['outputsal'], params['outputsal'])
        result = yield self.driver_client.fetch_params(params.keys())
        self.assertEqual(result['status'], 'OK')
        self.assertEqual(result['baudrate'], params['baudrate'])
        self.assertEqual(result['outputsal'], params['outputsal'])
        """

        #raise unittest.SkipTest('Temporarily skipping')

    @defer.inlineCallbacks
    def test_execute(self):
        """
        Test the execute command to the Instrument Driver
        """
        result = yield self.driver_client.initialize('some arg')

        dpsc = DataPubsubClient(self.sup)

        subscription = SubscriptionResource()
        subscription.topic1 = PubSubTopicResource.create('SBE49 Topic', '')
        #subscription.topic2 = PubSubTopicResource.create('','oceans')

        subscription.workflow = {
            'consumer1':
                {'module':'ion.services.dm.distribution.consumers.logging_consumer',
                 'consumerclass':'LoggingConsumer',\
                 'attach':'topic1'}
                }

        subscription = yield dpsc.define_subscription(subscription)

        logging.info('Defined subscription: ' + str(subscription))

        cmd1 = [['ds', 'now']]
        #cmd1 = [['start', 'now']]
        #cmd2 = [['stop', 'now']]
        #cmd2 = [['pumpoff', '3600', '1']]
        result = yield self.driver_client.execute(cmd1)
        self.assertEqual(result['status'], 'OK')
        # DHE: wait a while...
        yield pu.asleep(1)
        #result = yield self.driver_client.execute(cmd2)
        #self.assertEqual(result['status'], 'OK')

        # DHE: disconnecting; a connect would probably be good.
        result = yield self.driver_client.disconnect(['some arg'])

    @defer.inlineCallbacks
    def test_sample(self):
        result = yield self.driver_client.initialize('some arg')

        dpsc = DataPubsubClient(self.sup)
        topicname = 'SBE49 Topic'
        topic = PubSubTopicResource.create(topicname, "")

        # Use the service to create a queue and register the topic
        topic = yield dpsc.define_topic(topic)

        subscription = SubscriptionResource()
        subscription.topic1 = PubSubTopicResource.create(topicname, '')

        subscription.workflow = {
            'consumer1':
                {'module':'ion.services.dm.distribution.consumers.logging_consumer',
                 'consumerclass':'LoggingConsumer',\
                 'attach':'topic1'}
                }

        subscription = yield dpsc.define_subscription(subscription)

        logging.info('Defined subscription: ' + str(subscription))

        params = {}
        params['publish-to'] = topic.RegistryIdentity
        yield self.driver_client.configure_driver(params)

        cmd1 = [['ds', 'now']]
        result = yield self.driver_client.execute(cmd1)
        self.assertEqual(result['status'], 'OK')

        yield pu.asleep(1)

        result = yield self.driver_client.disconnect(['some arg'])
Пример #17
0
class TestSBE49(IonTestCase):


    @defer.inlineCallbacks
    def setUp(self):
        yield self._start_container()

        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        services = [
            {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'},
            {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'},

            {'name':'SBE49_Driver','module':'ion.agents.instrumentagents.SBE49_driver','class':'SBE49InstrumentDriver'}
            ]

        self.sup = yield self._spawn_processes(services)

        self.driver_pid = yield self.sup.get_child_id('SBE49_Driver')
        logging.debug("Driver pid %s" % (self.driver_pid))

        self.driver_client = SBE49InstrumentDriverClient(proc=self.sup,
                                                         target=self.driver_pid)

    @defer.inlineCallbacks
    def tearDown(self):
        yield self.simulator.stop()

        # stop_SBE49_simulator(self.simproc)
        yield self._stop_container()

    @defer.inlineCallbacks
    def test_create_topic(self):
        #dpsc = DataPubsubClient(self.pubsubSuper)

        dpsc = DataPubsubClient(self.sup)
        # Create and Register a topic
        """
        DHE: not sure the driver should be creating the topic; for right
        now I'll have the test case do it.
        """
        self.topic = PubSubTopicResource.create('SBE49 Topic',"oceans, oil spill")
        self.topic = yield dpsc.define_topic(self.topic)


        print 'TADA!'


    @defer.inlineCallbacks
    def test_initialize(self):
        result = yield self.driver_client.initialize('some arg')
        print 'TADA!'

    @defer.inlineCallbacks
    def test_driver_load(self):
        config_vals = {'addr':'127.0.0.1', 'port':'9000'}
        result = yield self.driver_client.configure_driver(config_vals)
        self.assertEqual(result['status'], 'OK')
        self.assertEqual(result['addr'], config_vals['addr'])
        self.assertEqual(result['port'], config_vals['port'])


    @defer.inlineCallbacks
    def test_fetch_set(self):
        params = {'outputformat':'2'}
        result = yield self.driver_client.set_params(params)
        self.assertEqual(result['status'], 'OK')

        params = {'baudrate':'19200'}
        result = yield self.driver_client.set_params(params)
        self.assertEqual(result['status'], 'OK')

        """
        params = {'baudrate':'19200', 'outputsal':'N'}
        result = yield self.driver_client.fetch_params(params.keys())
        self.assertNotEqual(params, result)
        result = yield self.driver_client.set_params({})
        self.assertEqual(len(result.keys()), 1)
        self.assertEqual(result['status'], 'OK')
        set_result = yield self.driver_client.set_params(params)
        self.assertEqual(set_result['status'], 'OK')
        self.assertEqual(set_result['baudrate'], params['baudrate'])
        self.assertEqual(set_result['outputsal'], params['outputsal'])
        result = yield self.driver_client.fetch_params(params.keys())
        self.assertEqual(result['status'], 'OK')
        self.assertEqual(result['baudrate'], params['baudrate'])
        self.assertEqual(result['outputsal'], params['outputsal'])
        """

        #raise unittest.SkipTest('Temporarily skipping')


    @defer.inlineCallbacks
    def test_execute(self):
        """
        Test the execute command to the Instrument Driver
        """
        result = yield self.driver_client.initialize('some arg')

        dpsc = DataPubsubClient(self.sup)

        subscription = SubscriptionResource()
        subscription.topic1 = PubSubTopicResource.create('SBE49 Topic','')
        #subscription.topic2 = PubSubTopicResource.create('','oceans')

        subscription.workflow = {
            'consumer1':
                {'module':'ion.services.dm.distribution.consumers.logging_consumer',
                 'consumerclass':'LoggingConsumer',\
                 'attach':'topic1'}
                }

        subscription = yield dpsc.define_subscription(subscription)

        logging.info('Defined subscription: '+str(subscription))

        cmd1 = [['ds', 'now']]
        #cmd1 = [['start', 'now']]
        #cmd2 = [['stop', 'now']]
        #cmd2 = [['pumpoff', '3600', '1']]
        result = yield self.driver_client.execute(cmd1)
        self.assertEqual(result['status'], 'OK')
        # DHE: wait a while...
        yield pu.asleep(1)
        #result = yield self.driver_client.execute(cmd2)
        #self.assertEqual(result['status'], 'OK')


        # DHE: disconnecting; a connect would probably be good.
        result = yield self.driver_client.disconnect(['some arg'])


    @defer.inlineCallbacks
    def test_sample(self):
        result = yield self.driver_client.initialize('some arg')

        dpsc = DataPubsubClient(self.sup)
        topicname = 'SBE49 Topic'
        topic = PubSubTopicResource.create(topicname,"")

        # Use the service to create a queue and register the topic
        topic = yield dpsc.define_topic(topic)

        subscription = SubscriptionResource()
        subscription.topic1 = PubSubTopicResource.create(topicname,'')

        subscription.workflow = {
            'consumer1':
                {'module':'ion.services.dm.distribution.consumers.logging_consumer',
                 'consumerclass':'LoggingConsumer',\
                 'attach':'topic1'}
                }

        subscription = yield dpsc.define_subscription(subscription)

        logging.info('Defined subscription: '+str(subscription))

        params = {}
        params['publish-to'] = topic.RegistryIdentity
        yield self.driver_client.configure_driver(params)

        cmd1 = [['ds', 'now']]
        result = yield self.driver_client.execute(cmd1)
        self.assertEqual(result['status'], 'OK')

        yield pu.asleep(1)

        result = yield self.driver_client.disconnect(['some arg'])
Пример #18
0
class TestInstrumentAgent(IonTestCase):

    @defer.inlineCallbacks
    def setUp(self):
        yield self._start_container()

        # Start an instrument agent
        processes = [
            {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'},
            {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'},
            {'name':'agent_registry',
             'module':'ion.services.coi.agent_registry',
             'class':'ResourceRegistryService'},
            {'name':'testSBE49IA',
             'module':'ion.agents.instrumentagents.SBE49_IA',
             'class':'SBE49InstrumentAgent'},
        ]
        self.sup = yield self._spawn_processes(processes)
        self.svc_id = yield self.sup.get_child_id('testSBE49IA')
        self.reg_id = yield self.sup.get_child_id('agent_registry')

        # Start a client (for the RPC)
        self.IAClient = IA.InstrumentAgentClient(proc=self.sup,
                                                 target=self.svc_id)

        # Start an Agent Registry to test against
        self.reg_client = AgentRegistryClient(proc=self.sup)
        yield self.reg_client.clear_registry()

    @defer.inlineCallbacks
    def tearDown(self):
        yield self._stop_container()

    @defer.inlineCallbacks
    def test_get_SBE49_capabilities(self):
        """
        Test the ability to gather capabilities from the SBE49 instrument
        capabilities
        """
        result = yield self.IAClient.get_capabilities()
        #logging.info("getCapabilities result: "+ str(result))
        self.assert_(set(IACIParameters).issubset(set(result[IA.ci_parameters])))
        self.assert_(IA.driver_address in
                     result[IA.ci_parameters])
        self.assert_(list(IACICommands) == result[IA.ci_commands])
        self.assert_(list(IAInstCommands) ==
                     result[IA.instrument_commands])
        self.assert_(list(IAInstParameters) ==
                     result[IA.instrument_parameters])

    @defer.inlineCallbacks
    def test_get_set_SBE49_params(self):
        """
        Test the ability of the SBE49 driver to send and receive get, set,
        and other messages. Best called as RPC message pairs.
        """

        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        # Sleep for a while to allow simlator to get set up.
        yield pu.asleep(1)

        try:
            
            response = yield self.IAClient.get_from_instrument(['baudrate',
                                                                'outputformat'])
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['baudrate'], 9600)
            self.assertEqual(response['outputformat'], 0)
    
            response = yield self.IAClient.set_to_instrument({'baudrate': 19200,
                                                'outputformat': 1})
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['baudrate'], 19200)
            self.assertEqual(response['outputformat'], 1)
            
            response = yield self.IAClient.get_from_instrument(['baudrate',
                                                                'outputformat'])
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['baudrate'], 19200)
            self.assertEqual(response['outputformat'], 1)
    
            response = yield self.IAClient.set_to_instrument({'outputformat': 2})
            self.assert_(response['status'] == 'OK')
            self.assertEqual(response['outputformat'], 2)
            
            # Try setting something bad
            response = yield self.IAClient.set_to_instrument({'baudrate': 19200,
                                                'badvalue': 1})
            self.assert_(response['status'] == 'ERROR')
            self.assert_('baudrate' not in response)

        finally:
            yield self.simulator.stop()

    @defer.inlineCallbacks
    def test_registration(self):
        """
        Tests the ability of an instrument agent to successfully register
        ifself with the resource registry.
        """
        reg_ref = yield self.IAClient.register_resource("123")

        result = yield self.IAClient.get_resource_instance()
        self.assertNotEqual(result, None)

        self.assert_(isinstance(result, InstrumentAgentResourceInstance))
        self.assertNotEqual(result.driver_process_id, None)
        self.assertEqual(result.instrument_ref.RegistryIdentity, "123")

        self.assertEqual(reg_ref.RegistryCommit, '')
        self.assertNotEqual(result.RegistryCommit, reg_ref.RegistryCommit)
        self.assertEqual(reg_ref.RegistryIdentity, result.RegistryIdentity)

        # Verify the reference is the same
        result = yield self.IAClient.get_resource_ref()

        self.assertEqual(result, reg_ref)

    @defer.inlineCallbacks
    def test_lifecycle_states(self):
        """
        Test the resource lifecycle management
        """
        yield self.IAClient.register_resource("123")

        response = yield self.IAClient.set_lifecycle_state(LCS.inactive)
        self.assertEqual(response, LCS.inactive)

        response = yield self.IAClient.get_lifecycle_state()
        self.assertEqual(response, LCS.inactive)
        self.assertNotEqual(response, LCS.active)

        response = yield self.IAClient.set_lifecycle_state(LCS.active)
        self.assertEqual(response, LCS.active)

        response = yield self.IAClient.get_lifecycle_state()
        self.assertEqual(response, LCS.active)

    @defer.inlineCallbacks
    def test_execute(self):
        """
        Test the ability of the SBE49 driver to execute commands through the
        InstrumentAgentClient class
        """
        self.simulator = Simulator("123", 9000)
        self.simulator.start()

        try:

            response = yield self.IAClient.execute_instrument([['start','now', 1],
                                                               ['stop']])
            print "response ", response
            self.assert_(isinstance(response, dict))
            self.assert_('status' in response.keys())
            self.assertEqual(response['status'], 'OK')
            self.assert_('start' in response['value'])
            self.assert_('stop' in response['value'])
            self.assert_(response['status'] == 'OK')

            response = yield self.IAClient.execute_instrument([['badcommand',
                                                                'now','1']])
            self.assert_(isinstance(response, dict))
            self.assertEqual(response['status'], 'ERROR')

            response = yield self.IAClient.execute_instrument([])
            self.assert_(isinstance(response, dict))
            self.assertEqual(response['status'], 'ERROR')

        finally:
            yield self.simulator.stop()

    @defer.inlineCallbacks
    def test_get_driver_proc(self):
        """
        Test the methods for retreiving the driver process directly from
        the instrument agent.
        """
        response = yield self.IAClient.get_from_CI([IA.driver_address])
        self.assertNotEqual(response, None)
        """
        Not the best test or logic, but see if the format is at least close
        Need a better way to get at the process id of the driver...maybe
        out of the registry?
        """
        self.assertEqual(str(response[IA.driver_address]).rsplit('.', 1)[0],
                         str(self.svc_id).rsplit('.', 1)[0])

    @defer.inlineCallbacks
    def test_status(self):
        """
        Test to see if the status response is correct
        @todo Do we even need this function?
        """
        response = yield self.IAClient.get_status(['some_arg'])
        self.assert_(isinstance(response, dict))
        self.assertEqual(response['status'], "OK")
        self.assertEqual(response['value'], 'a-ok')

    @defer.inlineCallbacks
    def test_translator(self):
        """
        Test to see if the translator function is coming back cleanly
        @todo make this not a stub when we can pass functions through AMQP
        """
        raise unittest.SkipTest('Needs Refactor of LifeCycle State and Resource Descriptions')

        yield