本文整理汇总了Python中pyon.agent.agent.ResourceAgentClient.ping_agent方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceAgentClient.ping_agent方法的具体用法?Python ResourceAgentClient.ping_agent怎么用?Python ResourceAgentClient.ping_agent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.agent.agent.ResourceAgentClient
的用法示例。
在下文中一共展示了ResourceAgentClient.ping_agent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ping_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
def ping_agent(self, resource_id=''):
"""Ping the agent.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.ping_agent(resource_id=resource_id)
raise BadRequest("Not implemented for resource type %s" % res_type)
示例2: ping_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
def ping_agent(self, resource_id=''):
"""Ping the agent.
@param resource_id The id of the resource agennt.
@retval A str containing a string representation of the agent
and a timestamp.
@param resource_id str
@retval result str
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.ping_agent(resource_id=resource_id)
raise BadRequest("Not implemented for resource type %s" % res_type)
示例3: TestRemoteEndpoint
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
svc_name='resource_registry',
command='delete',
args=[obj_id],
kwargs='',
command_id = str(uuid.uuid4()))
self._terrestrial_client.enqueue(cmd)
# Wait for command request to be acked.
# Wait for response to arrive.
self._cmd_tx_evt.get(timeout=CFG.endpoint.receive.timeout)
self._done_evt.get(timeout=CFG.endpoint.receive.timeout)
# Returns nothing.
# Publish a telemetry unavailable event.
# This will cause the endpoint clients to disconnect and go to sleep.
self.on_link_down()
gevent.sleep(1)
def test_resource_commands(self):
"""
test_resource_commands
Test that real resource commands are handled by the remote endpoint.
"""
# Start the IA and check it's out there and behaving.
self.start_agent()
state = self._ia_client.get_agent_state()
log.debug('Agent state is: %s', state)
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
retval = self._ia_client.ping_agent()
log.debug('Agent ping is: %s', str(retval))
self.assertIn('ping from InstrumentAgent', retval)
# Publish a telemetry available event.
# This will cause the endpoint clients to wake up and connect.
self.on_link_up()
# Wait for the link to be up.
# The remote side does not publish public telemetry events
# so we can't wait for that.
gevent.sleep(1)
# Send commands one at a time.
# Reset queues and events.
self._no_requests = 1
self._done_evt = AsyncResult()
self._cmd_tx_evt = AsyncResult()
self._requests_sent = {}
self._results_recv = {}
# Get agent state via remote endpoint.
cmd = IonObject('RemoteCommand',
resource_id=IA_RESOURCE_ID,
svc_name='',
command='get_agent_state',
args=[],
kwargs={},
command_id = str(uuid.uuid4()))
self._terrestrial_client.enqueue(cmd)
# Wait for command request to be acked.
# Wait for response to arrive.
示例4: TestAgentPersistence
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
"""
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)
self._ia_client = None
###############################################################################
# Tests.
###############################################################################
def test_agent_config_persistence(self):
"""
test_agent_config_persistence
Test that agent parameter configuration is persisted between running
instances.
"""
# Start the agent.
self._start_agent()
# 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)
# Confirm the default agent parameters.
#{'streams': {'raw': ['quality_flag', 'ingestion_timestamp', 'port_timestamp', 'raw', 'lat', 'driver_timestamp', 'preferred_timestamp', 'lon', 'internal_timestamp', 'time'], 'parsed': ['quality_flag', 'ingestion_timestamp', 'port_timestamp', 'pressure', 'lat', 'driver_timestamp', 'conductivity', 'preferred_timestamp', 'temp', 'density', 'salinity', 'lon', 'internal_timestamp', 'time']}}
retval = self._ia_client.get_agent(['streams'])['streams']
self.assertIn('raw', retval.keys())
self.assertIn('parsed', retval.keys())
#{'pubrate': {'raw': 0, 'parsed': 0}}
retval = self._ia_client.get_agent(['pubrate'])['pubrate']
self.assertIn('raw', retval.keys())
self.assertIn('parsed', retval.keys())
self.assertEqual(retval['raw'], 2)
self.assertEqual(retval['parsed'], 2)
#{'alerts': []}
retval = self._ia_client.get_agent(['alerts'])['alerts']
self.assertEqual(retval, [])
# Define a few new parameters and set them.
# Confirm they are set.
alert_def_1 = {
'name' : 'current_warning_interval',
'stream_name' : 'parsed',
'description' : 'Current is below normal range.',
'alert_type' : StreamAlertType.WARNING,
'aggregate_type' : AggregateStatusType.AGGREGATE_DATA,
'value_id' : 'temp',
'lower_bound' : None,
'lower_rel_op' : None,
'upper_bound' : 10.0,
'upper_rel_op' : '<',
示例5: Test2CAA
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
# Restart remote side and publish remote link up.
self._start_remote()
self.remote_link_up()
# Block for transmission and result events.
self._done_cmd_tx_evt.get(timeout=CFG.endpoint.receive.timeout)
self._done_cmd_evt.get(timeout=CFG.endpoint.receive.timeout)
# Publish link down events.
self.terrestrial_link_down()
self.remote_link_down()
self._done_telem_evt.get(timeout=CFG.endpoint.receive.timeout)
self.assertItemsEqual(self._requests_sent.keys(),
self._results_recv.keys())
def test_resource_commands(self):
"""
test_resource_commands
"""
# Set up to verify the two commands queued.
self._no_requests = 2
self._no_telem_evts = 2
self._no_cmd_tx_evts = self._no_requests
self._no_queue_mod_evts = self._no_requests
# Use IA client to verify IA.
state = self._ia_client.get_agent_state()
log.debug('Agent state is: %s', state)
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
retval = self._ia_client.ping_agent()
log.debug('Agent ping is: %s', str(retval))
self.assertIn('ping from InstrumentAgent', retval)
# Create and enqueue commands.
state_cmd = IonObject('RemoteCommand',
resource_id=IA_RESOURCE_ID,
svc_name='',
command='get_agent_state',
args=[],
kwargs={})
state_cmd = self.te_client.enqueue_command(state_cmd)
self._requests_sent[state_cmd.command_id] = state_cmd
ping_cmd = IonObject('RemoteCommand',
resource_id=IA_RESOURCE_ID,
svc_name='',
command='ping_agent',
args=[],
kwargs={})
ping_cmd = self.te_client.enqueue_command(ping_cmd)
self._requests_sent[ping_cmd.command_id] = ping_cmd
# Block on queue mod events.
self._done_queue_mod_evt.get(timeout=CFG.endpoint.receive.timeout)
# Publish link up events.
self.terrestrial_link_up()
self.remote_link_up()
# Block on command transmissions and results.
self._done_cmd_tx_evt.get(timeout=CFG.endpoint.receive.timeout)
self._done_cmd_evt.get(timeout=CFG.endpoint.receive.timeout)
示例6: TestOmsLaunch
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
# now that most of the topology information is there, add the
# PlatformAgentInstance elements
self._set_platform_agent_instances()
base_platform_config = self.platform_configs[base_platform_id]
log.info("base_platform_id = %r", base_platform_id)
log.info("topology = %s", str(self.topology))
#-------------------------------
# Launch Base Platform AgentInstance, connect to the resource agent client
#-------------------------------
agent_instance_id = base_platform_objs['agent_instance_id']
pid = self.imsclient.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
instance_obj = self.imsclient.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.processdispatchclient.read_process,
instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
agent_instance_obj= self.imsclient.read_instrument_agent_instance(agent_instance_id)
log.debug('test_oms_create_and_launch: Platform agent instance obj: %s', str(agent_instance_obj))
# Start a resource agent client to talk with the instrument agent.
self._pa_client = ResourceAgentClient('paclient', name=agent_instance_obj.agent_process_id, process=FakeProcess())
log.debug(" test_oms_create_and_launch:: got pa client %s", str(self._pa_client))
log.debug("base_platform_config =\n%s", base_platform_config)
# ping_agent can be issued before INITIALIZE
retval = self._pa_client.ping_agent(timeout=TIMEOUT)
log.debug( 'Base Platform ping_agent = %s', str(retval) )
# issue INITIALIZE command to the base platform, which will launch the
# creation of the whole platform hierarchy rooted at base_platform_config['platform_id']
# cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE, kwargs=dict(plat_config=base_platform_config))
cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform INITIALIZE = %s', str(retval) )
# GO_ACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_ACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_ACTIVE = %s', str(retval) )
# RUN: this command includes the launch of the resource monitoring greenlets
cmd = AgentCommand(command=PlatformAgentEvent.RUN)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform RUN = %s', str(retval) )
# START_EVENT_DISPATCH
kwargs = dict(params="TODO set params")
cmd = AgentCommand(command=PlatformAgentEvent.START_EVENT_DISPATCH, kwargs=kwargs)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
self.assertTrue(retval.result is not None)
# wait for data sample
# just wait for at least one -- see consume_data above
log.info("waiting for reception of a data sample...")
self._async_data_result.get(timeout=DATA_TIMEOUT)
self.assertTrue(len(self._samples_received) >= 1)
log.info("waiting a bit more for reception of more data samples...")
sleep(10)
log.info("Got data samples: %d", len(self._samples_received))
# wait for event
# just wait for at least one event -- see consume_event above
log.info("waiting for reception of an event...")
self._async_event_result.get(timeout=EVENT_TIMEOUT)
log.info("Received events: %s", len(self._events_received))
# STOP_EVENT_DISPATCH
cmd = AgentCommand(command=PlatformAgentEvent.STOP_EVENT_DISPATCH)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
self.assertTrue(retval.result is not None)
# GO_INACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_INACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_INACTIVE = %s', str(retval) )
# RESET: Resets the base platform agent, which includes termination of
# its sub-platforms processes:
cmd = AgentCommand(command=PlatformAgentEvent.RESET)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform RESET = %s', str(retval) )
#-------------------------------
# Stop Base Platform AgentInstance
#-------------------------------
self.imsclient.stop_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
示例7: TestAgentCommsAlerts
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
"""
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)
self._ia_client = None
###############################################################################
# Tests.
###############################################################################
def test_lost_connection_alert(self):
"""
test_lost_connection_alert
Verify that agents detect lost connection state and issue alert.
"""
self._event_count = 3
self._start_agent()
# 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)
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': [],
示例8: TestVel3d
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
subscriber.stop()
###############################################################################
# tcp helpers.
###############################################################################
def _start_tcp_client(self, retval):
host = retval.result['ip_address']
port = retval.result['port']
tcp_client = TcpClient(host, port)
return tcp_client
###############################################################################
# Tests.
###############################################################################
@unittest.skip('Test should be run manually only.')
def test_initialize(self):
"""
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)
示例9: BaseIntTestPlatform
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
"platform_id=%r: Exception in IMS.stop_platform_agent_instance with "
"platform_agent_instance_id = %r. Perhaps already dead.",
p_obj.platform_id, p_obj.platform_agent_instance_id)
#################################################################
# misc convenience methods
#################################################################
def _create_resource_agent_client(self, resource_id):
client = ResourceAgentClient(resource_id, process=FakeProcess())
return client
def _get_state(self):
state = self._pa_client.get_agent_state()
return state
def _assert_state(self, state):
self.assertEquals(self._get_state(), state)
def _execute_agent(self, cmd):
log.info("_execute_agent: cmd=%r kwargs=%r ...", cmd.command, cmd.kwargs)
time_start = time.time()
#retval = self._pa_client.execute_agent(cmd, timeout=timeout)
retval = self._pa_client.execute_agent(cmd)
elapsed_time = time.time() - time_start
log.info("_execute_agent: cmd=%r elapsed_time=%s, retval = %s",
cmd.command, elapsed_time, str(retval))
return retval
#################################################################
# commands that concrete tests can call
#################################################################
def _ping_agent(self):
retval = self._pa_client.ping_agent()
self.assertIsInstance(retval, str)
def _ping_resource(self):
cmd = AgentCommand(command=PlatformAgentEvent.PING_RESOURCE)
if self._get_state() == PlatformAgentState.UNINITIALIZED:
# should get ServerError: "Command not handled in current state"
with self.assertRaises(ServerError):
self._pa_client.execute_agent(cmd)
else:
# In all other states the command should be accepted:
retval = self._execute_agent(cmd)
self.assertEquals("PONG", retval.result)
def _get_metadata(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_METADATA)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_METADATA = %s", md)
def _get_ports(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_PORTS)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_PORTS = %s", md)
def _initialize(self):
self._assert_state(PlatformAgentState.UNINITIALIZED)
示例10: TestPlatformAgent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
Stop the data subscribers on cleanup.
"""
for sub in self._data_subscribers:
if hasattr(sub, "subscription_id"):
try:
self._pubsub_client.deactivate_subscription(sub.subscription_id)
except:
pass
self._pubsub_client.delete_subscription(sub.subscription_id)
sub.stop()
def _get_state(self):
state = self._pa_client.get_agent_state()
return state
def _assert_state(self, state):
self.assertEquals(self._get_state(), state)
# def _execute_agent(self, cmd, timeout=TIMEOUT):
def _execute_agent(self, cmd):
log.info("_execute_agent: cmd=%r kwargs=%r ...", cmd.command, cmd.kwargs)
time_start = time.time()
# retval = self._pa_client.execute_agent(cmd, timeout=timeout)
retval = self._pa_client.execute_agent(cmd)
elapsed_time = time.time() - time_start
log.info("_execute_agent: cmd=%r elapsed_time=%s, retval = %s", cmd.command, elapsed_time, str(retval))
return retval
def _reset(self):
cmd = AgentCommand(command=PlatformAgentEvent.RESET)
retval = self._execute_agent(cmd)
self._assert_state(PlatformAgentState.UNINITIALIZED)
def _ping_agent(self):
retval = self._pa_client.ping_agent()
self.assertIsInstance(retval, str)
def _ping_resource(self):
cmd = AgentCommand(command=PlatformAgentEvent.PING_RESOURCE)
if self._get_state() == PlatformAgentState.UNINITIALIZED:
# should get ServerError: "Command not handled in current state"
with self.assertRaises(ServerError):
# self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
self._pa_client.execute_agent(cmd)
else:
# In all other states the command should be accepted:
retval = self._execute_agent(cmd)
self.assertEquals("PONG", retval.result)
def _get_metadata(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_METADATA)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_METADATA = %s", md)
def _get_ports(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_PORTS)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_PORTS = %s", md)
def _set_up_port(self):
示例11: TestPlatformAgent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
for sub in self._event_subscribers:
if hasattr(sub, "subscription_id"):
try:
self.pubsubcli.deactivate_subscription(sub.subscription_id)
except:
pass
self.pubsubcli.delete_subscription(sub.subscription_id)
sub.stop()
finally:
self._event_subscribers = []
def _get_state(self):
state = self._pa_client.get_agent_state()
return state
def _assert_state(self, state):
self.assertEquals(self._get_state(), state)
# def _execute_agent(self, cmd, timeout=TIMEOUT):
def _execute_agent(self, cmd):
log.info("_execute_agent: cmd=%r kwargs=%r ...", cmd.command, cmd.kwargs)
time_start = time.time()
# retval = self._pa_client.execute_agent(cmd, timeout=timeout)
retval = self._pa_client.execute_agent(cmd)
elapsed_time = time.time() - time_start
log.info("_execute_agent: cmd=%r elapsed_time=%s, retval = %s", cmd.command, elapsed_time, str(retval))
return retval
def _reset(self):
cmd = AgentCommand(command=PlatformAgentEvent.RESET)
retval = self._execute_agent(cmd)
self._assert_state(PlatformAgentState.UNINITIALIZED)
def _ping_agent(self):
retval = self._pa_client.ping_agent()
self.assertIsInstance(retval, str)
def _ping_resource(self):
cmd = AgentCommand(command=PlatformAgentEvent.PING_RESOURCE)
if self._get_state() == PlatformAgentState.UNINITIALIZED:
# should get ServerError: "Command not handled in current state"
with self.assertRaises(ServerError):
# self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
self._pa_client.execute_agent(cmd)
else:
# In all other states the command should be accepted:
retval = self._execute_agent(cmd)
self.assertEquals("PONG", retval.result)
def _get_metadata(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_METADATA)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_METADATA = %s", md)
def _get_ports(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_PORTS)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_PORTS = %s", md)
def _connect_instrument(self):
示例12: TestPlatformLaunch
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
agent_instance_id = self.IMS.create_platform_agent_instance(
platform_agent_instance = agent_instance_obj,
platform_agent_id = agent_id,
platform_device_id = self.device_id)
stream_id = stream_ids[0]
self._start_data_subscriber(agent_instance_id, stream_id)
log.debug("about to call imsclient.start_platform_agent_instance with id=%s", agent_instance_id)
pid = self.IMS.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
instance_obj = self.IMS.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.PDC.read_process,
instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
agent_instance_obj= self.IMS.read_instrument_agent_instance(agent_instance_id)
log.debug('Platform agent instance obj')
# Start a resource agent client to talk with the instrument agent.
self._pa_client = ResourceAgentClient('paclient',
name=agent_instance_obj.agent_process_id,
process=FakeProcess())
log.debug("got platform agent client %s", str(self._pa_client))
# ping_agent can be issued before INITIALIZE
retval = self._pa_client.ping_agent(timeout=TIMEOUT)
log.debug('Base Platform ping_agent = %s', str(retval) )
cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform INITIALIZE = %s', str(retval) )
# GO_ACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_ACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_ACTIVE = %s', str(retval) )
# RUN:
cmd = AgentCommand(command=PlatformAgentEvent.RUN)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform RUN = %s', str(retval) )
# START_MONITORING:
cmd = AgentCommand(command=PlatformAgentEvent.START_MONITORING)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform START_MONITORING = %s', str(retval) )
# wait for data sample
# just wait for at least one -- see consume_data above
log.info("waiting for reception of a data sample...")
self._async_data_result.get(timeout=DATA_TIMEOUT)
self.assertTrue(len(self._samples_received) >= 1)
log.info("waiting a bit more for reception of more data samples...")
sleep(15)
log.info("Got data samples: %d", len(self._samples_received))
# wait for event
# just wait for at least one event -- see consume_event above
log.info("waiting for reception of an event...")
self._async_event_result.get(timeout=EVENT_TIMEOUT)
log.info("Received events: %s", len(self._events_received))
#get the extended platfrom which wil include platform aggreate status fields
# extended_platform = self.IMS.get_platform_device_extension(self.device_id)
# log.debug( 'test_single_platform extended_platform: %s', str(extended_platform) )
# log.debug( 'test_single_platform power_status_roll_up: %s', str(extended_platform.computed.power_status_roll_up.value) )
# log.debug( 'test_single_platform comms_status_roll_up: %s', str(extended_platform.computed.communications_status_roll_up.value) )
# STOP_MONITORING:
cmd = AgentCommand(command=PlatformAgentEvent.STOP_MONITORING)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform STOP_MONITORING = %s', str(retval) )
# GO_INACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_INACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_INACTIVE = %s', str(retval) )
# RESET: Resets the base platform agent, which includes termination of
# its sub-platforms processes:
cmd = AgentCommand(command=PlatformAgentEvent.RESET)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform RESET = %s', str(retval) )
#-------------------------------
# Stop Base Platform AgentInstance
#-------------------------------
self.IMS.stop_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
示例13: test_xxx
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
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
log.info("create FakePuckReader")
puck_reader = FakePuckReader()
log.info("read_puck()")
puck_data = puck_reader.read_puck(DEV_ADDR, DEV_PORT, DEV_SERIAL_LINE)
driver_config = {
'dvr_mod' : puck_data['dvr_mod'],
'dvr_cls' : puck_data['dvr_cls'],
'workdir' : WORK_DIR,
'process_type' : PROCESS_TYPE,
'comms_config' : {
'addr' : host,
'port' : port
}
}
agent_config = {
'driver_config' : driver_config,
'stream_config' : stream_config,
'agent' : {'resource_id': resource_id},
'test_mode' : True
}
log.debug("Starting instrument agent.")
ia_pid = self.container_client.spawn_process(
name=IA_NAME,
module=IA_MOD,
cls=IA_CLS,
config=agent_config)
#self.addCleanup(self._verify_agent_reset)
ia_client = ResourceAgentClient(resource_id, process=FakeProcess())
log.info('Got ia client %s.', str(ia_client))
# We start in uninitialized state.
# In this state there is no driver process.
state = ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
# Ping the agent.
retval = ia_client.ping_agent()
log.info(retval)
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = ia_client.execute_agent(cmd)
state = ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
retval = ia_client.execute_agent(cmd)
state = ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.IDLE)
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
retval = ia_client.execute_agent(cmd)
state = ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
cmd = AgentCommand(command=SBE37ProtocolEvent.ACQUIRE_SAMPLE)
retval = ia_client.execute_resource(cmd)
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = ia_client.execute_agent(cmd)
state = ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
示例14: BaseIntTestPlatform
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
self._ia_client = ResourceAgentClient('paclient',
name=agent_instance_obj.agent_process_id,
process=FakeProcess())
log.debug("got instrument agent client %s", str(self._ia_client))
def _stop_instrument(self, agent_instance_id):
self.IMS.stop_instrument_agent_instance(instrument_agent_instance_id=agent_instance_id)
#################################################################
# misc convenience methods
#################################################################
def _get_state(self):
state = self._pa_client.get_agent_state()
return state
def _assert_state(self, state):
self.assertEquals(self._get_state(), state)
def _execute_agent(self, cmd):
log.info("_execute_agent: cmd=%r kwargs=%r ...", cmd.command, cmd.kwargs)
time_start = time.time()
#retval = self._pa_client.execute_agent(cmd, timeout=timeout)
retval = self._pa_client.execute_agent(cmd)
elapsed_time = time.time() - time_start
log.info("_execute_agent: cmd=%r elapsed_time=%s, retval = %s",
cmd.command, elapsed_time, str(retval))
return retval
#################################################################
# commands that concrete tests can call
#################################################################
def _ping_agent(self):
retval = self._pa_client.ping_agent()
self.assertIsInstance(retval, str)
def _ping_resource(self):
cmd = AgentCommand(command=PlatformAgentEvent.PING_RESOURCE)
if self._get_state() == PlatformAgentState.UNINITIALIZED:
# should get ServerError: "Command not handled in current state"
with self.assertRaises(ServerError):
#self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
self._pa_client.execute_agent(cmd)
else:
# In all other states the command should be accepted:
retval = self._execute_agent(cmd)
self.assertEquals("PONG", retval.result)
def _get_metadata(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_METADATA)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_METADATA = %s", md)
def _get_ports(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_PORTS)
retval = self._execute_agent(cmd)
md = retval.result
self.assertIsInstance(md, dict)
# TODO verify possible subset of required entries in the dict.
log.info("GET_PORTS = %s", md)
def _initialize(self):
示例15: TestAgentPersistence
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import ping_agent [as 别名]
#.........这里部分代码省略.........
"""
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)
self._ia_client = None
###############################################################################
# Tests.
###############################################################################
def test_agent_config_persistence(self):
"""
test_agent_config_persistence
Test that agent parameter configuration is persisted between running
instances.
"""
# Start the agent.
self._start_agent()
# 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)
# Confirm the default agent parameters.
#{'streams': {'raw': ['quality_flag', 'ingestion_timestamp', 'port_timestamp', 'raw', 'lat', 'driver_timestamp', 'preferred_timestamp', 'lon', 'internal_timestamp', 'time'], 'parsed': ['quality_flag', 'ingestion_timestamp', 'port_timestamp', 'pressure', 'lat', 'driver_timestamp', 'conductivity', 'preferred_timestamp', 'temp', 'density', 'salinity', 'lon', 'internal_timestamp', 'time']}}
retval = self._ia_client.get_agent(['streams'])['streams']
self.assertIn('raw', retval.keys())
self.assertIn('parsed', retval.keys())
#{'pubrate': {'raw': 0, 'parsed': 0}}
retval = self._ia_client.get_agent(['pubrate'])['pubrate']
self.assertIn('raw', retval.keys())
self.assertIn('parsed', retval.keys())
self.assertEqual(retval['raw'], 0)
self.assertEqual(retval['parsed'], 0)
#{'alerts': []}
retval = self._ia_client.get_agent(['alerts'])['alerts']
self.assertEqual(retval, [])
# Define a few new parameters and set them.
# Confirm they are set.
alert_def_1 = {
'name' : 'current_warning_interval',
'stream_name' : 'parsed',
'message' : 'Current is below normal range.',
'alert_type' : StreamAlertType.WARNING,
'aggregate_type' : AggregateStatusType.AGGREGATE_DATA,
'value_id' : 'temp',
'lower_bound' : None,
'lower_rel_op' : None,
'upper_bound' : 10.0,
'upper_rel_op' : '<',