本文整理汇总了Python中interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient.get_instrument_device_extension方法的典型用法代码示例。如果您正苦于以下问题:Python InstrumentManagementServiceClient.get_instrument_device_extension方法的具体用法?Python InstrumentManagementServiceClient.get_instrument_device_extension怎么用?Python InstrumentManagementServiceClient.get_instrument_device_extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient
的用法示例。
在下文中一共展示了InstrumentManagementServiceClient.get_instrument_device_extension方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDriverEgg
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
stream_definition_id=raw_stream_def_id)
print 'new dp_id = %s' % str(data_product_id2)
self.damsclient.assign_data_product(input_resource_id=instDevice_id, data_product_id=data_product_id2)
self.dpclient.activate_data_product_persistence(data_product_id=data_product_id2)
# Retrieve the id of the OUTPUT stream from the out Data Product
stream_ids, _ = self.rrclient.find_objects(data_product_id2, PRED.hasStream, None, True)
print 'Data product streams2 = %s' % str(stream_ids)
# Retrieve the id of the OUTPUT stream from the out Data Product
dataset_ids, _ = self.rrclient.find_objects(data_product_id2, PRED.hasDataset, RT.Dataset, True)
print 'Data set for data_product_id2 = %s' % dataset_ids[0]
self.raw_dataset = dataset_ids[0]
# add start/stop for instrument agent
gevent.joinall([gevent.spawn(lambda:
self.imsclient.start_instrument_agent_instance(instrument_agent_instance_id=instAgentInstance_id))])
self.addCleanup(self.imsclient.stop_instrument_agent_instance,
instrument_agent_instance_id=instAgentInstance_id)
#wait for start
inst_agent_instance_obj = self.imsclient.read_instrument_agent_instance(instAgentInstance_id)
agent_process_id = ResourceAgentClient._get_agent_process_id(instDevice_id)
print "Agent process id is '%s'" % str(agent_process_id)
self.assertTrue(agent_process_id)
gate = ProcessStateGate(self.processdispatchclient.read_process,
agent_process_id,
ProcessStateEnum.RUNNING)
if not expect_launch:
self.assertFalse(gate.await(30), "The instance (%s) of bogus instrument agent spawned in 30 seconds ?!?" %
agent_process_id)
return
self.assertTrue(gate.await(30), "The instrument agent instance (%s) did not spawn in 30 seconds" %
agent_process_id)
print "Instrument Agent Instance successfully triggered ProcessStateGate as RUNNING"
#print 'Instrument agent instance obj: = %s' % str(inst_agent_instance_obj)
# Start a resource agent client to talk with the instrument agent.
self._ia_client = ResourceAgentClient(instDevice_id,
to_name=agent_process_id,
process=FakeProcess())
print "ResourceAgentClient created: %s" % str(self._ia_client)
print "Sending command=ResourceAgentEvent.INITIALIZE"
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
if not expect_command:
self.assertRaises(ServerError, self._ia_client.execute_agent, cmd)
return
retval = self._ia_client.execute_agent(cmd)
print "Result of INITIALIZE: %s" % str(retval)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GET_RESOURCE_STATE)
retval = self._ia_client.execute_agent(cmd)
state = retval.result
self.assertTrue(state, 'DRIVER_STATE_COMMAND')
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=SBE37ProtocolEvent.START_AUTOSAMPLE)
retval = self._ia_client.execute_resource(cmd)
# This gevent sleep is there to test the autosample time, which will show something different from default
# only if the instrument runs for over a minute
gevent.sleep(90)
extended_instrument = self.imsclient.get_instrument_device_extension(instrument_device_id=instDevice_id)
self.assertIsInstance(extended_instrument.computed.uptime, ComputedStringValue)
autosample_string = extended_instrument.computed.uptime.value
autosampling_time = int(autosample_string.split()[4])
self.assertTrue(autosampling_time > 0)
cmd = AgentCommand(command=SBE37ProtocolEvent.STOP_AUTOSAMPLE)
retval = self._ia_client.execute_resource(cmd)
print "Sending command=ResourceAgentEvent.RESET"
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
reply = self._ia_client.execute_agent(cmd)
print "Result of RESET: %s" % str(reply)
示例2: TestInstrumentManagementServiceIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
#create a parsed product for this instrument output
tdom, sdom = time_series_domain()
tdom = tdom.dump()
sdom = sdom.dump()
dp_obj = IonObject(RT.DataProduct,
name='the parsed data',
description='ctd stream test',
processing_level_code='Parsed_Canonical',
temporal_domain = tdom,
spatial_domain = sdom)
pdict_id = self.DSC.read_parameter_dictionary_by_name('ctd_parsed_param_dict', id_only=True)
parsed_stream_def_id = self.PSC.create_stream_definition(name='parsed', parameter_dictionary_id=pdict_id)
data_product_id1 = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=parsed_stream_def_id)
log.debug( 'new dp_id = %s', data_product_id1)
self.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=data_product_id1)
def addInstOwner(inst_id, subject):
actor_identity_obj = any_old(RT.ActorIdentity, {"name": subject})
user_id = self.IDS.create_actor_identity(actor_identity_obj)
user_info_obj = any_old(RT.UserInfo)
user_info_id = self.IDS.create_user_info(user_id, user_info_obj)
self.RR.create_association(inst_id, PRED.hasOwner, user_id)
#Testing multiple instrument owners
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Roger Unwin A254")
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Bob Cumbers A256")
extended_instrument = self.IMS.get_instrument_device_extension(instrument_device_id)
self.assertEqual(instrument_device_id, extended_instrument._id)
self.assertEqual(len(extended_instrument.owners), 2)
self.assertEqual(extended_instrument.instrument_model._id, instrument_model_id)
# Lifecycle
self.assertEquals(len(extended_instrument.lcstate_transitions), 7)
self.assertEquals(set(extended_instrument.lcstate_transitions.keys()), set(['enable', 'develop', 'deploy', 'retire', 'plan', 'integrate', 'announce']))
# Verify that computed attributes exist for the extended instrument
self.assertIsInstance(extended_instrument.computed.firmware_version, ComputedFloatValue)
self.assertIsInstance(extended_instrument.computed.last_data_received_datetime, ComputedFloatValue)
self.assertIsInstance(extended_instrument.computed.last_calibration_datetime, ComputedFloatValue)
self.assertIsInstance(extended_instrument.computed.uptime, ComputedStringValue)
self.assertIsInstance(extended_instrument.computed.power_status_roll_up, ComputedIntValue)
self.assertIsInstance(extended_instrument.computed.communications_status_roll_up, ComputedIntValue)
self.assertIsInstance(extended_instrument.computed.data_status_roll_up, ComputedIntValue)
self.assertIsInstance(extended_instrument.computed.location_status_roll_up, ComputedIntValue)
log.debug("extended_instrument.computed: %s", extended_instrument.computed)
#check model
inst_model_obj = self.RR.read(instrument_model_id)
self.assertEqual(inst_model_obj.name, extended_instrument.instrument_model.name)
#check agent instance
inst_agent_instance_obj = self.RR.read(instrument_agent_instance_id)
self.assertEqual(inst_agent_instance_obj.name, extended_instrument.agent_instance.name)
#check agent
inst_agent_obj = self.RR.read(instrument_agent_id)
示例3: TestActivateInstrumentIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
reply = self._ia_client.execute_agent(cmd)
log.debug("test_activateInstrumentSample: return from reset %s" , str(reply))
#--------------------------------------------------------------------------------
# Now get the data in one chunk using an RPC Call to start_retreive
#--------------------------------------------------------------------------------
replay_data_raw = self.dataretrieverclient.retrieve(self.raw_dataset)
self.assertIsInstance(replay_data_raw, Granule)
rdt_raw = RecordDictionaryTool.load_from_granule(replay_data_raw)
log.debug("RDT raw: %s", str(rdt_raw.pretty_print()) )
self.assertIn('raw', rdt_raw)
raw_vals = rdt_raw['raw']
all_raw = "".join(raw_vals)
# look for 't' entered after a prompt -- ">t"
t_commands = all_raw.count(">t")
if 10 != t_commands:
log.error("%s raw_vals: ", len(raw_vals))
for i, r in enumerate(raw_vals): log.error("raw val %s: %s", i, [r])
self.fail("Expected 10 't' strings in raw_vals, got %s" % t_commands)
else:
log.debug("%s raw_vals: ", len(raw_vals))
for i, r in enumerate(raw_vals): log.debug("raw val %s: %s", i, [r])
replay_data_parsed = self.dataretrieverclient.retrieve(self.parsed_dataset)
self.assertIsInstance(replay_data_parsed, Granule)
rdt_parsed = RecordDictionaryTool.load_from_granule(replay_data_parsed)
log.debug("test_activateInstrumentSample: RDT parsed: %s", str(rdt_parsed.pretty_print()) )
self.assertIn('temp', rdt_parsed)
temp_vals = rdt_parsed['temp']
pressure_vals = rdt_parsed['pressure']
if 10 != len(temp_vals):
log.error("%s temp_vals: %s", len(temp_vals), temp_vals)
self.fail("Expected 10 temp_vals, got %s" % len(temp_vals))
log.debug("l4-ci-sa-rq-138")
"""
Physical resource control shall be subject to policy
Instrument management control capabilities shall be subject to policy
The actor accessing the control capabilities must be authorized to send commands.
note from maurice 2012-05-18: Talk to tim M to verify that this is policy. If it is then talk with Stephen to
get an example of a policy test and use that to create a test stub that will be
completed when we have instrument policies.
Tim M: The "actor", aka observatory operator, will access the instrument through ION.
"""
#--------------------------------------------------------------------------------
# Get the extended data product to see if it contains the granules
#--------------------------------------------------------------------------------
extended_product = self.dpclient.get_data_product_extension(data_product_id=data_product_id1, user_id=user_id_1)
def poller(extended_product):
return len(extended_product.computed.user_notification_requests.value) == 1
poll(poller, extended_product, timeout=30)
self._check_computed_attributes_of_extended_product( expected_data_product_id = data_product_id1, extended_data_product = extended_product)
#--------------------------------------------------------------------------------
# Get the extended instrument
#--------------------------------------------------------------------------------
extended_instrument = self.imsclient.get_instrument_device_extension(instrument_device_id=instDevice_id, user_id=user_id_1)
#--------------------------------------------------------------------------------
# For the second user, check the extended data product and the extended intrument
#--------------------------------------------------------------------------------
extended_product = self.dpclient.get_data_product_extension(data_product_id=data_product_id2, user_id=user_id_2)
self._check_computed_attributes_of_extended_product(expected_data_product_id = data_product_id2, extended_data_product = extended_product)
#--------------------------------------------------------------------------------
# Get the extended instrument
#--------------------------------------------------------------------------------
extended_instrument = self.imsclient.get_instrument_device_extension(instrument_device_id=instDevice_id, user_id=user_id_2)
self._check_computed_attributes_of_extended_instrument(expected_instrument_device_id = instDevice_id, extended_instrument = extended_instrument)
#--------------------------------------------------------------------------------
# Deactivate loggers
#--------------------------------------------------------------------------------
for pid in self.loggerpids:
self.processdispatchclient.cancel_process(pid)
self.dpclient.delete_data_product(data_product_id1)
self.dpclient.delete_data_product(data_product_id2)
示例4: TestCTDTransformsIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
#-------------------------------------------------------------------------------------
# Launch InstrumentAgentInstance, connect to the resource agent client
#-------------------------------------------------------------------------------------
self.imsclient.start_instrument_agent_instance(instrument_agent_instance_id=instAgentInstance_id)
self.addCleanup(self.imsclient.stop_instrument_agent_instance,
instrument_agent_instance_id=instAgentInstance_id)
inst_agent_instance_obj= self.imsclient.read_instrument_agent_instance(instAgentInstance_id)
# Wait for instrument agent to spawn
gate = AgentProcessStateGate(self.processdispatchclient.read_process,
instDevice_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(15), "The instrument agent instance did not spawn in 15 seconds")
# Start a resource agent client to talk with the instrument agent.
self._ia_client = ResourceAgentClient(instDevice_id, to_name=gate.process_id, process=FakeProcess())
#-------------------------------------------------------------------------------------
# Streaming
#-------------------------------------------------------------------------------------
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GET_RESOURCE_STATE)
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)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
#todo ResourceAgentClient no longer has method set_param
# # Make sure the sampling rate and transmission are sane.
# params = {
# SBE37Parameter.NAVG : 1,
# SBE37Parameter.INTERVAL : 5,
# SBE37Parameter.TXREALTIME : True
# }
# self._ia_client.set_param(params)
#todo There is no ResourceAgentEvent attribute for go_streaming... so what should be the command for it?
cmd = AgentCommand(command=SBE37ProtocolEvent.START_AUTOSAMPLE)
retval = self._ia_client.execute_resource(cmd)
# This gevent sleep is there to test the autosample time, which will show something different from default
# only if the instrument runs for over a minute
gevent.sleep(90)
extended_instrument = self.imsclient.get_instrument_device_extension(instrument_device_id=instDevice_id)
self.assertIsInstance(extended_instrument.computed.uptime, ComputedStringValue)
autosample_string = extended_instrument.computed.uptime.value
autosampling_time = int(autosample_string.split()[4])
self.assertTrue(autosampling_time > 0)
cmd = AgentCommand(command=SBE37ProtocolEvent.STOP_AUTOSAMPLE)
retval = self._ia_client.execute_resource(cmd)
#todo There is no ResourceAgentEvent attribute for go_observatory... so what should be the command for it?
# log.debug("test_activateInstrumentStream: calling go_observatory")
# cmd = AgentCommand(command='go_observatory')
# reply = self._ia_client.execute_agent(cmd)
# cmd = AgentCommand(command='get_current_state')
# retval = self._ia_client.execute_agent(cmd)
# state = retval.result
# log.debug("test_activateInstrumentStream: return from go_observatory state %s", str(state))
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
#-------------------------------------------------------------------------------------------------
# Cleanup processes
#-------------------------------------------------------------------------------------------------
for pid in self.loggerpids:
self.processdispatchclient.cancel_process(pid)
#--------------------------------------------------------------------------------
# Cleanup data products
#--------------------------------------------------------------------------------
dp_ids, _ = self.rrclient.find_resources(restype=RT.DataProduct, id_only=True)
for dp_id in dp_ids:
self.dataproductclient.delete_data_product(dp_id)
示例5: TestRollups
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
self.assertEqual(self.idv[1], self.RR2.find_instrument_device_id_of_instrument_site_using_has_device(self.ist[1]))
self.assertEqual(DeviceStatusType.STATUS_CRITICAL,
self.my_get_agent_client(self.idv[1]).get_agent(["aggstatus"])["aggstatus"][AggregateStatusType.AGGREGATE_DATA])
# pdv4 should have status warning, coming from pdv7
self.assertEqual(self.pdv[5], self.RR2.find_platform_device_id_of_platform_device_using_has_device(self.pdv[4]))
self.assertIn(self.pdv[6], self.RR2.find_platform_device_ids_of_platform_device_using_has_device(self.pdv[5]))
self.assertIn(self.pdv[7], self.RR2.find_platform_device_ids_of_platform_device_using_has_device(self.pdv[5]))
self.assertEqual(self.idv[4], self.RR2.find_instrument_device_id_of_platform_device_using_has_device(self.pdv[7]))
self.assertEqual(DeviceStatusType.STATUS_OK,
self.my_get_agent_client(self.idv[4]).get_agent(["aggstatus"])["aggstatus"][AggregateStatusType.AGGREGATE_DATA])
self.assertEqual(DeviceStatusType.STATUS_WARNING,
self.my_get_agent_client(self.pdv[7]).get_agent(["aggstatus"])["aggstatus"][AggregateStatusType.AGGREGATE_DATA])
@unittest.skip("errors in outil prevent this from passing")
def test_complex_rollup_structure(self):
self.check_structure_assumptions()
o = DeviceStatusType.STATUS_OK
u = DeviceStatusType.STATUS_UNKNOWN
w = DeviceStatusType.STATUS_WARNING
c = DeviceStatusType.STATUS_CRITICAL
pst_stat = ["ignore", c, c, w, w, u, w, o, w]
pdv_stat = ["ignore", o, w, w, w, w, o, w, c, c, w, c]
ist_stat = ["ignore", c, o, w, u, o, u]
idv_stat = ["ignore", c, o, w, o, w, c]
for i, id in self.idv.iteritems():
label = "InstrumentDevice %s" % i
log.info("Checking rollup of %s", label)
self.assertProperRollup(label, self.IMS.get_instrument_device_extension(id), idv_stat[i])
for i, id in self.ist.iteritems():
label = "InstrumentSite %s" % i
log.info("Checking rollup of %s", label)
self.assertProperRollup(label, self.OMS.get_site_extension(id), ist_stat[i])
for i, id in self.pdv.iteritems():
label = "PlatformDevice %s" % i
log.info("Checking rollup of %s", label)
self.assertProperRollup(label, self.IMS.get_platform_device_extension(id), pdv_stat[i])
for i, id in self.pst.iteritems():
label = "PlatformSite %s" % i
log.info("Checking rollup of %s", label)
self.assertProperRollup(label, self.OMS.get_site_extension(id), pst_stat[i])
#TODO: check observatory and org rollups!
#TODO: REMOVE THIS TEST when test_complex_rollup_structure is fixed
#@unittest.skip("phasing out")
def test_complex_rollup_structure_partially(self):
o = DeviceStatusType.STATUS_OK
u = DeviceStatusType.STATUS_UNKNOWN
w = DeviceStatusType.STATUS_WARNING
c = DeviceStatusType.STATUS_CRITICAL
idv_stat = ["ignore", c, o, w, o, w, c]
ist_stat = ["ignore", c, o, w, u, o, u]
示例6: TestInstrumentManagementServiceIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
#create a parsed product for this instrument output
tdom, sdom = time_series_domain()
tdom = tdom.dump()
sdom = sdom.dump()
dp_obj = IonObject(RT.DataProduct,
name='the parsed data',
description='ctd stream test',
processing_level_code='Parsed_Canonical',
temporal_domain = tdom,
spatial_domain = sdom)
pdict_id = self.DSC.read_parameter_dictionary_by_name('ctd_parsed_param_dict', id_only=True)
parsed_stream_def_id = self.PSC.create_stream_definition(name='parsed', parameter_dictionary_id=pdict_id)
data_product_id1 = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=parsed_stream_def_id)
log.debug( 'new dp_id = %s', data_product_id1)
self.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=data_product_id1)
def addInstOwner(inst_id, subject):
actor_identity_obj = any_old(RT.ActorIdentity, {"name": subject})
user_id = self.IDS.create_actor_identity(actor_identity_obj)
user_info_obj = any_old(RT.UserInfo)
user_info_id = self.IDS.create_user_info(user_id, user_info_obj)
self.RR.create_association(inst_id, PRED.hasOwner, user_id)
#Testing multiple instrument owners
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Roger Unwin A254")
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Bob Cumbers A256")
extended_instrument = self.IMS.get_instrument_device_extension(instrument_device_id)
self.assertEqual(instrument_device_id, extended_instrument._id)
self.assertEqual(len(extended_instrument.owners), 2)
self.assertEqual(extended_instrument.instrument_model._id, instrument_model_id)
#check model
inst_model_obj = self.RR.read(instrument_model_id)
self.assertEqual(inst_model_obj.name, extended_instrument.instrument_model.name)
#check agent instance
inst_agent_instance_obj = self.RR.read(instrument_agent_instance_id)
self.assertEqual(inst_agent_instance_obj.name, extended_instrument.agent_instance.name)
#check agent
inst_agent_obj = self.RR.read(instrument_agent_id)
#compound assoc return list of lists so check the first element
self.assertEqual(inst_agent_obj.name, extended_instrument.instrument_agent[0].name)
#check platform device
plat_device_obj = self.RR.read(platform_device_id)
self.assertEqual(plat_device_obj.name, extended_instrument.platform_device.name)
#check sensor devices
self.assertEqual(1, len(extended_instrument.sensor_devices))
#check data_product_parameters_set
self.assertEqual(ComputedValueAvailability.PROVIDED,
extended_instrument.computed.data_product_parameters_set.status)
self.assertTrue( 'Parsed_Canonical' in extended_instrument.computed.data_product_parameters_set.value)
# the ctd parameters should include 'temp'
self.assertTrue( 'temp' in extended_instrument.computed.data_product_parameters_set.value['Parsed_Canonical'])
示例7: TestActivateInstrumentIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
#out_of_range_temp_vals = [i for i in temp_vals if i > 5]
out_of_range_temp_vals = [i for i in temp_vals if i < 50.0]
log.debug("test_activateInstrumentSample: Out_of_range_temp_vals: %s", out_of_range_temp_vals )
self._samples_out_of_range = len(out_of_range_temp_vals)
# if no bad values were produced, then do not wait for an event
if self._samples_out_of_range == 0:
self._async_sample_result.set()
log.debug("test_activateInstrumentSample: _events_received: %s", self._events_received )
log.debug("test_activateInstrumentSample: _event_count: %s", self._event_count )
self._async_sample_result.get(timeout=CFG.endpoint.receive.timeout)
replay_data = self.dataretrieverclient.retrieve(self.raw_dataset)
self.assertIsInstance(replay_data, Granule)
rdt = RecordDictionaryTool.load_from_granule(replay_data)
log.debug("RDT raw: %s", str(rdt.pretty_print()) )
raw_vals = rdt['raw']
self.assertEquals(len(raw_vals) , 10)
log.debug("l4-ci-sa-rq-138")
"""
Physical resource control shall be subject to policy
Instrument management control capabilities shall be subject to policy
The actor accessing the control capabilities must be authorized to send commands.
note from maurice 2012-05-18: Talk to tim M to verify that this is policy. If it is then talk with Stephen to
get an example of a policy test and use that to create a test stub that will be
completed when we have instrument policies.
Tim M: The "actor", aka observatory operator, will access the instrument through ION.
"""
#--------------------------------------------------------------------------------
# Get the extended data product to see if it contains the granules
#--------------------------------------------------------------------------------
extended_product = self.dpclient.get_data_product_extension(data_product_id=data_product_id1, user_id=user_id_1)
def poller(extended_product):
return len(extended_product.computed.user_notification_requests.value) == 1
poll(poller, extended_product, timeout=30)
self._check_computed_attributes_of_extended_product( expected_data_product_id = data_product_id1, extended_data_product = extended_product)
#--------------------------------------------------------------------------------
#put some events into the eventsdb to test - this should set the comms and data status to WARNING
#--------------------------------------------------------------------------------
t = get_ion_ts()
self.event_publisher.publish_event( ts_created= t, event_type = 'DeviceStatusEvent',
origin = instDevice_id, state=DeviceStatusType.OUT_OF_RANGE, values = [200] )
self.event_publisher.publish_event( ts_created= t, event_type = 'DeviceCommsEvent',
origin = instDevice_id, state=DeviceCommsType.DATA_DELIVERY_INTERRUPTION, lapse_interval_seconds = 20 )
#--------------------------------------------------------------------------------
# Get the extended instrument
#--------------------------------------------------------------------------------
extended_instrument = self.imsclient.get_instrument_device_extension(instrument_device_id=instDevice_id, user_id=user_id_1)
self._check_computed_attributes_of_extended_instrument(expected_instrument_device_id = instDevice_id, extended_instrument = extended_instrument)
#--------------------------------------------------------------------------------
# For the second user, check the extended data product and the extended intrument
#--------------------------------------------------------------------------------
extended_product = self.dpclient.get_data_product_extension(data_product_id=data_product_id2, user_id=user_id_2)
self._check_computed_attributes_of_extended_product(expected_data_product_id = data_product_id2, extended_data_product = extended_product)
#---------- Put some events into the eventsdb to test - this should set the comms and data status to WARNING ---------
t = get_ion_ts()
self.event_publisher.publish_event( ts_created= t, event_type = 'DeviceStatusEvent',
origin = instDevice_id, state=DeviceStatusType.OUT_OF_RANGE, values = [200] )
self.event_publisher.publish_event( ts_created= t, event_type = 'DeviceCommsEvent',
origin = instDevice_id, state=DeviceCommsType.DATA_DELIVERY_INTERRUPTION, lapse_interval_seconds = 20 )
#--------------------------------------------------------------------------------
# Get the extended instrument
#--------------------------------------------------------------------------------
extended_instrument = self.imsclient.get_instrument_device_extension(instrument_device_id=instDevice_id, user_id=user_id_2)
self._check_computed_attributes_of_extended_instrument(expected_instrument_device_id = instDevice_id, extended_instrument = extended_instrument)
#--------------------------------------------------------------------------------
# Deactivate loggers
#--------------------------------------------------------------------------------
for pid in self.loggerpids:
self.processdispatchclient.cancel_process(pid)
self.dpclient.delete_data_product(data_product_id1)
self.dpclient.delete_data_product(data_product_id2)
示例8: TestInstrumentManagementServiceIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
#.........这里部分代码省略.........
#sensor_device
self.RR.create_association(sensor_device_id, PRED.hasModel, sensor_model_id)
self.RR.create_association(sensor_device_id, PRED.hasDevice, instrument_device_id)
sensor_model_id #is only a target
#create a parsed product for this instrument output
dp_obj = IonObject(RT.DataProduct,
name='the parsed data',
description='ctd stream test',
processing_level_code='Parsed_Canonical')
pdict_id = self.DSC.read_parameter_dictionary_by_name('ctd_parsed_param_dict', id_only=True)
parsed_stream_def_id = self.PSC.create_stream_definition(name='parsed', parameter_dictionary_id=pdict_id)
data_product_id1 = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=parsed_stream_def_id)
log.debug( 'new dp_id = %s', data_product_id1)
self.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=data_product_id1)
def addInstOwner(inst_id, subject):
actor_identity_obj = any_old(RT.ActorIdentity, {"name": subject})
user_id = self.IDS.create_actor_identity(actor_identity_obj)
user_info_obj = any_old(RT.UserInfo)
user_info_id = self.IDS.create_user_info(user_id, user_info_obj)
self.RR.create_association(inst_id, PRED.hasOwner, user_id)
#Testing multiple instrument owners
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Roger Unwin A254")
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Bob Cumbers A256")
extended_instrument = self.IMS.get_instrument_device_extension(instrument_device_id)
self.assertEqual(instrument_device_id, extended_instrument._id)
self.assertEqual(len(extended_instrument.owners), 2)
self.assertEqual(extended_instrument.instrument_model._id, instrument_model_id)
# Lifecycle
self.assertEquals(len(extended_instrument.lcstate_transitions), 6)
self.assertEquals(set(extended_instrument.lcstate_transitions.keys()), set(['develop', 'deploy', 'retire', 'plan', 'integrate', 'delete']))
self.assertEquals(len(extended_instrument.availability_transitions), 2)
self.assertEquals(set(extended_instrument.availability_transitions.keys()), set(['enable', 'announce']))
# Verify that computed attributes exist for the extended instrument
self.assertIsInstance(extended_instrument.computed.last_data_received_datetime, ComputedFloatValue)
self.assertIsInstance(extended_instrument.computed.uptime, ComputedStringValue)
self.assertIsInstance(extended_instrument.computed.power_status_roll_up, ComputedIntValue)
self.assertIsInstance(extended_instrument.computed.communications_status_roll_up, ComputedIntValue)
self.assertIsInstance(extended_instrument.computed.data_status_roll_up, ComputedIntValue)
self.assertIsInstance(extended_instrument.computed.location_status_roll_up, ComputedIntValue)
log.debug("extended_instrument.computed: %s", extended_instrument.computed)
#check model
inst_model_obj = self.RR.read(instrument_model_id)
self.assertEqual(inst_model_obj.name, extended_instrument.instrument_model.name)
#check agent instance
inst_agent_instance_obj = self.RR.read(instrument_agent_instance_id)
self.assertEqual(inst_agent_instance_obj.name, extended_instrument.agent_instance.name)
#check agent
inst_agent_obj = self.RR.read(instrument_agent_id)
示例9: TestInstrumentManagementServiceIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
class TestInstrumentManagementServiceIntegration(IonIntegrationTestCase):
def setUp(self):
# Start container
#print 'instantiating container'
self._start_container()
#container = Container()
#print 'starting container'
#container.start()
#print 'started container'
self.container.start_rel_from_url('res/deploy/r2deploy.yml')
self.RR = ResourceRegistryServiceClient(node=self.container.node)
self.IMS = InstrumentManagementServiceClient(node=self.container.node)
self.IDS = IdentityManagementServiceClient(node=self.container.node)
print 'started services'
# @unittest.skip('this test just for debugging setup')
# def test_just_the_setup(self):
# return
@attr('EXT')
def test_resources_associations_extensions(self):
"""
create one of each resource and association used by IMS
to guard against problems in ion-definitions
"""
#stuff we control
# instrument_agent_instance_id, _ = self.RR.create(any_old(RT.InstrumentAgentInstance))
instrument_agent_id, _ = self.RR.create(any_old(RT.InstrumentAgent))
instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice))
instrument_model_id, _ = self.RR.create(any_old(RT.InstrumentModel))
platform_agent_instance_id, _ = self.RR.create(any_old(RT.PlatformAgentInstance))
platform_agent_id, _ = self.RR.create(any_old(RT.PlatformAgent))
platform_device_id, _ = self.RR.create(any_old(RT.PlatformDevice))
platform_model_id, _ = self.RR.create(any_old(RT.PlatformModel))
sensor_device_id, _ = self.RR.create(any_old(RT.SensorDevice))
sensor_model_id, _ = self.RR.create(any_old(RT.SensorModel))
#stuff we associate to
data_producer_id, _ = self.RR.create(any_old(RT.DataProducer))
#instrument_agent_instance_id #is only a target
#instrument_agent
self.RR.create_association(instrument_agent_id, PRED.hasModel, instrument_model_id)
# self.RR.create_association(instrument_agent_instance_id, PRED.hasAgentDefinition, instrument_agent_id)
#instrument_device
self.RR.create_association(instrument_device_id, PRED.hasModel, instrument_model_id)
# self.RR.create_association(instrument_device_id, PRED.hasAgentInstance, instrument_agent_instance_id)
self.RR.create_association(instrument_device_id, PRED.hasDataProducer, data_producer_id)
self.RR.create_association(instrument_device_id, PRED.hasDevice, sensor_device_id)
instrument_model_id #is only a target
platform_agent_instance_id #is only a target
#platform_agent
self.RR.create_association(platform_agent_id, PRED.hasModel, platform_model_id)
self.RR.create_association(platform_agent_instance_id, PRED.hasAgentDefinition, platform_agent_id)
#platform_device
self.RR.create_association(platform_device_id, PRED.hasModel, platform_model_id)
self.RR.create_association(platform_device_id, PRED.hasAgentInstance, platform_agent_instance_id)
self.RR.create_association(platform_device_id, PRED.hasDevice, instrument_device_id)
platform_model_id #is only a target
#sensor_device
self.RR.create_association(sensor_device_id, PRED.hasModel, sensor_model_id)
self.RR.create_association(sensor_device_id, PRED.hasDevice, instrument_device_id)
sensor_model_id #is only a target
def addInstOwner(inst_id, subject):
actor_identity_obj = any_old(RT.ActorIdentity, {"name": subject})
user_id = self.IDS.create_actor_identity(actor_identity_obj)
user_info_obj = any_old(RT.UserInfo)
user_info_id = self.IDS.create_user_info(user_id, user_info_obj)
self.RR.create_association(inst_id, PRED.hasOwner, user_id)
#Testing multiple instrument owners
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Roger Unwin A254")
addInstOwner(instrument_device_id, "/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Bob Cumbers A256")
#testing data products
dp_id, _ = self.RR.create(any_old(RT.DataProduct))
self.RR.create_association(instrument_device_id, PRED.hasOutputProduct, dp_id)
extended_instrument = self.IMS.get_instrument_device_extension(instrument_device_id)
self.assertEqual(instrument_device_id, extended_instrument._id)
self.assertEqual(len(extended_instrument.owners), 2)
#.........这里部分代码省略.........
示例10: TestAgentStatusBuilderIntegration
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import get_instrument_device_extension [as 别名]
class TestAgentStatusBuilderIntegration(IonIntegrationTestCase):
def setUp(self):
# Start container
#print 'instantiating container'
self._start_container()
#container = Container()
#print 'starting container'
#container.start()
#print 'started container'
self.container.start_rel_from_url('res/deploy/r2deploy.yml')
self.RR = ResourceRegistryServiceClient(node=self.container.node)
self.IMS = InstrumentManagementServiceClient(node=self.container.node)
self.OMS = ObservatoryManagementServiceClient(node=self.container.node)
self.RR2 = EnhancedResourceRegistryClient(self.RR)
self._setup_statuses()
def _make_status(self, bad_items_dict):
ret = {}
for k in reverse_mapping.values():
if k in bad_items_dict:
ret[k] = bad_items_dict[k]
else:
ret[k] = DeviceStatusType.STATUS_OK
return ret
def _setup_statuses(self):
device_agents = {}
IMS_SVC = self._get_svc(InstrumentManagementService)
OMS_SVC = self._get_svc(ObservatoryManagementService)
self.IMS_ASB = self._get_specific_attr(IMS_SVC, AgentStatusBuilder)
self.OMS_ASB = self._get_specific_attr(OMS_SVC, AgentStatusBuilder)
assert self.IMS_ASB
assert self.OMS_ASB
self.IMS_ASB.RR2 = IMS_SVC.RR2
self.OMS_ASB.RR2 = OMS_SVC.RR2
# create one tree of devices
self.grandparent1_device_id = self.RR2.create(any_old(RT.PlatformDevice))
self.parent1_device_id = self.RR2.create(any_old(RT.PlatformDevice))
self.child1_device_id = self.RR2.create(any_old(RT.InstrumentDevice))
self.RR2.create_association(self.grandparent1_device_id, PRED.hasDevice, self.parent1_device_id)
self.RR2.create_association(self.parent1_device_id, PRED.hasDevice, self.child1_device_id)
g1_agent = FakeAgent()
g1_stat = self._make_status({AggregateStatusType.AGGREGATE_COMMS: DeviceStatusType.STATUS_UNKNOWN})
p1_stat = self._make_status({AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_CRITICAL})
c1_stat = self._make_status({AggregateStatusType.AGGREGATE_LOCATION: DeviceStatusType.STATUS_WARNING})
g1_agent.set_agent("aggstatus", g1_stat)
g1_agent.set_agent("child_agg_status", {self.parent1_device_id: p1_stat,
self.child1_device_id: c1_stat})
device_agents[self.grandparent1_device_id] = g1_agent
c1_agent = FakeAgent()
c1_agent.set_agent("aggstatus", c1_stat)
device_agents[self.child1_device_id] = c1_agent
# create second tree of devices
self.grandparent2_device_id = self.RR2.create(any_old(RT.PlatformDevice))
self.parent2_device_id = self.RR2.create(any_old(RT.PlatformDevice))
self.child2_device_id = self.RR2.create(any_old(RT.InstrumentDevice))
self.RR2.create_association(self.grandparent2_device_id, PRED.hasDevice, self.parent2_device_id)
self.RR2.create_association(self.parent2_device_id, PRED.hasDevice, self.child2_device_id)
g2_agent = FakeAgent()
g2_stat = self._make_status({AggregateStatusType.AGGREGATE_COMMS: DeviceStatusType.STATUS_UNKNOWN})
p2_stat = self._make_status({AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_CRITICAL})
c2_stat = self._make_status({AggregateStatusType.AGGREGATE_LOCATION: DeviceStatusType.STATUS_WARNING})
g2_agent.set_agent("aggstatus", g2_stat)
g2_agent.set_agent("child_agg_status", {self.parent2_device_id: p2_stat,
self.child2_device_id: c2_stat})
device_agents[self.grandparent2_device_id] = g2_agent
def my_get_agent_client(device_id, **kwargs):
try:
return device_agents[device_id]
except KeyError:
raise NotFound
self.IMS_ASB._get_agent_client = my_get_agent_client
@unittest.skip("hasDevice rollup is no longer supported")
def test_get_device_rollup(self):
iext = self.IMS.get_instrument_device_extension(self.child1_device_id)
istatus = self._make_status({AggregateStatusType.AGGREGATE_LOCATION: DeviceStatusType.STATUS_WARNING})
#.........这里部分代码省略.........