本文整理汇总了Python中ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport.start_pagent方法的典型用法代码示例。如果您正苦于以下问题:Python DriverIntegrationTestSupport.start_pagent方法的具体用法?Python DriverIntegrationTestSupport.start_pagent怎么用?Python DriverIntegrationTestSupport.start_pagent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport
的用法示例。
在下文中一共展示了DriverIntegrationTestSupport.start_pagent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_port_agent
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
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()
示例2: TestSBE37Driver
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestSBE37Driver(unittest.TestCase):
"""
Integration tests for the sbe37 driver. This class tests and shows
use patterns for the sbe37 driver as a zmq driver process.
"""
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
def assertSampleDict(self, val):
"""
Verify the value is a sample dictionary for the sbe37.
"""
#{'p': [-6.945], 'c': [0.08707], 't': [20.002], 'time': [1333752198.450622]}
self.assertTrue(isinstance(val, dict))
self.assertTrue(val.has_key('c'))
self.assertTrue(val.has_key('t'))
self.assertTrue(val.has_key('p'))
self.assertTrue(val.has_key('time'))
c = val['c'][0]
t = val['t'][0]
p = val['p'][0]
time = val['time'][0]
self.assertTrue(isinstance(c, float))
self.assertTrue(isinstance(t, float))
self.assertTrue(isinstance(p, float))
self.assertTrue(isinstance(time, float))
def assertParamDict(self, pd, all_params=False):
"""
Verify all device parameters exist and are correct type.
"""
if all_params:
self.assertEqual(set(pd.keys()), set(PARAMS.keys()))
#print str(pd)
#print str(PARAMS)
for (key, type_val) in PARAMS.iteritems():
#print key
self.assertTrue(isinstance(pd[key], type_val))
else:
for (key, val) in pd.iteritems():
self.assertTrue(PARAMS.has_key(key))
self.assertTrue(isinstance(val, PARAMS[key]))
def assertParamVals(self, params, correct_params):
"""
Verify parameters take the correct values.
"""
self.assertEqual(set(params.keys()), set(correct_params.keys()))
for (key, val) in params.iteritems():
correct_val = correct_params[key]
if isinstance(val, float):
# Verify to 5% of the larger value.
max_val = max(abs(val), abs(correct_val))
self.assertAlmostEqual(val, correct_val, delta=max_val*.01)
else:
# int, bool, str, or tuple of same
#.........这里部分代码省略.........
示例3: InstrumentAgentTestDA
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class InstrumentAgentTestDA():
"""
Test cases for instrument agent class. Functions in this class provide
instrument agent integration tests for Direct Access mode and provide
a tutorial on use of the agent setup and interface.
"""
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)
log.info('LAUNCH_FROM_EGG: %s', LAUNCH_FROM_EGG)
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')
# 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.addCleanup(self._verify_agent_reset)
log.info('test setup complete')
###############################################################################
# Port agent helpers.
###############################################################################
def _start_pagent(self):
"""
Construct and start the port agent.
"""
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
}
def _verify_agent_reset(self):
"""
Check agent state and reset if necessary.
This called if a test fails and reset hasn't occurred.
"""
if self._ia_client is None:
return
state = self._ia_client.get_agent_state()
if state != ResourceAgentState.UNINITIALIZED:
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = self._ia_client.execute_agent(cmd)
###############################################################################
# Event helpers.
###############################################################################
def _start_event_subscriber(self, type='ResourceAgentEvent', count=0):
"""
Start a subscriber to the instrument agent events.
@param type The type of event to catch.
@count Trigger the async event result when events received reaches this.
"""
def consume_event(*args, **kwargs):
log.info('Test recieved ION event: args=%s, kwargs=%s, event=%s.',
str(args), str(kwargs), str(args[0]))
#.........这里部分代码省略.........
示例4: TestInstrumentAgent
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestInstrumentAgent(IonIntegrationTestCase):
"""
Test cases for instrument agent class. Functions in this class provide
instrument agent integration tests and provide a tutorial on use of
the agent setup and interface.
"""
def setUp(self):
"""
Initialize test members.
Start port agent.
Start container and client.
Start streams and subscribers.
Start agent, client.
"""
self._support = DriverIntegrationTestSupport(DRV_MOD,
DRV_CLS,
DEV_ADDR,
DEV_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)
# Start a resource agent client to talk with the instrument agent.
self._ia_client = None
self._ia_client = start_fake_instrument_agent(self.container, self._stream_config)
def _start_pagent(self):
"""
Construct and start the port agent.
"""
port = self._support.start_pagent()
# Configure driver to use port agent port number.
DVR_CONFIG['comms_config'] = {
'addr' : 'localhost',
'port' : port
}
def _start_data_subscribers(self):
"""
"""
# Create a pubsub client to create streams.
pubsub_client = PubsubManagementServiceClient(node=self.container.node)
# A callback for processing subscribed-to data.
def consume_data(message, headers):
log.info('Subscriber received data message: %s.', str(message))
self._samples_received.append(message)
if self._no_samples and self._no_samples == len(self._samples_received):
self._async_data_result.set()
# Create a stream subscriber registrar to create subscribers.
subscriber_registrar = StreamSubscriberRegistrar(process=self.container,
container=self.container)
# Create streams and subscriptions for each stream named in driver.
self._stream_config = {}
self._data_subscribers = []
# TODO the following is a mininal adjustment to at least let the test
# continue:
# for (stream_name, val) in PACKET_CONFIG.iteritems():
for stream_name in PACKET_CONFIG:
stream_def = ctd_stream_definition(stream_id=None)
stream_def_id = pubsub_client.create_stream_definition(
container=stream_def)
stream_id = pubsub_client.create_stream(
name=stream_name,
stream_definition_id=stream_def_id,
original=True,
encoding='ION R2')
#.........这里部分代码省略.........
示例5: TestAgentCommsAlerts
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestAgentCommsAlerts(IonIntegrationTestCase):
"""
"""
############################################################################
# Setup, teardown.
############################################################################
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)
###############################################################################
# Port agent helpers.
###############################################################################
def _start_pagent(self):
"""
Construct and start the port agent.
"""
port = self._support.start_pagent()
log.info('Port agent started at port %i',port)
#.........这里部分代码省略.........
示例6: TestAgentConnectionFailures
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestAgentConnectionFailures(IonIntegrationTestCase):
"""
Test cases for instrument agent class. Functions in this class provide
instrument agent integration tests and provide a tutorial on use of
the agent setup and interface.
"""
############################################################################
# Setup, teardown.
############################################################################
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
# 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('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)
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')
###############################################################################
# Port agent helpers.
###############################################################################
def _start_pagent(self):
"""
Construct and start the port agent.
"""
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
}
def _verify_agent_reset(self):
"""
Check agent state and reset if necessary.
This called if a test fails and reset hasn't occurred.
"""
if self._ia_client is None:
return
state = self._ia_client.get_agent_state(timeout=120.1)
if state != ResourceAgentState.UNINITIALIZED:
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = self._ia_client.execute_agent(cmd,timeout=300)
###############################################################################
# Event helpers.
###############################################################################
def _start_event_subscriber(self, type='ResourceAgentEvent', count=0):
"""
Start a subscriber to the instrument agent events.
#.........这里部分代码省略.........
示例7: TestAgentPersistence
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestAgentPersistence(IonIntegrationTestCase):
"""
"""
############################################################################
# Setup, teardown.
############################################################################
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
}
self._ia_client = None
self._ia_pid = '8989'
self.addCleanup(self._verify_agent_reset)
self.addCleanup(self.container.state_repository.put_state,
self._ia_pid, {})
###############################################################################
# Port agent helpers.
###############################################################################
def _start_pagent(self):
"""
Construct and start the port agent.
"""
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
}
###############################################################################
# Data stream helpers.
###############################################################################
def _build_stream_config(self):
"""
"""
# Create a pubsub client to create streams.
pubsub_client = PubsubManagementServiceClient(node=self.container.node)
dataset_management = DatasetManagementServiceClient()
# Create streams and subscriptions for each stream named in driver.
self._stream_config = {}
#.........这里部分代码省略.........
示例8: TestAgentPersistence
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestAgentPersistence(IonIntegrationTestCase):
"""
"""
############################################################################
# Setup, teardown.
############################################################################
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, {})
###############################################################################
# Port agent helpers.
###############################################################################
def _start_pagent(self):
"""
Construct and start the port agent.
"""
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
}
###############################################################################
# Data stream helpers.
###############################################################################
def _build_stream_config(self):
"""
"""
# Create a pubsub client to create streams.
pubsub_client = PubsubManagementServiceClient(node=self.container.node)
#.........这里部分代码省略.........
示例9: TrhphDriverProxy
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TrhphDriverProxy(InstrumentDriver):
"""
An InstrumentDriver serving as a proxy to the driver client
connecting to the actual TrhphInstrumentDriver implementation.
Extends InstrumentDriver (instead of TrhphInstrumentDriver) because
that's the main driver interface in general whereas extending
TrhphInstrumentDriver would bring unneeded implementation stuff.
"""
def __init__(self, device_address, device_port):
"""
Setup test cases.
"""
driver_module = 'mi.instrument.uw.res_probe.ooicore.trhph_driver'
driver_class = 'TrhphInstrumentDriver'
self._support = DriverIntegrationTestSupport(driver_module,
driver_class,
device_address,
device_port)
# Create and start the port agent.
mi_logger.info('starting port agent')
self.comms_config = {
'addr': 'localhost',
'port': self._support.start_pagent()}
# Create and start the driver.
mi_logger.info('starting driver client')
##<update-july-2012>:
## start_driver and _dvr_client no longer defined in
## DriverIntegrationTestSupport
# self._support.start_driver()
# self._dvr_client = self._support._dvr_client
dvr_config = {
'comms_config': self.comms_config,
'dvr_mod': driver_module,
'dvr_cls': driver_class,
'workdir' : '/tmp/',
'process_type': ('ZMQPyClassDriverLauncher',)
}
self._start_driver(dvr_config)
##</update-july-2012>
def _start_driver(self, dvr_config):
## Part of <update-july-2012>
##
## Adapted from InstrumentAgent._start_driver(self, dvr_config).
##
"""
Start the driver process and driver client.
@param dvr_config The driver configuration.
@raises InstDriverError If the driver or client failed to start properly.
"""
from ion.agents.instrument.driver_process import DriverProcess
self._dvr_proc = DriverProcess.get_process(dvr_config, True)
self._dvr_proc.launch()
# Verify the driver has started.
if not self._dvr_proc.getpid():
log.error('TrhphDriverProxy: error starting driver process.')
raise InstDriverError('Error starting driver process.')
def evt_recv(evt):
"""
Callback to receive asynchronous driver events.
@param evt The driver event received.
"""
log.info('TrhphDriverProxy:received driver event %s' % str(evt))
try:
driver_client = self._dvr_proc.get_client()
driver_client.start_messaging(evt_recv)
# retval = driver_client.cmd_dvr('process_echo', 'Test.')
self._dvr_client = driver_client
except Exception, e:
self._dvr_proc.stop()
log.error('TrhphDriverProxy: error starting driver client: %s' % e)
raise InstDriverError('Error starting driver client: %s' % e)
log.info('TrhphDriverProxy: started driver.')
示例10: TestRemoteClient
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
#.........这里部分代码省略.........
origin=self._resource_id,
callback=self.consume_event)
self._fake_result_subscriber.start()
self._fake_result_subscriber._ready_event.wait(timeout=CFG.endpoint.receive.timeout)
self.addCleanup(self._fake_result_subscriber.stop)
###################################################################
# Start/stop helpers.
###################################################################
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
}
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())
示例11: TestIAAlarms
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestIAAlarms(IonIntegrationTestCase):
"""
"""
############################################################################
# Setup, teardown.
############################################################################
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')
###############################################################################
# Port agent helpers.
###############################################################################
def _start_pagent(self):
"""
Construct and start the port agent.
"""
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
}
def _verify_agent_reset(self):
"""
Check agent state and reset if necessary.
This called if a test fails and reset hasn't occurred.
"""
if self._ia_client is None:
return
state = self._ia_client.get_agent_state()
if state != ResourceAgentState.UNINITIALIZED:
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = self._ia_client.execute_agent(cmd)
###############################################################################
# Event helpers.
###############################################################################
def _start_event_subscriber(self, type='StreamAlarmEvent', count=0):
"""
Start a subscriber to the instrument agent events.
@param type The type of event to catch.
@count Trigger the async event result when events received reaches this.
"""
def consume_event(*args, **kwargs):
print '#################'
log.info('Test recieved ION event: args=%s, kwargs=%s, event=%s.',
str(args), str(kwargs), str(args[0]))
self._events_received.append(args[0])
#.........这里部分代码省略.........
示例12: TestPuck
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestPuck(IonIntegrationTestCase):
"""
"""
############################################################################
# Setup, teardown.
############################################################################
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.
"""
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.
self._support.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.debug("Starting container client.")
self.container_client = ContainerAgentClient(node=self.container.node,
name=self.container.name)
self._build_stream_config()
###############################################################################
# Data stream helpers.
###############################################################################
def _build_stream_config(self):
"""
"""
# Create a pubsub client to create streams.
pubsub_client = PubsubManagementServiceClient(node=self.container.node)
dataset_management = DatasetManagementServiceClient()
# Create streams and subscriptions for each stream named in driver.
self._stream_config = {}
streams = {
'parsed' : 'ctd_parsed_param_dict',
'raw' : 'ctd_raw_param_dict'
}
for (stream_name, param_dict_name) in streams.iteritems():
pd_id = dataset_management.read_parameter_dictionary_by_name(param_dict_name, id_only=True)
stream_def_id = pubsub_client.create_stream_definition(name=stream_name, parameter_dictionary_id=pd_id)
pd = pubsub_client.read_stream_definition(stream_def_id).parameter_dictionary
stream_id, stream_route = pubsub_client.create_stream(name=stream_name,
exchange_point='science_data',
stream_definition_id=stream_def_id)
stream_config = dict(stream_route=stream_route,
routing_key=stream_route.routing_key,
exchange_point=stream_route.exchange_point,
stream_id=stream_id,
stream_definition_ref=stream_def_id,
parameter_dictionary=pd)
self._stream_config[stream_name] = stream_config
###############################################################################
# Tests.
###############################################################################
def test_xxx(self, host='localhost', port=DATA_PORT,
resource_id=IA_RESOURCE_ID, stream_config=None):
"""
"""
if not stream_config:
stream_config = self._stream_config
#.........这里部分代码省略.........
示例13: BaseIntTestPlatform
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
#.........这里部分代码省略.........
# Launch from egg or a local MI repo.
LAUNCH_FROM_EGG=True
if LAUNCH_FROM_EGG:
# Dynamically load the egg into the test path
launcher = ZMQEggDriverProcess(instrument_driver_config)
egg = launcher._get_egg(DRV_URI)
if not egg in sys.path: sys.path.insert(0, egg)
instrument_driver_config['process_type'] = (DriverProcessType.EGG,)
else:
mi_repo = os.getcwd() + os.sep + 'extern' + os.sep + 'mi_repo'
if not mi_repo in sys.path: sys.path.insert(0, mi_repo)
instrument_driver_config['process_type'] = (DriverProcessType.PYTHON_MODULE,)
instrument_driver_config['mi_repo'] = mi_repo
DEV_ADDR = CFG.device.sbe37.host
DEV_PORT = CFG.device.sbe37.port
DATA_PORT = CFG.device.sbe37.port_agent_data_port
CMD_PORT = CFG.device.sbe37.port_agent_cmd_port
PA_BINARY = CFG.device.sbe37.port_agent_binary
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.
port = self._support.start_pagent()
log.info('Port agent started at port %i', port)
self.addCleanup(self._support.stop_pagent)
# Configure instrument driver to use port agent port number.
instrument_driver_config['comms_config'] = {
'addr': 'localhost',
'port': port,
'cmd_port': CMD_PORT
}
return instrument_driver_config
def _make_instrument_agent_structure(self, org_obj, agent_config=None):
if None is agent_config: agent_config = {}
# from test_activate_instrument:test_activateInstrumentSample
# Create InstrumentModel
instModel_obj = IonObject(RT.InstrumentModel,
name='SBE37IMModel',
description="SBE37IMModel")
instModel_id = self.IMS.create_instrument_model(instModel_obj)
log.debug('new InstrumentModel id = %s ', instModel_id)
# agent creation
instrument_agent_obj = IonObject(RT.InstrumentAgent,
name='agent007',
description="SBE37IMAgent",
driver_uri="http://sddevrepo.oceanobservatories.org/releases/seabird_sbe37smb_ooicore-0.0.1a-py2.7.egg",
stream_configurations=self._get_instrument_stream_configs())
instrument_agent_id = self.IMS.create_instrument_agent(instrument_agent_obj)
示例14: TestInstrumentDataIngestion
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestInstrumentDataIngestion(IonIntegrationTestCase):
"""
Tests for data ingestion from an instrument. It is basically the
test_poll from test_instrument_agent (as of 7/23/12) with
the additional preparation of the ingestion management service and the
verification that the published granules are persisted.
"""
def setUp(self):
self.resource_registry = ResourceRegistryServiceClient()
self.ingestion_management = IngestionManagementServiceClient()
self._support = DriverIntegrationTestSupport(DRV_MOD,
DRV_CLS,
DEV_ADDR,
DEV_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)
self.prepare_ingestion()
# Start event subscribers, add stop to cleanup.
self._no_events = None
self._async_event_result = AsyncResult()
self._events_received = []
# 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("TestInstrumentDataIngestion.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 = None
self._ia_client = ResourceAgentClient(IA_RESOURCE_ID, process=FakeProcess())
log.info('Got ia client %s.', str(self._ia_client))
def _start_pagent(self):
"""
Construct and start the port agent.
"""
port = self._support.start_pagent()
# Configure driver to use port agent port number.
DVR_CONFIG['comms_config'] = {
'addr' : 'localhost',
'port' : port
}
def _start_data_subscribers(self):
"""
"""
# Create a pubsub client to create streams.
pubsub_client = PubsubManagementServiceClient(node=self.container.node)
# A callback for processing subscribed-to data.
def consume_data(message, headers):
log.info('Subscriber received data message: type(message)=%s.', str(type(message)))
log.info('Subscriber received data message: %s.', str(message))
self._samples_received.append(message)
if self._no_samples and self._no_samples == len(self._samples_received):
self._async_data_result.set()
# Create a stream subscriber registrar to create subscribers.
#.........这里部分代码省略.........
示例15: TestInstrumentAgentWithTrhph
# 需要导入模块: from ion.agents.instrument.driver_int_test_support import DriverIntegrationTestSupport [as 别名]
# 或者: from ion.agents.instrument.driver_int_test_support.DriverIntegrationTestSupport import start_pagent [as 别名]
class TestInstrumentAgentWithTrhph(TrhphTestCase, IonIntegrationTestCase):
"""
R2 instrument agent tests with the TRHPH driver.
"""
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)
def addCleanup(self, f):
IonIntegrationTestCase.addCleanup(self, f)
def tearDown(self):
try:
IonIntegrationTestCase.tearDown(self)
finally:
TrhphTestCase.tearDown(self)
def _start_pagent(self):
"""
Construct and start the port agent.
"""
port = self._support.start_pagent()
# Configure driver to use port agent port number.
DVR_CONFIG['comms_config'] = {
'addr' : 'localhost',
'port' : port
}
def _start_data_subscribers(self):
#.........这里部分代码省略.........