本文整理汇总了Python中pyon.agent.agent.ResourceAgentClient.execute_resource方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceAgentClient.execute_resource方法的具体用法?Python ResourceAgentClient.execute_resource怎么用?Python ResourceAgentClient.execute_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.agent.agent.ResourceAgentClient
的用法示例。
在下文中一共展示了ResourceAgentClient.execute_resource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recover_data
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def recover_data(self, agent_instance_id, resource_id):
res_obj = self.rr.read(resource_id)
if res_obj.type_ != RT.InstrumentDevice:
log.warn("Ignoring resource because it is not an instrument: %s - %s", res_obj.name, res_obj.type_)
self._recover_data_status['ignored'].append("%s (%s)" % (res_obj.name, res_obj.type_))
return
self.recover_start = self.CFG.get("recover_start", None)
self.recover_end = self.CFG.get("recover_end", None)
if self.recover_end is None:
raise BadRequest("Missing recover_end parameter")
if self.recover_start is None:
raise BadRequest("Missing recover_start parameter")
try:
ia_client = ResourceAgentClient(resource_id, process=self)
log.info('Got ia client %s.', str(ia_client))
ia_client.execute_resource(command=AgentCommand(command=DriverEvent.GAP_RECOVERY, args=[self.recover_start, self.recover_end]))
self._recover_data_status['success'].append(res_obj.name)
except Exception as e:
log.warn("Failed to start recovery process for %s", res_obj.name)
log.warn("Exception: %s", e)
self._recover_data_status['fail'].append("%s (%s)" % (res_obj.name, e))
示例2: test_instrument_simple
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def test_instrument_simple(self):
instrument_model_id = self.create_instrument_model()
instrument_agent_id = self.create_instrument_agent(instrument_model_id)
instrument_device_id = self.create_instrument_device(instrument_model_id)
instrument_agent_instance_id = self.create_instrument_agent_instance(instrument_agent_id, instrument_device_id)
raw_dp_id, parsed_dp_id = self.create_instrument_data_products(instrument_device_id)
self.start_instrument_agent_instance(instrument_agent_instance_id)
agent_process_id = self.poll_instrument_agent_instance(instrument_agent_instance_id, instrument_device_id)
agent_client = ResourceAgentClient(instrument_device_id,
to_name=agent_process_id,
process=FakeProcess())
self.agent_state_transition(agent_client, ResourceAgentEvent.INITIALIZE, ResourceAgentState.INACTIVE)
self.agent_state_transition(agent_client, ResourceAgentEvent.GO_ACTIVE, ResourceAgentState.IDLE)
self.agent_state_transition(agent_client, ResourceAgentEvent.RUN, ResourceAgentState.COMMAND)
dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(parsed_dp_id)
for i in xrange(10):
monitor = DatasetMonitor(dataset_id=dataset_id)
agent_client.execute_resource(AgentCommand(command=SBE37ProtocolEvent.ACQUIRE_SAMPLE))
if not monitor.wait():
raise AssertionError('Failed on the %ith granule' % i)
monitor.stop()
rdt = RecordDictionaryTool.load_from_granule(self.data_retriever.retrieve(dataset_id))
self.assertEquals(len(rdt), 10)
示例3: start_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def start_agent(self, agent_instance_id, resource_id):
if not agent_instance_id or not resource_id:
log.warn("Could not %s agent %s for device %s", self.op, agent_instance_id, resource_id)
return
res_obj = self.rr.read(resource_id)
log.info('Starting agent...')
if res_obj.type_ == RT.ExternalDatasetAgentInstance or res_obj == RT.ExternalDataset:
dams = DataAcquisitionManagementServiceProcessClient(process=self)
dams.start_external_dataset_agent_instance(agent_instance_id)
elif res_obj.type_ == RT.InstrumentDevice:
ims = InstrumentManagementServiceClient()
ims.start_instrument_agent_instance(agent_instance_id)
elif res_obj.type_ == RT.PlatformDevice:
ims = InstrumentManagementServiceClient()
ims.start_platform_agent_instance(agent_instance_id)
else:
BadRequest("Attempt to start unsupported agent type: %s", res_obj.type_)
log.info('Agent started!')
activate = self.CFG.get("activate", True)
if activate:
log.info('Activating agent...')
client = ResourceAgentClient(resource_id, process=self)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('Agent active!')
示例4: start_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def start_agent(self, agent_instance_id, resource_id):
if not agent_instance_id or not resource_id:
log.warn("Could not op=%s agent %s for device %s", self.op, agent_instance_id, resource_id)
return
res_obj = self.rr.read(resource_id)
ai_obj = self.rr.read(agent_instance_id)
try:
client = ResourceAgentClient(resource_id, process=self)
if self.force:
log.warn("Agent for resource %s seems running - continuing", resource_id)
if self.autoclean:
self.cleanup_agent(agent_instance_id, resource_id)
else:
log.warn("Agent for resource %s seems running", resource_id)
return
except NotFound:
pass # This is expected
log.info('Starting agent...')
if ai_obj.type_ == RT.ExternalDatasetAgentInstance:
dams = DataAcquisitionManagementServiceProcessClient(process=self)
dams.start_external_dataset_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
timeout=self.timeout)
elif ai_obj.type_ == RT.InstrumentAgentInstance:
ims = InstrumentManagementServiceProcessClient(process=self)
ims.start_instrument_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
timeout=self.timeout)
elif ai_obj.type_ == RT.PlatformAgentInstance:
ims = InstrumentManagementServiceProcessClient(process=self)
ims.start_platform_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
timeout=self.timeout)
else:
BadRequest("Attempt to start unsupported agent type: %s", ai_obj.type_)
log.info('Agent started!')
activate = self.CFG.get("activate", True)
if activate:
log.info('Activating agent...')
client = ResourceAgentClient(resource_id, process=self)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE),
headers=self._get_system_actor_headers(), timeout=self.timeout)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE),
headers=self._get_system_actor_headers(), timeout=self.timeout)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN),
headers=self._get_system_actor_headers(), timeout=self.timeout)
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE),
headers=self._get_system_actor_headers(), timeout=self.timeout)
log.info('Agent in auto-sample mode!')
示例5: _start_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def _start_agent(self, eda_instance_id, resource_id):
log.info('Starting agent...')
dams = DataAcquisitionManagementServiceProcessClient(process=self)
dams.start_external_dataset_agent_instance(eda_instance_id)
log.info('Agent started!')
activate = self.CFG.get("activate", True)
if activate:
log.info('Activating agent...')
client = ResourceAgentClient(resource_id, process=self)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('Agent active!')
示例6: execute_resource
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def execute_resource(self, resource_id='', command=None):
"""Execute command on the resource represented by agent.
@param resource_id The id of the resource agennt.
@param command An AgentCommand containing the command.
@retval result An AgentCommandResult containing the result.
@throws BadRequest if the command was malformed.
@throws NotFound if the command is not available in current state.
@throws ResourceError if the resource produced an error during execution.
@param resource_id str
@param command AgentCommand
@retval result AgentCommandResult
@throws BadRequest if the command was malformed.
@throws NotFound if the command is not implemented in the agent.
@throws ResourceError if the resource produced an error.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.execute_resource(resource_id=resource_id, command=command)
cmd_res = None
res_interface = self._get_type_interface(res_type)
target = get_safe(res_interface, "commands.%s.execute" % command.command, None)
if target:
res = self._call_execute(target, resource_id, res_type, command.args, command.kwargs)
cmd_res = AgentCommandResult(command_id=command.command_id,
command=command.command,
ts_execute=get_ion_ts(),
status=0)
else:
log.warn("execute_resource(): command %s not defined", command.command)
return cmd_res
示例7: on_start
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def on_start(self):
rr = self.container.resource_registry
name = self.CFG.get("dataset")
if name: # We are looking for an external dataset!
log.trace("Looking for an external dataset with name %s", name)
objects,_ = rr.find_resources(RT.ExternalDataset)
filtered_objs = [obj for obj in objects if obj.name == name]
if (filtered_objs) == []:
raise ConfigNotFound("No appropriate ExternalDataset objects loaded")
external_dataset = filtered_objs[0]
instance_id = rr.read_object(subject=external_dataset._id,
predicate=PRED.hasAgentInstance,
object_type=RT.ExternalDatasetAgentInstance,
id_only=True)
dams = get_service_registry().services['data_acquisition_management'].client(process=self)
dams.start_external_dataset_agent_instance(instance_id)
client = ResourceAgentClient(external_dataset._id, process=FakeProcess())
else:
name = self.CFG.get("instrument")
if name: # We are looking for an instrument device!
log.trace("Looking for an instrument device with name %s", name)
objects,_ = rr.find_resources(RT.InstrumentDevice)
filtered_objs = [obj for obj in objects if obj.name == name]
if (filtered_objs) == []:
raise ConfigNotFound("No appropriate InstrumentDevice objects loaded")
instrument_device = filtered_objs[0]
log.trace("Found instrument device: %s", instrument_device)
instance_id = rr.read_object(subject=instrument_device._id,
predicate=PRED.hasAgentInstance,
object_type=RT.ExternalDatasetAgentInstance,
id_only=True)
dams = get_service_registry().services['data_acquisition_management'].client(process=self)
proc_id = dams.start_external_dataset_agent_instance(instance_id)
client = ResourceAgentClient(instrument_device._id, process=FakeProcess())
else:
raise ConfigNotFound("Could not find dataset or instrument_device value name")
log.info('Activating agent...')
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('Now reading: %s', name)
示例8: on_start
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def on_start(self):
name = self.CFG.get("dataset")
rr = self.container.resource_registry
objects,_ = rr.find_resources(RT.ExternalDataset)
filtered_objs = [obj for obj in objects if obj.name == name]
external_dataset = filtered_objs[0]
instance_id = rr.read_object(subject=external_dataset._id, predicate=PRED.hasAgentInstance, object_type=RT.ExternalDatasetAgentInstance, id_only=True)
dams = get_service_registry().services['data_acquisition_management'].client(process=self)
dams.start_external_dataset_agent_instance(instance_id)
# OLD METHOD of starting agent, now this code has been implemented and tested in DAMS
#obj,_ = rr.find_objects(subject=external_dataset._id, predicate=PRED.hasAgentInstance, object_type=RT.ExternalDatasetAgentInstance)
#agent_instance = obj[0]
#obj,_ = rr.find_objects(object_type=RT.ExternalDatasetAgent, predicate=PRED.hasAgentDefinition, subject=agent_instance._id)
#agent = obj[0]
#stream_definition_id = agent_instance.dataset_driver_config['dh_cfg']['stream_def']
#stream_definition = rr.read(stream_definition_id)
#data_producer_id = agent_instance.dataset_driver_config['dh_cfg']['data_producer_id']
#data_producer = rr.read(data_producer_id) #subject="", predicate="", object_type="", assoc="", id_only=False)
#data_product = rr.read_object(object_type=RT.DataProduct, predicate=PRED.hasOutputProduct, subject=external_dataset._id)
#ids,_ = rr.find_objects(data_product._id, PRED.hasStream, RT.Stream, id_only=True)
#stream_id = ids[0]
#route = pubsub.read_stream_route(stream_id)
#agent_instance.dataset_agent_config['driver_config']['dh_cfg']['stream_id'] = stream_id
#agent_instance.dataset_agent_config['driver_config']['stream_id'] = stream_id
#agent_instance.dataset_agent_config['driver_config']['dh_cfg']['stream_route'] = route
#
#log.info('launching agent process: %s.%s', agent.handler_module, agent.handler_class)
#self.container.spawn_process(name=agent_instance.name,
# module=agent.handler_module, cls=agent.handler_class,
# config=agent_instance.dataset_agent_config)
#
# should i wait for process (above) to start
# before launching client (below)?
#
log.info('activating agent...')
client = ResourceAgentClient(external_dataset._id, process=FakeProcess())
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('now reading external dataset: %s', name)
示例9: execute_resource
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
def execute_resource(self, resource_id='', command=None):
"""Execute command on the resource represented by agent.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.execute_resource(resource_id=resource_id, command=command)
cmd_res = None
res_interface = self._get_type_interface(res_type)
target = get_safe(res_interface, "commands.%s.execute" % command.command, None)
if target:
res = self._call_execute(target, resource_id, res_type, command.args, command.kwargs)
cmd_res = AgentCommandResult(command_id=command.command_id,
command=command.command,
ts_execute=get_ion_ts(),
status=0)
else:
log.warn("execute_resource(): command %s not defined", command.command)
return cmd_res
示例10: TestPreloadThenLoadDataset
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
class TestPreloadThenLoadDataset(IonIntegrationTestCase):
""" replicates the TestHypm_WPF_CTD test (same handler/parser/data file)
but uses the preload system to define the ExternalDataset and related resources,
then invokes services to perform the load
"""
def setUp(self):
# Start container
self._start_container()
self.container.start_rel_from_url('res/deploy/r2deploy.yml')
config = dict(op="load", scenario="BETA,NOSE", attachments="res/preload/r2_ioc/attachments")
self.container.spawn_process("Loader", "ion.processes.bootstrap.ion_loader", "IONLoader", config=config)
self.pubsub = PubsubManagementServiceClient()
self.dams = DataAcquisitionManagementServiceClient()
def find_object_by_name(self, name, resource_type):
objects,_ = self.container.resource_registry.find_resources(resource_type)
self.assertTrue(len(objects) >= 1)
# filtered_objs = [obj for obj in objects if obj.name == name]
filtered_objs = []
for obj in objects:
if obj.name==name:
filtered_objs.append(obj)
self.assertEquals(len(filtered_objs), 1, msg='Found %d objects with name %s'%(len(filtered_objs),name))
return filtered_objs[0]
def test_use_case(self):
# setUp() has already started the container and performed the preload
# self.assert_dataset_loaded('Test External CTD Dataset') # make sure we have the ExternalDataset resources
self.assert_dataset_loaded('Unit Test SMB37') # association changed -- now use device name
self.do_listen_for_incoming() # listen for any data being received from the dataset
self.do_read_dataset() # call services to load dataset
self.assert_data_received() # check that data was received as expected
self.do_shutdown()
def assert_dataset_loaded(self, name):
# self.external_dataset = self.find_object_by_name(name, RT.ExternalDataset)
self.device = self.find_object_by_name(name, RT.InstrumentDevice)
rr = self.container.resource_registry
obj,_ = rr.find_objects(subject=self.device._id, predicate=PRED.hasAgentInstance, object_type=RT.ExternalDatasetAgentInstance)
self.agent_instance = obj[0]
obj,_ = rr.find_objects(object_type=RT.ExternalDatasetAgent, predicate=PRED.hasAgentDefinition, subject=self.agent_instance._id)
self.agent = obj[0]
stream_definition_id = self.agent_instance.dataset_driver_config['dh_cfg']['stream_def'] if 'dh_cfg' in self.agent_instance.dataset_driver_config else self.agent_instance.dataset_driver_config['stream_def']
self.stream_definition = rr.read(stream_definition_id)
# data_producer_id = self.agent_instance.dataset_driver_config['dh_cfg']['data_producer_id'] if 'dh_cfg' in self.agent_instance.dataset_driver_config else self.agent_instance.dataset_driver_config['data_producer_id']
# self.data_producer = rr.read(data_producer_id) #subject="", predicate="", object_type="", assoc="", id_only=False)
# self.data_product = rr.read_object(object_type=RT.DataProduct, predicate=PRED.hasOutputProduct, subject=self.external_dataset._id)
self.data_product = rr.read_object(object_type=RT.DataProduct, predicate=PRED.hasOutputProduct, subject=self.device._id)
ids,_ = rr.find_objects(self.data_product._id, PRED.hasStream, RT.Stream, id_only=True)
self.stream_id = ids[0]
self.route = self.pubsub.read_stream_route(self.stream_id)
def do_listen_for_incoming(self):
subscription_id = self.pubsub.create_subscription('validator', data_product_ids=[self.data_product._id])
self.addCleanup(self.pubsub.delete_subscription, subscription_id)
self.granule_capture = []
self.granule_count = 0
def on_granule(msg, route, stream_id):
self.granule_count += 1
if self.granule_count<5:
self.granule_capture.append(msg)
validator = StandaloneStreamSubscriber('validator', callback=on_granule)
validator.start()
self.addCleanup(validator.stop)
self.pubsub.activate_subscription(subscription_id)
self.addCleanup(self.pubsub.deactivate_subscription, subscription_id)
self.dataset_modified = Event()
def cb2(*args, **kwargs):
self.dataset_modified.set()
# TODO: event isn't using the ExternalDataset, but a different ID for a Dataset
es = EventSubscriber(event_type=OT.DatasetModified, callback=cb2, origin=self.device._id)
es.start()
self.addCleanup(es.stop)
def do_read_dataset(self):
self.dams.start_external_dataset_agent_instance(self.agent_instance._id)
#
# should i wait for process (above) to start
# before launching client (below)?
#
self.client = ResourceAgentClient(self.device._id, process=FakeProcess())
self.client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
self.client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
self.client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
self.client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
def assert_data_received(self):
#let it go for up to 120 seconds, then stop the agent and reset it
if not self.dataset_modified.is_set():
self.dataset_modified.wait(30)
self.assertTrue(self.granule_count>2, msg='granule count = %d'%self.granule_count)
rdt = RecordDictionaryTool.load_from_granule(self.granule_capture[0])
self.assertAlmostEqual(0, rdt['oxygen'][0], delta=0.01)
#.........这里部分代码省略.........
示例11: RunInstrument
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
#.........这里部分代码省略.........
waiting = False
print "Input command: " + str(command)
if command == 'RESOURCE_AGENT_EVENT_GO_DIRECT_ACCESS':
cmd = AgentCommand(command = command,
kwargs={'session_type': DirectAccessTypes.telnet,
'session_timeout':600,
'inactivity_timeout':600})
waiting = True
else:
cmd = AgentCommand(command = command)
retval = self._ia_client.execute_agent(cmd)
print "Results of command: " + str(retval)
while waiting:
print "Waiting " + str(DA_WAIT_PERIOD) + " seconds for you to test direct access."
gevent.sleep(DA_WAIT_PERIOD)
still_waiting = prompt.text('Still waiting? (y/n)')
if still_waiting is 'n':
waiting = False
def send_driver_command(self, command):
"""
@brief Send a command to the instrument through the instrument agent.
First determine whether it's a get or set, which are handled separately.
"""
if command == DriverEvent.GET:
self._get_param()
elif command == DriverEvent.SET:
self._set_param()
else:
print "Input command: " + str(command)
cmd = AgentCommand(command = command)
retval = self._ia_client.execute_resource(cmd)
print "Results of command: " + str(retval)
def _get_param(self):
"""
@brief Get a single parameter from the instrument (will be updated to get
multiple later).
"""
_all_params = self._ia_client.get_resource('DRIVER_PARAMETER_ALL')
print "Parameters you can get are: " + str(_all_params)
_param_valid = False
while _param_valid is False:
_param = prompt.text('\nEnter a single parameter')
if _param in _all_params:
_param_valid = True
else:
print 'Invalid parameter: ' + _param
reply = self._ia_client.get_resource([_param])
print 'Reply is :' + str(reply)
def _set_param(self):
"""
@brief Set a single parameter
"""
_all_params = self._ia_client.get_resource('DRIVER_PARAMETER_ALL')
print "Parameters you can set are: " + str(_all_params)
_param_valid = False
while _param_valid is False:
_param = prompt.text('\nEnter a single parameter')
if _param in _all_params:
示例12: TestInstrumentAlerts
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
#.........这里部分代码省略.........
self.event_subscriber.start()
self.addCleanup(self.event_subscriber.stop)
#-------------------------------------------------------------------------------------
# Running the instrument....
#-------------------------------------------------------------------------------------
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
# Prevent this test from hanging indefinitely until
# OOIION-1313 is resolved
timeout_val = 90
with gevent.Timeout(timeout_val, Exception('Agent failed to initialize after %fs' % timeout_val)):
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
with gevent.Timeout(timeout_val, Exception('Agent failed to go active after %fs' % timeout_val)):
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GET_RESOURCE_STATE)
with gevent.Timeout(timeout_val, Exception('Agent failed to get resource after %fs' % timeout_val)):
retval = self._ia_client.execute_agent(cmd)
state = retval.result
log.debug("(L4-CI-SA-RQ-334): current state after sending go_active command %s", str(state))
self.assertTrue(state, 'DRIVER_STATE_COMMAND')
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
with gevent.Timeout(timeout_val, Exception('Agent failed to run after %fs' % timeout_val)):
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=SBE37ProtocolEvent.START_AUTOSAMPLE)
with gevent.Timeout(timeout_val, Exception('Agent failed to start autosample after %fs' % timeout_val)):
retval = self._ia_client.execute_resource(cmd)
got_bad_temp = [False, False, False, False]
got_late_data = False
got_temp_all_clear = [False, False, False, False]
runtime = 0
starttime = time.time()
caught_events = []
while (got_bad_temp[0] == False or
got_bad_temp[1] == False or
got_bad_temp[2] == False or
got_temp_all_clear[0] == False or
got_temp_all_clear[1] == False or
got_temp_all_clear[2] == False or
got_late_data == False) and runtime < 120:
a = self.catch_alert.get(timeout=180)
caught_events.append(a)
if a.name == 'temperature_warning_interval temp below 25':
if a.sub_type == 'WARNING' and \
a.values[0] > 25:
got_bad_temp[0] = True
log.error(str(a.values[0]) + " should be above 25")
elif a.sub_type == 'ALL_CLEAR':
got_temp_all_clear[0] = True
log.debug("25 ALL_CLEAR")
if a.name == 'temperature_warning_interval temp below 50':
if a.sub_type == 'WARNING' and \
a.values[0] > 50:
got_bad_temp[1] = True
log.error(str(a.values[0]) + " should be above 50")
elif a.sub_type == 'ALL_CLEAR':
got_temp_all_clear[1] = True
log.debug("50 ALL_CLEAR" )
if a.name == 'temperature_warning_interval temp below 75':
if a.sub_type == 'WARNING' and \
a.values[0] > 75:
got_bad_temp[2] = True
log.error(str(a.values[0]) + " should be above 75")
elif a.sub_type == 'ALL_CLEAR':
got_temp_all_clear[2] = True
log.debug("75 ALL_CLEAR")
if a.name == 'late_data_warning' and \
a.description == 'Expected data has not arrived.':
got_late_data = True
log.debug("late value")
runtime = time.time() - starttime
log.debug("caught_events: %s", [c.name for c in caught_events])
for c in caught_events:
self.assertIn(c.name, ['temperature_warning_interval temp below 25',
'temperature_warning_interval temp below 50',
'temperature_warning_interval temp below 75',
'late_data_warning'])
self.assertEqual(c.origin, instDevice_id)
self.assertEqual(c.type_, 'DeviceStatusAlertEvent')
self.assertEqual(c.origin_type, 'InstrumentDevice')
self.assertTrue(got_bad_temp)
#simply log the state of the late data flag and the simulator does not seem to be consistent.
log.debug("test_alerts late data alert flag: %s", got_late_data)
示例13: ExternalDatasetAgentTestBase
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
#.........这里部分代码省略.........
self.assertEqual(val, correct_val)
########################################
# Test functions
########################################
def test_acquire_data_while_streaming(self):
# Test instrument driver execute interface to start and stop streaming mode.
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.IDLE)
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
params = {
'POLLING_INTERVAL': 3
}
self._ia_client.set_resource(params)
self._finished_count = 1
cmd = AgentCommand(command=DriverEvent.START_AUTOSAMPLE)
self._ia_client.execute_resource(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.STREAMING)
config = get_safe(self.DVR_CONFIG, 'dh_cfg', {})
log.info('Send a constrained request for data: constraints = HIST_CONSTRAINTS_1')
config['stream_id'], config['stream_route'], _ = self.create_stream_and_logger(name='stream_id_for_historical_1')
config['constraints'] = self.HIST_CONSTRAINTS_1
cmd = AgentCommand(command=DriverEvent.ACQUIRE_SAMPLE, args=[config])
self._ia_client.execute_resource(cmd)
cmd = AgentCommand(command=DriverEvent.STOP_AUTOSAMPLE)
self._ia_client.execute_resource(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
finished = self._async_finished_result.get(timeout=120)
self.assertEqual(finished, self._finished_count)
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
def test_acquire_data(self):
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
self._ia_client.execute_agent(cmd)
示例14: TestAgentCommsAlerts
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
#.........这里部分代码省略.........
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
# Ping the driver proc.
retval = self._ia_client.ping_resource()
log.info(retval)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.IDLE)
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
# Confirm the persisted parameters.
retval = self._ia_client.get_agent(['alerts'])['alerts']
"""
{'origin': '123xyz', 'status': 1, '_id': 'da03b90d2e064b25bf51ed90b729e82e',
'description': 'The alert is cleared.', 'time_stamps': [],
'type_': 'DeviceStatusAlertEvent', 'valid_values': [],
'values': ['RESOURCE_AGENT_STATE_INACTIVE'], 'value_id': '',
'base_types': ['DeviceStatusEvent', 'DeviceEvent', 'Event'],
'stream_name': '', 'ts_created': '1366749987069', 'sub_type': 3,
'origin_type': 'InstrumentDevice', 'name': 'comms_warning'}
"""
# Acquire sample returns a string, not a particle. The particle
# is created by the data handler though.
cmd = AgentCommand(command=SBE37ProtocolEvent.ACQUIRE_SAMPLE)
retval = self._ia_client.execute_resource(cmd)
# Blow the port agent out from under the agent.
self._support.stop_pagent()
# Wait for a while, the supervisor is restarting the port agent.
gevent.sleep(5)
self._support.start_pagent()
timeout = gevent.Timeout(120)
timeout.start()
try:
while True:
state = self._ia_client.get_agent_state()
if state == ResourceAgentState.COMMAND:
timeout.cancel()
break
else:
gevent.sleep(2)
except Timeout as t:
self.fail('Could not reconnect to device.')
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
# Reset the agent. This causes the driver messaging to be stopped,
# the driver process to end and switches us back to uninitialized.
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
示例15: TestVel3d
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_resource [as 别名]
#.........这里部分代码省略.........
"""
test_initialize
Test agent initialize command. This causes creation of
driver process and transition to inactive.
"""
print '#### in test'
# We start in uninitialized state.
# In this state there is no driver process.
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
# Ping the agent.
retval = self._ia_client.ping_agent()
log.info(retval)
# Initialize the agent.
# The agent is spawned with a driver config, but you can pass one in
# optinally with the initialize command. This validates the driver
# config, launches a driver process and connects to it via messaging.
# If successful, we switch to the inactive state.
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
# Ping the driver proc.
retval = self._ia_client.ping_resource()
log.info(retval)
# Reset the agent. This causes the driver messaging to be stopped,
# the driver process to end and switches us back to uninitialized.
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
@unittest.skip('Test should be run manually only.')
def test_xx(self):
"""
"""
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
with self.assertRaises(Conflict):
res_state = self._ia_client.get_resource_state()
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
print '################################# mavs4 came up in state: ' + state
if state == ResourceAgentState.IDLE:
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
elif state == ResourceAgentState.STREAMING:
cmd = AgentCommand(command='DRIVER_EVENT_STOP_AUTOSAMPLE')
retval = self._ia_client.execute_resource(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
state = self._ia_client.get_agent_state()
print '################################# mavs4 now in state: ' + state
cmd = AgentCommand(command=ResourceAgentEvent.GO_DIRECT_ACCESS,
kwargs={'session_type': DirectAccessTypes.telnet,
'session_timeout':600,
'inactivity_timeout':600})
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.DIRECT_ACCESS)
state = self._ia_client.get_agent_state()
print '################################# mavs4 now in state: ' + state
tcp_client = self._start_tcp_client(retval)
self.assertTrue(tcp_client.start_telnet(token=retval.result['token']))
self.assertTrue(tcp_client.send_data('\r\r'))
gevent.sleep(180)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.DIRECT_ACCESS)
cmd = AgentCommand(command=ResourceAgentEvent.GO_COMMAND)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)