def test_observatory_extensions(self): obs_id = self.RR2.create(any_old(RT.Observatory)) pss_id = self.RR2.create(any_old(RT.PlatformSite, dict(alt_resource_type="StationSite"))) pas_id = self.RR2.create(any_old(RT.PlatformSite, dict(alt_resource_type="PlatformAssemblySite"))) pcs_id = self.RR2.create(any_old(RT.PlatformSite, dict(alt_resource_type="PlatformComponentSite"))) ins_id = self.RR2.create(any_old(RT.InstrumentSite)) obs_obj = self.RR2.read(obs_id) pss_obj = self.RR2.read(pss_id) pas_obj = self.RR2.read(pas_id) pcs_obj = self.RR2.read(pcs_id) ins_obj = self.RR2.read(ins_id) self.RR2.create_association(obs_id, PRED.hasSite, pss_id) self.RR2.create_association(pss_id, PRED.hasSite, pas_id) self.RR2.create_association(pas_id, PRED.hasSite, pcs_id) self.RR2.create_association(pcs_id, PRED.hasSite, ins_id) extended_obs = self.OMS.get_observatory_site_extension(obs_id, user_id=12345) self.assertEqual([pss_obj], extended_obs.platform_station_sites) self.assertEqual([pas_obj], extended_obs.platform_assembly_sites) self.assertEqual([pcs_obj], extended_obs.platform_component_sites) self.assertEqual([ins_obj], extended_obs.instrument_sites) extended_pss = self.OMS.get_observatory_site_extension(obs_id, user_id=12345) self.assertEqual([pas_obj], extended_pss.platform_assembly_sites) self.assertEqual([pcs_obj], extended_pss.platform_component_sites) self.assertEqual([ins_obj], extended_pss.instrument_sites) extended_pas = self.OMS.get_observatory_site_extension(pas_id, user_id=12345) self.assertEqual([pcs_obj], extended_pas.platform_component_sites) self.assertEqual([ins_obj], extended_pas.instrument_sites) extended_pcs = self.OMS.get_platform_component_site_extension(pcs_id, user_id=12345) self.assertEqual([ins_obj], extended_pcs.instrument_sites)
def test_custom_attributes(self): """ Test assignment of custom attributes """ instModel_obj = IonObject(OT.CustomAttribute, name='SBE37IMModelAttr', description="model custom attr") instrument_model_id, _ = self.RR.create( any_old(RT.InstrumentModel, {"custom_attributes": [instModel_obj]})) instrument_device_id, _ = self.RR.create( any_old( RT.InstrumentDevice, { "custom_attributes": { "favorite_color": "red", "bogus_attr": "should raise warning" } })) self.IMS.assign_instrument_model_to_instrument_device( instrument_model_id, instrument_device_id) # cleanup self.IMS.force_delete_instrument_device(instrument_device_id) self.IMS.force_delete_instrument_model(instrument_model_id)
def _make_platform_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation platform_agent_instance_obj = any_old(RT.PlatformAgentInstance) platform_agent_instance_obj.agent_config = agent_config platform_agent_instance_id = self.IMS.create_platform_agent_instance(platform_agent_instance_obj) # agent creation raw_config = StreamConfiguration(stream_name='parsed', parameter_dictionary_name='platform_eng_parsed', records_per_granule=2, granule_publish_rate=5) platform_agent_obj = any_old(RT.PlatformAgent, {"stream_configurations":[raw_config]}) platform_agent_id = self.IMS.create_platform_agent(platform_agent_obj) # device creation platform_device_id = self.IMS.create_platform_device(any_old(RT.PlatformDevice)) # data product creation dp_obj = any_old(RT.DataProduct, {"temporal_domain":tdom, "spatial_domain": sdom}) # dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=self.parsed_stream_def_id) self.DAMS.assign_data_product(input_resource_id=platform_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) # assignments self.RR2.assign_platform_agent_instance_to_platform_device(platform_agent_instance_id, platform_device_id) self.RR2.assign_platform_agent_to_platform_agent_instance(platform_agent_id, platform_agent_instance_id) self.RR2.assign_platform_device_to_org_with_has_resource(platform_agent_instance_id, org_id) return platform_agent_instance_id, platform_agent_id, platform_device_id
def _make_instrument_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation instrument_agent_instance_obj = any_old(RT.InstrumentAgentInstance, {"startup_config": inst_startup_config, 'alerts': generic_alerts_config}) instrument_agent_instance_obj.agent_config = agent_config instrument_agent_instance_id = self.IMS.create_instrument_agent_instance(instrument_agent_instance_obj) # agent creation raw_config = StreamConfiguration(stream_name='raw', parameter_dictionary_name='ctd_raw_param_dict', records_per_granule=2, granule_publish_rate=5 ) instrument_agent_obj = any_old(RT.InstrumentAgent, {"stream_configurations":[raw_config]}) instrument_agent_id = self.IMS.create_instrument_agent(instrument_agent_obj) # device creation instrument_device_id = self.IMS.create_instrument_device(any_old(RT.InstrumentDevice)) # data product creation dp_obj = any_old(RT.DataProduct, {"temporal_domain":tdom, "spatial_domain": sdom}) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) self.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) # assignments self.RR2.assign_instrument_agent_instance_to_instrument_device(instrument_agent_instance_id, instrument_device_id) self.RR2.assign_instrument_agent_to_instrument_agent_instance(instrument_agent_id, instrument_agent_instance_id) self.RR2.assign_instrument_device_to_org_with_has_resource(instrument_agent_instance_id, org_id) return instrument_agent_instance_id, instrument_agent_id, instrument_device_id
def _make_instrument_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation instrument_agent_instance_obj = any_old(RT.InstrumentAgentInstance, {"startup_config": inst_startup_config}) instrument_agent_instance_obj.agent_config = agent_config instrument_agent_instance_id = self.IMS.create_instrument_agent_instance(instrument_agent_instance_obj) # agent creation raw_config = StreamConfiguration(stream_name='raw', parameter_dictionary_name='ctd_raw_param_dict', records_per_granule=2, granule_publish_rate=5 ) instrument_agent_obj = any_old(RT.InstrumentAgent, {"stream_configurations":[raw_config]}) instrument_agent_id = self.IMS.create_instrument_agent(instrument_agent_obj) # device creation instrument_device_id = self.IMS.create_instrument_device(any_old(RT.InstrumentDevice)) # data product creation dp_obj = any_old(RT.DataProduct, {"temporal_domain":tdom, "spatial_domain": sdom}) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) self.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) # assignments self.RR2.assign_instrument_agent_instance_to_instrument_device(instrument_agent_instance_id, instrument_device_id) self.RR2.assign_instrument_agent_to_instrument_agent_instance(instrument_agent_id, instrument_agent_instance_id) self.RR2.assign_instrument_device_to_org_with_has_resource(instrument_agent_instance_id, org_id) return instrument_agent_instance_id, instrument_agent_id, instrument_device_id
def test_custom_attributes(self): """ Test assignment of custom attributes """ instModel_obj = IonObject(OT.CustomAttribute, name='SBE37IMModelAttr', description="model custom attr") instrument_model_id, _ = self.RR.create(any_old(RT.InstrumentModel, {"custom_attributes": [instModel_obj] })) instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice, {"custom_attributes": {"favorite_color": "red", "bogus_attr": "should raise warning" } })) self.IMS.assign_instrument_model_to_instrument_device(instrument_model_id, instrument_device_id) # cleanup self.IMS.force_delete_instrument_device(instrument_device_id) self.IMS.force_delete_instrument_model(instrument_model_id)
def _make_platform_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation platform_agent_instance_obj = any_old(RT.PlatformAgentInstance, {'driver_config': {'foo': 'bar'}, 'alerts': generic_alerts_config}) platform_agent_instance_obj.agent_config = agent_config platform_agent_instance_id = self.IMS.create_platform_agent_instance(platform_agent_instance_obj) # agent creation raw_config = StreamConfiguration(stream_name='raw', parameter_dictionary_name='ctd_raw_param_dict' ) platform_agent_obj = any_old(RT.PlatformAgent, {"stream_configurations":[raw_config]}) platform_agent_id = self.IMS.create_platform_agent(platform_agent_obj) # device creation platform_device_id = self.IMS.create_platform_device(any_old(RT.PlatformDevice)) # data product creation dp_obj = any_old(RT.DataProduct, {"temporal_domain":tdom, "spatial_domain": sdom}) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) self.DAMS.assign_data_product(input_resource_id=platform_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) self.addCleanup(self.DP.suspend_data_product_persistence, dp_id) # assignments self.RR2.assign_platform_agent_instance_to_platform_device_with_has_agent_instance(platform_agent_instance_id, platform_device_id) self.RR2.assign_platform_agent_to_platform_agent_instance_with_has_agent_definition(platform_agent_id, platform_agent_instance_id) self.RR2.assign_platform_device_to_org_with_has_resource(platform_agent_instance_id, org_id) return platform_agent_instance_id, platform_agent_id, platform_device_id
def test_activate_deployment_csp_fail(self): platform_model_id = [self.RR2.create(any_old(RT.PlatformModel)) for _ in range(2)] platform_device_id = [self.RR2.create(any_old(RT.PlatformDevice)) for _ in range(2)] platform_site_id = [self.RR2.create(any_old(RT.PlatformSite, {"planned_uplink_port": IonObject(OT.PlatformPort, reference_designator="platport_%d" % (i+1))})) for i in range(2)] deployment_id = self.RR2.create(any_old(RT.Deployment, {"context": IonObject(OT.CabledNodeDeploymentContext)})) # set up the structure for p in range(2): self.RR2.assign_platform_model_to_platform_site_with_has_model(platform_model_id[p], platform_site_id[p]) self.RR2.assign_platform_model_to_platform_device_with_has_model(platform_model_id[p], platform_device_id[p]) self.RR2.assign_deployment_to_platform_device_with_has_deployment(deployment_id, platform_device_id[p]) self.RR2.assign_deployment_to_platform_site_with_has_deployment(deployment_id, platform_site_id[p]) self.RR2.assign_platform_device_to_platform_device_with_has_device(platform_device_id[1], platform_device_id[0]) self.RR2.assign_platform_site_to_platform_site_with_has_site(platform_site_id[1], platform_site_id[0]) self.assert_deploy_fail(deployment_id, BadRequest, "Deployment activation without port_assignment is limited to 1 PlatformDevice") self.RR2.unassign_deployment_from_platform_device_with_has_deployment(deployment_id, platform_device_id[1]) self.assert_deploy_fail(deployment_id, BadRequest, "Deployment activation without port_assignment is limited to 1 PlatformSite")
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)
def _make_instrument_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation instrument_agent_instance_obj = any_old(RT.InstrumentAgentInstance, {"startup_config": inst_startup_config, 'alerts': generic_alerts_config}) instrument_agent_instance_obj.agent_config = agent_config instrument_agent_instance_id = self.IMS.create_instrument_agent_instance(instrument_agent_instance_obj) # agent creation raw_config = StreamConfiguration(stream_name='raw', parameter_dictionary_name='ctd_raw_param_dict' ) instrument_agent_obj = any_old(RT.InstrumentAgent, {"stream_configurations":[raw_config]}) instrument_agent_id = self.IMS.create_instrument_agent(instrument_agent_obj) # device creation instrument_device_id = self.IMS.create_instrument_device(any_old(RT.InstrumentDevice)) # data product creation dp_obj = any_old(RT.DataProduct, {"temporal_domain":tdom, "spatial_domain": sdom}) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) self.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) self.addCleanup(self.DP.suspend_data_product_persistence, dp_id) #deployment creation site_obj = IonObject(RT.InstrumentSite, name='siteInstrument') site_id = self.OMS.create_instrument_site(instrument_site =site_obj) # find current deployment using time constraints current_time = int( calendar.timegm(time.gmtime()) ) # two years on either side of current time start = current_time - 63115200 end = current_time + 63115200 temporal_bounds = IonObject(OT.TemporalBounds, name='planned', start_datetime=str(start), end_datetime=str(end)) platform_port_obj= IonObject(OT.PlatformPort, reference_designator = 'GA01SUMO-FI003-08-CTDMO0888', port_type=PortTypeEnum.PAYLOAD, ip_address=0) deployment_obj = IonObject(RT.Deployment, name='TestDeployment for Cabled Instrument', description='some new deployment', context=IonObject(OT.CabledInstrumentDeploymentContext), constraint_list=[temporal_bounds], port_assignments={instrument_device_id:platform_port_obj}) deploy_id = self.OMS.create_deployment(deployment=deployment_obj, site_id=site_id, device_id=instrument_device_id) # assignments self.RR2.assign_instrument_agent_instance_to_instrument_device_with_has_agent_instance(instrument_agent_instance_id, instrument_device_id) self.RR2.assign_instrument_agent_to_instrument_agent_instance_with_has_agent_definition(instrument_agent_id, instrument_agent_instance_id) self.RR2.assign_instrument_device_to_org_with_has_resource(instrument_agent_instance_id, org_id) return instrument_agent_instance_id, instrument_agent_id, instrument_device_id
def _make_platform_agent_structure(name='', agent_config=None): if None is agent_config: agent_config = {} # instance creation platform_agent_instance_obj = any_old(RT.PlatformAgentInstance, {'driver_config': {'foo': 'bar'}, 'alerts': generic_alerts_config}) platform_agent_instance_obj.agent_config = agent_config platform_agent_instance_id = self.IMS.create_platform_agent_instance(platform_agent_instance_obj) # agent creation raw_config = StreamConfiguration(stream_name='raw', parameter_dictionary_name='ctd_raw_param_dict' ) platform_agent_obj = any_old(RT.PlatformAgent, {"stream_configurations":[raw_config]}) platform_agent_id = self.IMS.create_platform_agent(platform_agent_obj) # device creation platform_device_id = self.IMS.create_platform_device(any_old(RT.PlatformDevice)) # data product creation dp_obj = any_old(RT.DataProduct) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) self.DAMS.assign_data_product(input_resource_id=platform_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) self.addCleanup(self.DP.suspend_data_product_persistence, dp_id) #deployment creation site_obj = IonObject(RT.PlatformSite, name='sitePlatform') site_id = self.OMS.create_platform_site(platform_site=site_obj) # find current deployment using time constraints current_time = int( calendar.timegm(time.gmtime()) ) # two years on either side of current time start = current_time - 63115200 end = current_time + 63115200 temporal_bounds = IonObject(OT.TemporalBounds, name='planned', start_datetime=str(start), end_datetime=str(end)) platform_port_obj= IonObject(OT.PlatformPort, reference_designator = 'GA01SUMO-FI003-09-CTDMO0999', port_type=PortTypeEnum.UPLINK, ip_address=0) deployment_obj = IonObject(RT.Deployment, name='TestPlatformDeployment_' + name, description='some new deployment', context=IonObject(OT.CabledNodeDeploymentContext), constraint_list=[temporal_bounds], port_assignments={platform_device_id:platform_port_obj}) deploy_id = self.OMS.create_deployment(deployment=deployment_obj, site_id=site_id, device_id=platform_device_id) # assignments self.RR2.assign_platform_agent_instance_to_platform_device_with_has_agent_instance(platform_agent_instance_id, platform_device_id) self.RR2.assign_platform_agent_to_platform_agent_instance_with_has_agent_definition(platform_agent_id, platform_agent_instance_id) self.RR2.assign_platform_device_to_org_with_has_resource(platform_agent_instance_id, org_id) return platform_agent_instance_id, platform_agent_id, platform_device_id
def _make_platform_agent_structure(agent_config=None): if None is agent_config: agent_config = {} driver_config = copy.deepcopy(DVR_CONFIG) driver_config['attributes'] = self._platform_attributes[platform_id] driver_config['ports'] = self._platform_ports[platform_id] log.debug("driver_config: %s", driver_config) # instance creation platform_agent_instance_obj = any_old(RT.PlatformAgentInstance, { 'driver_config': driver_config}) platform_agent_instance_obj.agent_config = agent_config platform_agent_instance_id = self.IMS.create_platform_agent_instance(platform_agent_instance_obj) # agent creation platform_agent_obj = any_old(RT.PlatformAgent, { "stream_configurations": self._get_platform_stream_configs(), 'driver_module': DVR_MOD, 'driver_class': DVR_CLS}) platform_agent_id = self.IMS.create_platform_agent(platform_agent_obj) # device creation platform_device_id = self.IMS.create_platform_device(any_old(RT.PlatformDevice)) # data product creation dp_obj = any_old(RT.DataProduct, {"temporal_domain":tdom, "spatial_domain": sdom}) dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=self.parsed_stream_def_id) self.DAMS.assign_data_product(input_resource_id=platform_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) self.addCleanup(self.DP.delete_data_product, dp_id) # assignments self.RR2.assign_platform_agent_instance_to_platform_device_with_has_agent_instance(platform_agent_instance_id, platform_device_id) self.RR2.assign_platform_agent_to_platform_agent_instance_with_has_agent_definition(platform_agent_id, platform_agent_instance_id) self.RR2.assign_platform_device_to_org_with_has_resource(platform_agent_instance_id, self.org_id) ####################################### # dataset log.debug('data product = %s', dp_id) stream_ids, _ = self.RR.find_objects(dp_id, PRED.hasStream, None, True) log.debug('Data product stream_ids = %s', stream_ids) stream_id = stream_ids[0] # Retrieve the id of the OUTPUT stream from the out Data Product dataset_ids, _ = self.RR.find_objects(dp_id, PRED.hasDataset, RT.Dataset, True) log.debug('Data set for data_product_id1 = %s', dataset_ids[0]) ####################################### return platform_agent_instance_id, platform_agent_id, platform_device_id, stream_id
def test_resources_associations(self): """ create one of each resource and association used by MFMS to guard against problems in ion-definitions """ #raise unittest.SkipTest("https://jira.oceanobservatories.org/tasks/browse/CISWCORE-41") #stuff we control logical_instrument_id, _ = self.RR.create(any_old(RT.LogicalInstrument)) logical_platform_id, _ = self.RR.create(any_old(RT.LogicalPlatform)) logical_platform2_id, _ = self.RR.create(any_old(RT.LogicalPlatform)) marine_facility_id, _ = self.RR.create(any_old(RT.MarineFacility)) site_id, _ = self.RR.create(any_old(RT.Site)) site2_id, _ = self.RR.create(any_old(RT.Site)) #stuff we associate to instrument_agent_id, _ = self.RR.create(any_old(RT.InstrumentAgent)) platform_agent_id, _ = self.RR.create(any_old(RT.PlatformAgent)) #logical_instrument self.RR.create_association(logical_instrument_id, PRED.hasAgent, instrument_agent_id) #logical_platform self.RR.create_association(logical_platform_id, PRED.hasPlatform, logical_platform2_id) self.RR.create_association(logical_platform_id, PRED.hasInstrument, logical_instrument_id) self.RR.create_association(logical_platform_id, PRED.hasAgent, platform_agent_id) #marine_facility self.RR.create_association(marine_facility_id, PRED.hasSite, site_id) self.RR.create_association(marine_facility_id, PRED.hasPlatform, logical_platform_id) #site self.RR.create_association(site_id, PRED.hasSite, site2_id)
def _make_platform_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation platform_agent_instance_obj = any_old( RT.PlatformAgentInstance, { 'driver_config': { 'foo': 'bar' }, 'alerts': generic_alerts_config }) platform_agent_instance_obj.agent_config = agent_config platform_agent_instance_id = self.IMS.create_platform_agent_instance( platform_agent_instance_obj) # agent creation raw_config = StreamConfiguration( stream_name='raw', parameter_dictionary_name='ctd_raw_param_dict') platform_agent_obj = any_old( RT.PlatformAgent, {"stream_configurations": [raw_config]}) platform_agent_id = self.IMS.create_platform_agent( platform_agent_obj) # device creation platform_device_id = self.IMS.create_platform_device( any_old(RT.PlatformDevice)) # data product creation dp_obj = any_old(RT.DataProduct, { "temporal_domain": tdom, "spatial_domain": sdom }) dp_id = self.DP.create_data_product( data_product=dp_obj, stream_definition_id=raw_stream_def_id) self.DAMS.assign_data_product(input_resource_id=platform_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) self.addCleanup(self.DP.suspend_data_product_persistence, dp_id) # assignments self.RR2.assign_platform_agent_instance_to_platform_device_with_has_agent_instance( platform_agent_instance_id, platform_device_id) self.RR2.assign_platform_agent_to_platform_agent_instance_with_has_agent_definition( platform_agent_id, platform_agent_instance_id) self.RR2.assign_platform_device_to_org_with_has_resource( platform_agent_instance_id, org_id) return platform_agent_instance_id, platform_agent_id, platform_device_id
def create_plat_agent_instance(self, agent_id, device_id): #todo : do this for real platAgentInstance_id, _ = self.client.RR.create(any_old(RT.PlatformAgentInstance)) self.client.RR.create_association(device_id, PRED.hasAgentInstance, platAgentInstance_id) return platAgentInstance_id
def _create_instrument(self, instr_key): """ The main method to create an instrument configuration. @param instr_key A key in instruments_dict @return instrument_driver_config """ self.assertIn(instr_key, instruments_dict) self.assertNotIn(instr_key, self._setup_instruments) instr_info = instruments_dict[instr_key] log.debug("_create_instrument: creating instrument %r: %s", instr_key, instr_info) org_obj = any_old(RT.Org) log.debug("making the structure for an instrument agent") i_obj = self._make_instrument_agent_structure(instr_key, org_obj) self._setup_instruments[instr_key] = i_obj log.debug("_create_instrument: created instrument %r", instr_key) return i_obj
def test_instrument_device_metadata_notification_l4_ci_sa_rq_145_323(self): """ Instrument management shall update physical resource metadata when change occurs For example, when there is a change of state. note from maurice 2012-05-18: consider this to mean a change of stored RR data """ inst_obj = any_old(RT.InstrumentDevice) instrument_device_id, _ = self.RR.create(inst_obj) self.received_event = AsyncResult() #Create subscribers for agent and driver events. def consume_event(*args, **kwargs): self.received_event.set(True) log.info("L4-CI-SA-RQ-323") log.info("L4-CI-SA-RQ-145") event_sub = EventSubscriber(event_type="ResourceModifiedEvent", callback=consume_event) event_sub.start() inst_obj = self.RR.read(instrument_device_id) inst_obj.description = "brand new description" self.RR.update(inst_obj) #wait for event result = self.received_event.get(timeout=10) event_sub.stop() self.assertTrue(result)
def test_register_instrument_agent(self): #test ssh-ability cfg_host = CFG.service.instrument_management.driver_release_host #'amoeaba.ucsd.edu' cfg_user = pwd.getpwuid(os.getuid())[0] remotehost = "%s@%s" % (cfg_user, cfg_host) ssh_retval = subprocess.call([ "ssh", "-o", "PasswordAuthentication=no", remotehost, "-f", "true" ]) if 0 != ssh_retval: raise unittest.SkipTest("SSH/SCP credentials to %s didn't work" % remotehost) inst_agent_id = self.IMS.create_instrument_agent( any_old(RT.InstrumentAgent)) inst_model_id = self.IMS.create_instrument_model( any_old(RT.InstrumentModel)) self.IMS.assign_instrument_model_to_instrument_agent( inst_model_id, inst_agent_id) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) attachments, _ = self.RR.find_objects(inst_agent_id, PRED.hasAttachment, RT.Attachment, True) self.assertEqual(len(attachments), 4) for a_id in attachments: a = self.RR.read_attachment(a_id) parts = string.split(a.name, ".") if "txt" == parts[1]: self.assertEqual("text/plain", a.content_type) self.assertIn(parts[0], a.keywords) self.assertEqual(a.content, (parts[0] * 3) + "\n") log.info("L4-CI-SA-RQ-148") return
def _make_platform_agent_structure(agent_config=None): if None is agent_config: agent_config = {} # instance creation platform_agent_instance_obj = any_old(RT.PlatformAgentInstance) platform_agent_instance_obj.agent_config = agent_config platform_agent_instance_id = self.IMS.create_platform_agent_instance( platform_agent_instance_obj) # agent creation raw_config = StreamConfiguration( stream_name='parsed', parameter_dictionary_name='platform_eng_parsed', records_per_granule=2, granule_publish_rate=5) platform_agent_obj = any_old( RT.PlatformAgent, {"stream_configurations": [raw_config]}) platform_agent_id = self.IMS.create_platform_agent( platform_agent_obj) # device creation platform_device_id = self.IMS.create_platform_device( any_old(RT.PlatformDevice)) # data product creation dp_obj = any_old(RT.DataProduct, { "temporal_domain": tdom, "spatial_domain": sdom }) # dp_id = self.DP.create_data_product(data_product=dp_obj, stream_definition_id=raw_stream_def_id) dp_id = self.DP.create_data_product( data_product=dp_obj, stream_definition_id=self.parsed_stream_def_id) self.DAMS.assign_data_product(input_resource_id=platform_device_id, data_product_id=dp_id) self.DP.activate_data_product_persistence(data_product_id=dp_id) # assignments self.RR2.assign_platform_agent_instance_to_platform_device( platform_agent_instance_id, platform_device_id) self.RR2.assign_platform_agent_to_platform_agent_instance( platform_agent_id, platform_agent_instance_id) self.RR2.assign_platform_device_to_org_with_has_resource( platform_agent_instance_id, org_id) return platform_agent_instance_id, platform_agent_id, platform_device_id
def setUp(self): self._start_container() self._pp = pprint.PrettyPrinter() log.debug("oms_uri = %s", OMS_URI) self.oms = CIOMSClientFactory.create_instance(OMS_URI) self._get_platform_attributes() url = OmsTestMixin.start_http_server() log.info("TestPlatformInstrument:setup http url %s", url) result = self.oms.event.register_event_listener(url) log.info( "TestPlatformInstrument:setup register_event_listener result %s", result) # response = self.oms.port.get_platform_ports('LPJBox_CI_Ben_Hall') # log.info("TestPlatformInstrument:setup get_platform_ports %s", response) self.container.start_rel_from_url('res/deploy/r2deploy.yml') # Now create client to DataProductManagementService self.rrclient = ResourceRegistryServiceClient(node=self.container.node) self.pubsubclient = PubsubManagementServiceClient( node=self.container.node) self.imsclient = InstrumentManagementServiceClient( node=self.container.node) self.datasetclient = DatasetManagementServiceClient( node=self.container.node) self.processdispatchclient = ProcessDispatcherServiceClient( node=self.container.node) self.dpclient = DataProductManagementServiceClient( node=self.container.node) self.damsclient = DataAcquisitionManagementServiceClient( node=self.container.node) self.dataset_management = DatasetManagementServiceClient() self.RR2 = EnhancedResourceRegistryClient(self.rrclient) self.org_id = self.RR2.create(any_old(RT.Org)) log.debug("Org created: %s", self.org_id) # see _set_receive_timeout self._receive_timeout = 177 self.instrument_device = '' self.platform_device = '' self.platform_agent_instance_id = '' self._pa_client = '' def done(): CIOMSClientFactory.destroy_instance(self.oms) event_notifications = OmsTestMixin.stop_http_server() log.info("event_notifications = %s" % str(event_notifications)) self.addCleanup(done)
def test_data_producer(self): idevice_id = self.IMS.create_instrument_device( any_old(RT.InstrumentDevice)) self.assertEqual( 1, len( self.RR2. find_data_producer_ids_of_instrument_device_using_has_data_producer( idevice_id))) pdevice_id = self.IMS.create_platform_device(any_old( RT.PlatformDevice)) self.assertEqual( 1, len( self.RR2. find_data_producer_ids_of_platform_device_using_has_data_producer( pdevice_id)))
def setUp(self): self._start_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.DAMS = DataAcquisitionManagementServiceClient(node=self.container.node) self.DP = DataProductManagementServiceClient(node=self.container.node) self.PSC = PubsubManagementServiceClient(node=self.container.node) self.PDC = ProcessDispatcherServiceClient(node=self.container.node) self.DSC = DatasetManagementServiceClient() self.IDS = IdentityManagementServiceClient(node=self.container.node) self.RR2 = EnhancedResourceRegistryClient(self.RR) self.org_id = self.RR2.create(any_old(RT.Org)) log.debug("Org created: %s", self.org_id) # Use the network definition provided by RSN OMS directly. rsn_oms = CIOMSClientFactory.create_instance(DVR_CONFIG['oms_uri']) self._network_definition = RsnOmsUtil.build_network_definition(rsn_oms) CIOMSClientFactory.destroy_instance(rsn_oms) # get serialized version for the configuration: self._network_definition_ser = NetworkUtil.serialize_network_definition(self._network_definition) log.trace("NetworkDefinition serialization:\n%s", self._network_definition_ser) # set attributes for the platforms: self._platform_attributes = {} for platform_id in self._network_definition.pnodes: pnode = self._network_definition.pnodes[platform_id] dic = dict((attr.attr_id, attr.defn) for attr in pnode.attrs.itervalues()) self._platform_attributes[platform_id] = dic log.trace("_platform_attributes: %s", self._platform_attributes) # set ports for the platforms: self._platform_ports = {} for platform_id in self._network_definition.pnodes: pnode = self._network_definition.pnodes[platform_id] dic = {} for port_id, port in pnode.ports.iteritems(): dic[port_id] = dict(port_id=port_id, network=port.network) self._platform_ports[platform_id] = dic log.trace("_platform_ports: %s", self._platform_attributes) self._async_data_result = AsyncResult() self._data_subscribers = [] self._samples_received = [] self.addCleanup(self._stop_data_subscribers) self._async_event_result = AsyncResult() self._event_subscribers = [] self._events_received = [] self.addCleanup(self._stop_event_subscribers) self._start_event_subscriber()
def test_register_instrument_agent(self): #test ssh-ability cfg_host = CFG.service.instrument_management.driver_release_host #'amoeaba.ucsd.edu' cfg_user = pwd.getpwuid(os.getuid())[0] remotehost = "%s@%s" % (cfg_user, cfg_host) ssh_retval = subprocess.call(["ssh", "-o", "PasswordAuthentication=no", "-o", "StrictHostKeyChecking=no", remotehost, "-f", "true"]) if 0 != ssh_retval: raise unittest.SkipTest("SSH/SCP credentials to %s didn't work" % remotehost) inst_agent_id = self.IMS.create_instrument_agent(any_old(RT.InstrumentAgent)) inst_model_id = self.IMS.create_instrument_model(any_old(RT.InstrumentModel)) self.IMS.assign_instrument_model_to_instrument_agent(inst_model_id, inst_agent_id) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) attachments, _ = self.RR.find_objects(inst_agent_id, PRED.hasAttachment, RT.Attachment, True) self.assertEqual(len(attachments), 4) for a_id in attachments: a = self.RR.read_attachment(a_id) parts = string.split(a.name, ".") # we expect a.txt to contain "aaa" and have a keyword listed called "a" if "txt" == parts[1]: self.assertEqual("text/plain", a.content_type) self.assertIn(parts[0], a.keywords) self.assertEqual(a.content, str(parts[0] * 3) + "\n") log.info("L4-CI-SA-RQ-148") return
def create_data_product_obj(self): # Construct temporal and spatial Coordinate Reference System objects tdom, sdom = time_series_domain() sdom = sdom.dump() tdom = tdom.dump() # creates an IonObject of RT.DataProduct and adds custom fields specified by dict return any_old(RT.DataProduct, dict(temporal_domain=tdom, spatial_domain=sdom))
def test_get_agent_client_noprocess(self): inst_device_id = self.RR2.create(any_old(RT.InstrumentDevice)) iap = ResourceAgentClient._get_agent_process_id(inst_device_id) # should be no running agent self.assertIsNone(iap) # should raise NotFound self.assertRaises(NotFound, ResourceAgentClient, inst_device_id)
def create_under_org(resource_type, extra_fields=None): obj = any_old(resource_type, extra_fields) if RT.InstrumentDevice == resource_type: resource_id = self.IMS.create_instrument_device(obj) else: resource_id, _ = self.RR.create(obj) self.OMS.assign_resource_to_observatory_org(resource_id=resource_id, org_id=org_id) return resource_id
def test_custom_attributes(self): """ Test assignment of custom attributes """ instrument_model_id, _ = self.RR.create(any_old(RT.InstrumentModel, {"custom_attributes": {"favorite_color": "attr desc goes here"} })) instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice, {"custom_attributes": {"favorite_color": "red", "bogus_attr": "should raise warning" } })) self.IMS.assign_instrument_model_to_instrument_device(instrument_model_id, instrument_device_id) # cleanup self.IMS.force_delete_instrument_device(instrument_device_id) self.IMS.force_delete_instrument_model(instrument_model_id)
def test_activate_deployment_asymmetric_children(self): """ P0 | \ P1 P2 | I1 Complex deployment using CSP P1, P2, and P3 share the same platform model. The CSP solver should be able to work this out based on relationships to parents """ log.debug("create models") imodel_id = self.RR2.create(any_old(RT.InstrumentModel)) pmodel_id = self.RR2.create(any_old(RT.PlatformModel)) log.debug("create devices") idevice_id = self.RR2.create(any_old(RT.InstrumentDevice)) pdevice_id = [self.RR2.create(any_old(RT.PlatformDevice)) for _ in range(3)] log.debug("create sites") isite_id = self.RR2.create(any_old(RT.InstrumentSite)) psite_id = [self.RR2.create(any_old(RT.PlatformSite)) for _ in range(3)] log.debug("assign models") self.RR2.assign_instrument_model_to_instrument_device_with_has_model(imodel_id, idevice_id) self.RR2.assign_instrument_model_to_instrument_site_with_has_model(imodel_id, isite_id) for x in range(3): self.RR2.assign_platform_model_to_platform_device_with_has_model(pmodel_id, pdevice_id[x]) self.RR2.assign_platform_model_to_platform_site_with_has_model(pmodel_id, psite_id[x]) log.debug("assign hierarchy") self.RR2.assign_instrument_device_to_platform_device_with_has_device(idevice_id, pdevice_id[1]) self.RR2.assign_instrument_site_to_platform_site_with_has_site(isite_id, psite_id[1]) for x in range(1,3): self.RR2.assign_platform_device_to_platform_device_with_has_device(pdevice_id[x], pdevice_id[0]) self.RR2.assign_platform_site_to_platform_site_with_has_site(psite_id[x], psite_id[0]) log.debug("create and activate deployment") dep_id = self.RR2.create(any_old(RT.Deployment, {"context": IonObject(OT.RemotePlatformDeploymentContext)})) self.RR2.assign_deployment_to_platform_device_with_has_deployment(dep_id, pdevice_id[0]) self.RR2.assign_deployment_to_platform_site_with_has_deployment(dep_id, psite_id[0]) self.omsclient.activate_deployment(dep_id) log.debug("verifying deployment") self.assertEqual(idevice_id, self.RR2.find_instrument_device_id_of_instrument_site_using_has_device(isite_id), "The instrument device was not assigned to the instrument site") for x in range(3): self.assertEqual(pdevice_id[x], self.RR2.find_platform_device_id_of_platform_site_using_has_device(psite_id[x]), "Platform device %d was not assigned to platform site %d" % (x, x))
def test_create_bad_wrongtype(self): """ test resource creation failure for wrong type """ # get objects bad_sample_resource = any_old(RT.PlatformDevice) delattr(bad_sample_resource, "name") #configure Mock self.rr.create.return_value = ('111', 'bla') self.rr.find_resources.return_value = ([], []) self.assertRaises(BadRequest, self.RR2.create, bad_sample_resource, RT.InstrumentDevice)
def setUp(self): self._start_container() self._pp = pprint.PrettyPrinter() log.debug("oms_uri = %s", OMS_URI) self.oms = CIOMSClientFactory.create_instance(OMS_URI) self._get_platform_attributes() url = OmsTestMixin.start_http_server() log.info("TestPlatformInstrument:setup http url %s", url) result = self.oms.event.register_event_listener(url) log.info("TestPlatformInstrument:setup register_event_listener result %s", result) # response = self.oms.port.get_platform_ports('LPJBox_CI_Ben_Hall') # log.info("TestPlatformInstrument:setup get_platform_ports %s", response) self.container.start_rel_from_url('res/deploy/r2deploy.yml') # Now create client to DataProductManagementService self.rrclient = ResourceRegistryServiceClient(node=self.container.node) self.pubsubclient = PubsubManagementServiceClient(node=self.container.node) self.imsclient = InstrumentManagementServiceClient(node=self.container.node) self.datasetclient = DatasetManagementServiceClient(node=self.container.node) self.processdispatchclient = ProcessDispatcherServiceClient(node=self.container.node) self.dpclient = DataProductManagementServiceClient(node=self.container.node) self.damsclient = DataAcquisitionManagementServiceClient(node=self.container.node) self.dataset_management = DatasetManagementServiceClient() self.RR2 = EnhancedResourceRegistryClient(self.rrclient) self.org_id = self.RR2.create(any_old(RT.Org)) log.debug("Org created: %s", self.org_id) # see _set_receive_timeout self._receive_timeout = 177 self.instrument_device = '' self.platform_device = '' self.platform_agent_instance_id = '' self._pa_client = '' def done(): CIOMSClientFactory.destroy_instance(self.oms) event_notifications = OmsTestMixin.stop_http_server() log.info("event_notifications = %s" % str(event_notifications)) self.addCleanup(done)
def base_policy_exception(self, fail_fn): log.info("Create platform agent") platform_agent_obj = any_old(RT.PlatformAgent) platform_agent_id = self.client.IMS.create_platform_agent(platform_agent_obj) log.debug("executing lifecycle transition to PLANNED") self.client.IMS.execute_platform_agent_lifecycle(platform_agent_id, LCE.PLAN) log.debug("reading current revision") resource_obj = self.client.IMS.read_platform_agent(platform_agent_id) log.debug("checking current state of resource") self.assertEqual(LCS.PLANNED, resource_obj.lcstate) log.debug("executing test-specific failure check") fail_fn(platform_agent_id, LCE.DEVELOP)
def create_observatory(self, first=False, create_with_marine_facility=False): obs_id = self.create_any(RT.Observatory, first) if create_with_marine_facility: org = any_old(RT.Org) org.org_type = OrgTypeEnum.MARINE_FACILITY rsrc_id, rev = self.RR.create(org) aid = self.RR.create_association(subject=rsrc_id, predicate=PRED.hasResource, object=obs_id) site_id1 = self.create_site(first) site_id2 = self.create_site(False) self.RR.create_association(subject=obs_id, predicate=PRED.hasSite, object=site_id1) self.RR.create_association(subject=obs_id, predicate=PRED.hasSite, object=site_id2) return obs_id
def create_any(self, resourcetype, first, label=None): rsrc_id, rev = self.RR.create(any_old(resourcetype)) if label is None: label = resourcetype if first: if label in self.care: self.fail("tried to add a duplicate %s" % label) log.debug("Creating %s as %s", resourcetype, label) self.care[label] = rsrc_id self.realtype[label] = resourcetype self.assertIn(label, self.care) self.assertIn(label, self.realtype) else: if not resourcetype in self.dontcare: self.dontcare[resourcetype] = [] self.dontcare[resourcetype].append(rsrc_id) return rsrc_id
def test_l4_ci_sa_rq_139(self): """ The control services shall support resource control by another resource Instrument management shall implement resource control by another resource Subject to policy. 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: A resource here, I believe, is a "service". So I believe this is just referring to the ability of one service to call the "instrument Management Service". """ instrument_device_id = self.client.IMS.create_instrument_device(any_old(RT.InstrumentDevice)) if instrument_device_id is None: self.fail("IMS could not be called")
def base_policy_exception(self, fail_fn): log.info("Create platform agent") platform_agent_obj = any_old(RT.PlatformAgent) platform_agent_id = self.client.IMS.create_platform_agent( platform_agent_obj) log.debug("executing lifecycle transition to PLANNED") self.client.IMS.execute_platform_agent_lifecycle( platform_agent_id, LCE.PLAN) log.debug("reading current revision") resource_obj = self.client.IMS.read_platform_agent(platform_agent_id) log.debug("checking current state of resource") self.assertEqual(LCS.PLANNED, resource_obj.lcstate) log.debug("executing test-specific failure check") fail_fn(platform_agent_id, LCE.DEVELOP)
def test_l4_ci_sa_rq_139(self): """ The control services shall support resource control by another resource Instrument management shall implement resource control by another resource Subject to policy. 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: A resource here, I believe, is a "service". So I believe this is just referring to the ability of one service to call the "instrument Management Service". """ instrument_device_id = self.client.IMS.create_instrument_device( any_old(RT.InstrumentDevice)) if instrument_device_id is None: self.fail("IMS could not be called")
def test_register_instrument_agent_unit(self): # setup inst_agent_id = "iaid1" self._mock_uploader_subprocess(False) self.RR.read.return_value = any_old(RT.InstrumentAgent) self.assertRaises(BadRequest, self.IMS.register_instrument_agent, inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.read.assert_called_once_with(inst_agent_id, '') self._mock_uploader_subprocess(True) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.execute_lifecycle_transition.assert_called_once_with( inst_agent_id, LCE.INTEGRATE) remote_cred = "my_user@my_host" remote_path = "/my/remote/wwwroot/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" scp_dest = "%s:%s" % (remote_cred, remote_path) self.mock_dict["subprocess"].Popen.assert_called_any( [ "scp", "-v", "-o", "PasswordAuthentication=no", "-o", 'StrictHostKeyChecking=no', 'my_tempfile_name', scp_dest ], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.mock_dict["subprocess"].Popen.assert_called_any( ["ssh", remote_cred, "chmod", "664", remote_path], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.assertEqual(4, self.RR.create_attachment.call_count) url_content = "[InternetShortcut]\nURL=http://my_host/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" found = False for acall in self.mock_ionobj.call_args_list: if ("Attachment", ) == acall[0]: self.assertEqual(url_content, acall[1]["content"]) found = True self.assertTrue(found, "URL attachment not found")
def _create_instrument(self): """ The main method to create an instrument configuration. """ iconfig_builder = self._create_instrument_config_builder() org_obj = any_old(RT.Org) log.debug("making the structure for an instrument agent") i_obj = self._make_instrument_agent_structure(org_obj) instrument_agent_instance_obj = self.RR2.read(i_obj.instrument_agent_instance_id) log.debug("Testing instrument config") iconfig_builder.set_agent_instance_object(instrument_agent_instance_obj) instrument_config = iconfig_builder.prepare(will_launch=False) self.verify_instrument_config(instrument_config, org_obj, i_obj.instrument_device_id) self._generate_instrument_config(instrument_agent_instance_obj, i_obj.instrument_agent_instance_id) return i_obj
def test_register_instrument_agent_unit(self): # setup inst_agent_id = "iaid1" self._mock_uploader_subprocess(False) self.RR.read.return_value = any_old(RT.InstrumentAgent) self.assertRaises(BadRequest, self.IMS.register_instrument_agent, inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.read.assert_called_once_with(inst_agent_id, '') self._mock_uploader_subprocess(True) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.execute_lifecycle_transition.assert_called_once_with(inst_agent_id, LCE.INTEGRATE) remote_cred = "my_user@my_host" remote_path = "/my/remote/wwwroot/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" scp_dest = "%s:%s" % (remote_cred, remote_path) self.mock_dict["subprocess"].Popen.assert_called_any(["scp", "-v", "-o", "PasswordAuthentication=no", "-o", 'StrictHostKeyChecking=no', 'my_tempfile_name', scp_dest], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.mock_dict["subprocess"].Popen.assert_called_any(["ssh", remote_cred, "chmod", "664", remote_path], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.assertEqual(4, self.RR.create_attachment.call_count) url_content = "[InternetShortcut]\nURL=http://my_host/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" found = False for acall in self.mock_ionobj.call_args_list: if ("Attachment",) == acall[0]: self.assertEqual(url_content, acall[1]["content"]) found = True self.assertTrue(found, "URL attachment not found")
def test_l4_ci_sa_rq_161_235_336(self): instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice)) #attachments to instrument self.RR.create_attachment(instrument_device_id, IonObject(RT.Attachment, name="blah", description="blah blah", content="blah blah blah ", content_type="text/plain", keywords=["blah"], attachment_type=AttachmentType.BLOB)) attachments, _ = self.RR.find_objects(instrument_device_id, PRED.hasAttachment, RT.Attachment, True) self.assertEqual(len(attachments), 1) a = self.RR.read_attachment(attachments[0]) self.assertEqual("blah", a.name) self.assertEqual("text/plain", a.content_type) self.assertIn("blah", a.keywords) self.assertEqual(a.content, "blah " * 3) log.info("L4-CI-SA-RQ-161") log.info("L4-CI-SA-RQ-235") log.info("L4-CI-SA-RQ-336")
def test_prepare_resource_support(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_model_id, _ = self.RR.create(any_old(RT.InstrumentModel)) instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice)) 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)) instrument_device2_id, _ = self.RR.create(any_old(RT.InstrumentDevice)) instrument_device3_id, _ = self.RR.create(any_old(RT.InstrumentDevice)) platform_device2_id, _ = self.RR.create(any_old(RT.PlatformDevice)) sensor_device2_id, _ = self.RR.create(any_old(RT.SensorDevice)) #stuff we associate to data_producer_id, _ = self.RR.create(any_old(RT.DataProducer)) org_id, _ = self.RR.create(any_old(RT.Org)) #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) self.RR.create_association(org_id, PRED.hasResource, instrument_device_id) self.RR.create_association(instrument_device2_id, PRED.hasModel, instrument_model_id) self.RR.create_association(org_id, PRED.hasResource, instrument_device2_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) self.RR.create_association(platform_device2_id, PRED.hasModel, platform_model_id) self.RR.create_association(platform_device2_id, PRED.hasDevice, instrument_device2_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) self.RR.create_association(sensor_device2_id, PRED.hasModel, sensor_model_id) self.RR.create_association(sensor_device2_id, PRED.hasDevice, instrument_device2_id) sensor_model_id #is only a target #set lcstate - used for testing prepare - not setting all to DEVELOP, only some self.RR.execute_lifecycle_transition(instrument_agent_id, LCE.DEVELOP) self.RR.execute_lifecycle_transition(instrument_device_id, LCE.DEVELOP) self.RR.execute_lifecycle_transition(instrument_device2_id, LCE.DEVELOP) self.RR.execute_lifecycle_transition(platform_device_id, LCE.DEVELOP) self.RR.execute_lifecycle_transition(platform_device2_id, LCE.DEVELOP) self.RR.execute_lifecycle_transition(platform_agent_id, LCE.DEVELOP) #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") def ion_object_encoder(obj): return obj.__dict__ #First call to create instrument_data = self.IMS.prepare_instrument_device_support() #print simplejson.dumps(instrument_data, default=ion_object_encoder, indent=2) self.assertEqual(instrument_data._id, '') self.assertEqual(instrument_data.type_, OT.InstrumentDevicePrepareSupport) self.assertEqual( len(instrument_data.associations['InstrumentModel'].resources), 1) self.assertEqual( instrument_data.associations['InstrumentModel'].resources[0]._id, instrument_model_id) self.assertEqual( len(instrument_data.associations['InstrumentAgentInstance']. resources), 1) self.assertEqual( instrument_data.associations['InstrumentAgentInstance']. resources[0]._id, instrument_agent_instance_id) self.assertEqual( len(instrument_data.associations['InstrumentModel']. associated_resources), 0) self.assertEqual( len(instrument_data.associations['InstrumentAgentInstance']. associated_resources), 0) self.assertEqual( len(instrument_data.associations['SensorDevice'].resources), 0) #Next call to update instrument_data = self.IMS.prepare_instrument_device_support( instrument_device_id) #print 'Update results' #print simplejson.dumps(instrument_data, default=ion_object_encoder, indent=2) self.assertEqual(instrument_data._id, instrument_device_id) self.assertEqual(instrument_data.type_, OT.InstrumentDevicePrepareSupport) self.assertEqual( len(instrument_data.associations['InstrumentModel'].resources), 1) self.assertEqual( instrument_data.associations['InstrumentModel'].resources[0]._id, instrument_model_id) self.assertEqual( len(instrument_data.associations['InstrumentAgentInstance']. resources), 1) self.assertEqual( instrument_data.associations['InstrumentAgentInstance']. resources[0]._id, instrument_agent_instance_id) self.assertEqual( len(instrument_data.associations['InstrumentModel']. associated_resources), 1) self.assertEqual( instrument_data.associations['InstrumentModel']. associated_resources[0].s, instrument_device_id) self.assertEqual( instrument_data.associations['InstrumentModel']. associated_resources[0].o, instrument_model_id) self.assertEqual( len(instrument_data.associations['InstrumentAgentInstance']. associated_resources), 1) self.assertEqual( instrument_data.associations['InstrumentAgentInstance']. associated_resources[0].o, instrument_agent_instance_id) self.assertEqual( instrument_data.associations['InstrumentAgentInstance']. associated_resources[0].s, instrument_device_id) self.assertEqual( len(instrument_data.associations['SensorDevice'].resources), 1) self.assertEqual( instrument_data.associations['SensorDevice'].resources[0]._id, sensor_device_id) self.assertEqual( len(instrument_data.associations['SensorDevice']. associated_resources), 1) self.assertEqual( instrument_data.associations['SensorDevice']. associated_resources[0].o, instrument_device_id) self.assertEqual( instrument_data.associations['SensorDevice']. associated_resources[0].s, sensor_device_id) self.assertEqual( instrument_data.associations['InstrumentModel'].assign_request. request_parameters['instrument_device_id'], instrument_device_id) #test prepare for create of instrument agent instance instrument_agent_data = self.IMS.prepare_instrument_agent_instance_support( ) #print 'Update results' #print simplejson.dumps(instrument_agent_data, default=ion_object_encoder, indent=2) self.assertEqual(instrument_agent_data._id, '') self.assertEqual(instrument_agent_data.type_, OT.InstrumentAgentInstancePrepareSupport) self.assertEqual( len(instrument_agent_data.associations['InstrumentDevice']. resources), 2) self.assertEqual( len(instrument_agent_data.associations['InstrumentAgent'].resources ), 1) self.assertEqual( instrument_agent_data.associations['InstrumentAgent'].resources[0]. _id, instrument_agent_id) self.assertEqual( len(instrument_agent_data.associations['InstrumentDevice']. associated_resources), 0) self.assertEqual( len(instrument_agent_data.associations['InstrumentAgent']. associated_resources), 0) #test prepare for update of instrument agent instance to see if it is associated with the instrument that was created instrument_agent_data = self.IMS.prepare_instrument_agent_instance_support( instrument_agent_instance_id=instrument_agent_instance_id) #print 'Update results' #print simplejson.dumps(instrument_agent_data, default=ion_object_encoder, indent=2) self.assertEqual(instrument_agent_data._id, instrument_agent_instance_id) self.assertEqual(instrument_agent_data.type_, OT.InstrumentAgentInstancePrepareSupport) self.assertEqual( len(instrument_agent_data.associations['InstrumentDevice']. resources), 3) self.assertEqual( len(instrument_agent_data.associations['InstrumentAgent'].resources ), 1) self.assertEqual( instrument_agent_data.associations['InstrumentAgent'].resources[0]. _id, instrument_agent_id) self.assertEqual( len(instrument_agent_data.associations['InstrumentDevice']. associated_resources), 1) self.assertEqual( instrument_agent_data.associations['InstrumentDevice']. associated_resources[0].s, instrument_device_id) self.assertEqual( instrument_agent_data.associations['InstrumentDevice']. associated_resources[0].o, instrument_agent_instance_id) self.assertEqual( len(instrument_agent_data.associations['InstrumentAgent']. associated_resources), 1) self.assertEqual( instrument_agent_data.associations['InstrumentAgent']. associated_resources[0].o, instrument_agent_id) self.assertEqual( instrument_agent_data.associations['InstrumentAgent']. associated_resources[0].s, instrument_agent_instance_id) self.assertEqual( instrument_agent_data.associations['InstrumentAgent']. assign_request.request_parameters['instrument_agent_instance_id'], instrument_agent_instance_id) #test prepare for update of data product to see if it is associated with the instrument that was created data_product_data = self.DP.prepare_data_product_support( data_product_id1) #print simplejson.dumps(data_product_data, default=ion_object_encoder, indent=2) self.assertEqual(data_product_data._id, data_product_id1) self.assertEqual(data_product_data.type_, OT.DataProductPrepareSupport) self.assertEqual( len(data_product_data.associations['StreamDefinition'].resources), 1) self.assertEqual( len(data_product_data.associations['Dataset'].resources), 0) self.assertEqual( len(data_product_data.associations['StreamDefinition']. associated_resources), 1) self.assertEqual( data_product_data.associations['StreamDefinition']. associated_resources[0].s, data_product_id1) self.assertEqual( len(data_product_data.associations['Dataset'].associated_resources ), 0) self.assertEqual( len(data_product_data. associations['InstrumentDeviceHasOutputProduct'].resources), 3) self.assertEqual( len(data_product_data.associations[ 'InstrumentDeviceHasOutputProduct'].associated_resources), 1) self.assertEqual( data_product_data.associations['InstrumentDeviceHasOutputProduct']. associated_resources[0].s, instrument_device_id) self.assertEqual( data_product_data.associations['InstrumentDeviceHasOutputProduct']. associated_resources[0].o, data_product_id1) self.assertEqual( len(data_product_data.associations['PlatformDevice'].resources), 2) platform_data = self.IMS.prepare_platform_device_support() #print simplejson.dumps(platform_data, default=ion_object_encoder, indent=2) self.assertEqual(platform_data._id, '') self.assertEqual(platform_data.type_, OT.PlatformDevicePrepareSupport) self.assertEqual( len(platform_data.associations['PlatformModel'].resources), 1) self.assertEqual( platform_data.associations['PlatformModel'].resources[0]._id, platform_model_id) self.assertEqual( len(platform_data.associations['PlatformAgentInstance'].resources), 1) self.assertEqual( platform_data.associations['PlatformAgentInstance'].resources[0]. _id, platform_agent_instance_id) self.assertEqual( len(platform_data.associations['PlatformModel']. associated_resources), 0) self.assertEqual( len(platform_data.associations['PlatformAgentInstance']. associated_resources), 0) self.assertEqual( len(platform_data.associations['InstrumentDevice'].resources), 1) platform_data = self.IMS.prepare_platform_device_support( platform_device_id) #print simplejson.dumps(platform_data, default=ion_object_encoder, indent=2) self.assertEqual(platform_data._id, platform_device_id) self.assertEqual(platform_data.type_, OT.PlatformDevicePrepareSupport) self.assertEqual( len(platform_data.associations['PlatformModel'].resources), 1) self.assertEqual( platform_data.associations['PlatformModel'].resources[0]._id, platform_model_id) self.assertEqual( len(platform_data.associations['PlatformAgentInstance'].resources), 1) self.assertEqual( platform_data.associations['PlatformAgentInstance'].resources[0]. _id, platform_agent_instance_id) self.assertEqual( len(platform_data.associations['PlatformModel']. associated_resources), 1) self.assertEqual( platform_data.associations['PlatformModel']. associated_resources[0].s, platform_device_id) self.assertEqual( platform_data.associations['PlatformModel']. associated_resources[0].o, platform_model_id) self.assertEqual( len(platform_data.associations['PlatformAgentInstance']. associated_resources), 1) self.assertEqual( platform_data.associations['PlatformAgentInstance']. associated_resources[0].o, platform_agent_instance_id) self.assertEqual( platform_data.associations['PlatformAgentInstance']. associated_resources[0].s, platform_device_id) self.assertEqual( len(platform_data.associations['InstrumentDevice'].resources), 2) #self.assertEqual(len(platform_data.associations['InstrumentDevice'].associated_resources), 1) #self.assertEqual(platform_data.associations['InstrumentDevice'].associated_resources[0].s, platform_device_id) #self.assertEqual(platform_data.associations['InstrumentDevice'].associated_resources[0].o, instrument_device_id) self.assertEqual( platform_data.associations['PlatformModel'].assign_request. request_parameters['platform_device_id'], platform_device_id) # cleanup c = DotDict() c.resource_registry = self.RR self.RR2.pluck(instrument_agent_id) self.RR2.pluck(instrument_model_id) self.RR2.pluck(instrument_device_id) self.RR2.pluck(platform_agent_id) self.RR2.pluck(sensor_device_id) self.RR2.pluck(sensor_device2_id) self.IMS.force_delete_instrument_agent(instrument_agent_id) self.IMS.force_delete_instrument_model(instrument_model_id) self.IMS.force_delete_instrument_device(instrument_device_id) self.IMS.force_delete_instrument_device(instrument_device2_id) self.IMS.force_delete_platform_agent_instance( platform_agent_instance_id) self.IMS.force_delete_platform_agent(platform_agent_id) self.IMS.force_delete_platform_device(platform_device_id) self.IMS.force_delete_platform_device(platform_device2_id) self.IMS.force_delete_platform_model(platform_model_id) self.IMS.force_delete_sensor_device(sensor_device_id) self.IMS.force_delete_sensor_device(sensor_device2_id) self.IMS.force_delete_sensor_model(sensor_model_id) #stuff we associate to self.RR.delete(data_producer_id) self.RR.delete(org_id)
def test_register_instrument_agent_int(self): #test ssh-ability cfg_host = CFG.service.instrument_management.driver_release_host #'amoeaba.ucsd.edu' cfg_user = pwd.getpwuid(os.getuid())[0] if "driver_release_user" in CFG.service.instrument_management: cfg_user = CFG.service.instrument_management.driver_release_user remotehost = "%s@%s" % (cfg_user, cfg_host) ssh_retval = subprocess.call(["ssh", "-o", "PasswordAuthentication=no", "-o", "StrictHostKeyChecking=no", remotehost, "-f", "true"], stdout=open(os.devnull), stderr=open(os.devnull)) if 0 != ssh_retval: raise unittest.SkipTest("SSH/SCP credentials to %s didn't work" % remotehost) inst_agent_id = self.IMS.create_instrument_agent(any_old(RT.InstrumentAgent)) inst_model_id = self.IMS.create_instrument_model(any_old(RT.InstrumentModel)) self.IMS.assign_instrument_model_to_instrument_agent(inst_model_id, inst_agent_id) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) attachments, _ = self.RR.find_objects(inst_agent_id, PRED.hasAttachment, RT.Attachment, True) self.assertEqual(len(attachments), 4) for a_id in attachments: a = self.RR.read_attachment(a_id, include_content=True) parts = string.split(a.name, ".") # we expect a.txt to contain "aaa" and have a keyword listed called "a" if "txt" == parts[1]: self.assertEqual("text/plain", a.content_type) self.assertIn(parts[0], a.keywords) self.assertEqual(a.content, str(parts[0] * 3) + "\n") elif "text/url" == a.content_type: remote_url = a.content.split("URL=")[1] failmsg = "" try: code = urlopen(remote_url).code if 400 <= code: failmsg = "HTTP code %s" % code except Exception as e: failmsg = str(e) if failmsg: self.fail(("Uploaded succeeded, but fetching '%s' failed with '%s'. ") % (remote_url, failmsg)) log.info("L4-CI-SA-RQ-148") log.info("L4-CI-SA-RQ-148: The test services shall ensure that test results are incorporated into physical resource metadata. ") log.info("L4-CI-SA-RQ-336: Instrument activation shall support the registration of Instrument Agents") # cleanup self.IMS.force_delete_instrument_agent(inst_agent_id) self.IMS.force_delete_instrument_model(inst_model_id) return
def _setup_statuses(self): # set up according to https://docs.google.com/drawings/d/1kZ_L4xr4Be0OdqMDX6tiI50hROgvLHU4HcnD7e_NIKE/pub?w=1200z # https://confluence.oceanobservatories.org/display/syseng/CIAD+SA+OV+Observatory+Status+and+Events device_agents = {} ms = self._make_status # override the default "get agent" function and resource registyr 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 org org_id = self.OMS.create_marine_facility(any_old(RT.Org)) obs_id = self.OMS.create_observatory(any_old(RT.Observatory), org_id) # create instrument and platform devices and sites pst = dict([(i + 1, self.RR2.create(any_old(RT.PlatformSite))) for i in range(8)]) pdv = dict([(i + 1, self.RR2.create(any_old(RT.PlatformDevice))) for i in range(11)]) ist = dict([(i + 1, self.RR2.create(any_old(RT.InstrumentSite))) for i in range(6)]) idv = dict([(i + 1, self.RR2.create(any_old(RT.InstrumentDevice))) for i in range(6)]) # create associations has_site = [ (obs_id, pst[2]), (pst[2], pst[1]), (pst[1], ist[1]), (pst[2], pst[3]), (pst[3], ist[2]), (pst[3], ist[3]), (obs_id, pst[4]), (pst[4], pst[5]), (pst[4], pst[6]), (pst[6], pst[7]), (pst[7], ist[4]), (pst[6], pst[8]), (pst[8], ist[5]), (pst[8], ist[6]), ] has_device = [ (pst[2], pdv[2]), (pst[1], pdv[1]), (ist[1], idv[1]), (pst[3], pdv[3]), (pdv[3], idv[2]), (pdv[3], idv[3]), (ist[2], idv[2]), (ist[3], idv[3]), (pst[4], pdv[4]), (pdv[4], pdv[5]), (pdv[5], pdv[6]), (pdv[5], pdv[7]), (pdv[7], idv[4]), (pst[6], pdv[5]), (pst[7], pdv[6]), (pst[8], pdv[7]), (ist[5], idv[4]), (pdv[8], pdv[9]), (pdv[9], pdv[10]), (pdv[10], idv[5]), (pdv[9], pdv[11]), (pdv[11], idv[6]), ] for (s, o) in has_site: self.RR2.create_association(s, PRED.hasSite, o) self.assertIn( o, self.RR2.find_objects(s, PRED.hasSite, None, id_only=True)) for (s, o) in has_device: self.RR2.create_association(s, PRED.hasDevice, o) self.assertIn( o, self.RR2.find_objects(s, PRED.hasDevice, None, id_only=True)) self.assertEqual( pdv[1], self.RR2.find_platform_device_id_of_platform_site_using_has_device( pst[1])) # preparing to create fake agents, shortcut to status names o = DeviceStatusType.STATUS_OK w = DeviceStatusType.STATUS_WARNING c = DeviceStatusType.STATUS_CRITICAL # expected status for instruments and platforms idv_stat = ["ignore", c, o, w, o, w, c] # make the fake instrument agents, with their statuses for i, id in idv.iteritems(): idv_agent = FakeAgent() idv_agent.set_agent( "aggstatus", ms({AggregateStatusType.AGGREGATE_DATA: idv_stat[i]})) device_agents[id] = idv_agent # create fake agents for platforms pdv1_agent = FakeAgent() pdv1_agent.set_agent("aggstatus", ms()) pdv1_agent.set_agent("child_agg_status", {}) device_agents[pdv[1]] = pdv1_agent pdv2_agent = FakeAgent() pdv2_agent.set_agent( "aggstatus", ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING })) pdv2_agent.set_agent("child_agg_status", {}) device_agents[pdv[2]] = pdv2_agent pdv3_agent = FakeAgent() pdv3_agent.set_agent("aggstatus", ms()) pdv3_agent.set_agent( "child_agg_status", { idv[2]: ms(), idv[3]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING }), }) device_agents[pdv[3]] = pdv3_agent pdv4_agent = FakeAgent() pdv4_agent.set_agent("aggstatus", ms()) pdv4_agent.set_agent( "child_agg_status", { pdv[5]: ms(), pdv[6]: ms(), pdv[7]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING }), idv[4]: ms(), }) device_agents[pdv[4]] = pdv4_agent pdv5_agent = FakeAgent() pdv5_agent.set_agent("aggstatus", ms()) pdv5_agent.set_agent( "child_agg_status", { pdv[6]: ms(), pdv[7]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING }), idv[4]: ms(), }) device_agents[pdv[5]] = pdv5_agent pdv6_agent = FakeAgent() pdv6_agent.set_agent("aggstatus", ms()) pdv6_agent.set_agent("child_agg_status", {}) device_agents[pdv[6]] = pdv6_agent pdv7_agent = FakeAgent() pdv7_agent.set_agent( "aggstatus", ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING })) pdv7_agent.set_agent("child_agg_status", { idv[4]: ms(), }) device_agents[pdv[7]] = pdv7_agent pdv8_agent = FakeAgent() pdv8_agent.set_agent("aggstatus", ms()) pdv8_agent.set_agent( "child_agg_status", { pdv[9]: ms(), pdv[10]: ms(), idv[5]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING }), pdv[11]: ms(), idv[6]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_CRITICAL }), }) device_agents[pdv[8]] = pdv8_agent pdv9_agent = FakeAgent() pdv9_agent.set_agent("aggstatus", ms()) pdv9_agent.set_agent( "child_agg_status", { pdv[10]: ms(), idv[5]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING }), pdv[11]: ms(), idv[6]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_CRITICAL }), }) device_agents[pdv[9]] = pdv9_agent pdv10_agent = FakeAgent() pdv10_agent.set_agent("aggstatus", ms()) pdv10_agent.set_agent( "child_agg_status", { idv[5]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING }), }) device_agents[pdv[10]] = pdv10_agent pdv11_agent = FakeAgent() pdv11_agent.set_agent("aggstatus", ms()) pdv11_agent.set_agent( "child_agg_status", { idv[6]: ms({ AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_CRITICAL }), }) device_agents[pdv[8]] = pdv11_agent self.device_agents = device_agents self.IMS_ASB._get_agent_client = self.my_get_agent_client self.OMS_ASB._get_agent_client = self.my_get_agent_client # save created ids self.org_id = org_id self.obs_id = obs_id self.pst = pst self.pdv = pdv self.ist = ist self.idv = idv log.info("org ID: %s", org_id) log.info("observatory ID: %s", obs_id) for k, v in self.pst.iteritems(): log.info("platform site ID %s: %s", k, v) for k, v in self.ist.iteritems(): log.info("instrument site ID %s: %s", k, v) for k, v in self.pdv.iteritems(): log.info("platform device ID %s: %s", k, v) for k, v in self.idv.iteritems(): log.info("instrument device ID %s: %s", k, v)
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_model_id, _ = self.RR.create(any_old(RT.InstrumentModel)) instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice)) instrument_site_id, _ = self.RR.create(any_old(RT.InstrumentSite)) platform_agent_instance_id, _ = self.RR.create( any_old(RT.PlatformAgentInstance)) platform_agent_id, _ = self.RR.create(any_old(RT.PlatformAgent)) platform_site_id, _ = self.RR.create(any_old(RT.PlatformSite)) 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)) org_id, _ = self.RR.create(any_old(RT.Org)) #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) self.RR.create_association(org_id, PRED.hasResource, instrument_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) self.RR.create_association(instrument_site_id, PRED.hasDevice, instrument_device_id) self.RR.create_association(platform_site_id, PRED.hasDevice, platform_device_id) self.RR.create_association(platform_site_id, PRED.hasSite, instrument_site_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 #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), 5) self.assertEquals( set(extended_instrument.lcstate_transitions.keys()), set(['develop', 'deploy', 'retire', 'plan', 'integrate'])) 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) #compound assoc return list of lists so check the first element self.assertEqual(inst_agent_obj.name, extended_instrument.instrument_agent.name) #check platform device plat_device_obj = self.RR.read(platform_device_id) self.assertEqual(plat_device_obj.name, extended_instrument.platform_device.name) extended_platform = self.IMS.get_platform_device_extension( platform_device_id) self.assertEqual(1, len(extended_platform.portals)) self.assertEqual(1, len(extended_platform.portal_instruments)) #self.assertEqual(1, len(extended_platform.computed.portal_status.value)) # no agent started so NO statuses reported self.assertEqual(1, len(extended_platform.instrument_devices)) self.assertEqual(instrument_device_id, extended_platform.instrument_devices[0]._id) self.assertEqual(1, len(extended_platform.instrument_models)) self.assertEqual(instrument_model_id, extended_platform.instrument_models[0]._id) self.assertEquals(extended_platform.platform_agent._id, platform_agent_id) self.assertEquals(len(extended_platform.lcstate_transitions), 5) self.assertEquals( set(extended_platform.lcstate_transitions.keys()), set(['develop', 'deploy', 'retire', 'plan', 'integrate'])) self.assertEquals(len(extended_platform.availability_transitions), 2) self.assertEquals( set(extended_platform.availability_transitions.keys()), set(['enable', 'announce'])) #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']) #none of these will work because there is no agent # self.assertEqual(ComputedValueAvailability.NOTAVAILABLE, # extended_instrument.computed.firmware_version.status) # self.assertEqual(ComputedValueAvailability.NOTAVAILABLE, # extended_instrument.computed.operational_state.status) # self.assertEqual(ComputedValueAvailability.PROVIDED, # extended_instrument.computed.power_status_roll_up.status) # self.assertEqual(ComputedValueAvailability.PROVIDED, # extended_instrument.computed.communications_status_roll_up.status) # self.assertEqual(ComputedValueAvailability.PROVIDED, # extended_instrument.computed.data_status_roll_up.status) # self.assertEqual(DeviceStatusType.STATUS_OK, # extended_instrument.computed.data_status_roll_up.value) # self.assertEqual(ComputedValueAvailability.PROVIDED, # extended_instrument.computed.location_status_roll_up.status) # self.assertEqual(ComputedValueAvailability.PROVIDED, # extended_instrument.computed.recent_events.status) # self.assertEqual([], extended_instrument.computed.recent_events.value) # cleanup c = DotDict() c.resource_registry = self.RR self.RR2.pluck(instrument_agent_id) self.RR2.pluck(instrument_model_id) self.RR2.pluck(instrument_device_id) self.RR2.pluck(platform_agent_id) self.RR2.pluck(sensor_device_id) self.IMS.force_delete_instrument_agent(instrument_agent_id) self.IMS.force_delete_instrument_model(instrument_model_id) self.IMS.force_delete_instrument_device(instrument_device_id) self.IMS.force_delete_platform_agent_instance( platform_agent_instance_id) self.IMS.force_delete_platform_agent(platform_agent_id) self.OMS.force_delete_instrument_site(instrument_site_id) self.OMS.force_delete_platform_site(platform_site_id) self.IMS.force_delete_platform_device(platform_device_id) self.IMS.force_delete_platform_model(platform_model_id) self.IMS.force_delete_sensor_device(sensor_device_id) self.IMS.force_delete_sensor_model(sensor_model_id) #stuff we associate to self.RR.delete(data_producer_id) self.RR.delete(org_id)
def sample_resource(self): return any_old(RT.InstrumentDevice)
def test_find_subjects_using_ionobj(self): obj = any_old(RT.InstrumentDevice) setattr(obj, "_id", "foo_id") self.tbase_find_subjects(obj)
def base_3x3_matchups(self, deployment_context): """ This will be 1 root platform, 3 sub platforms (2 of one model, 1 of another) and 3 sub instruments each (2-to-1) """ deployment_context_type = type(deployment_context).__name__ instrument_model_id = [self.RR2.create(any_old(RT.InstrumentModel)) for _ in range(6)] platform_model_id = [self.RR2.create(any_old(RT.PlatformModel)) for _ in range(3)] instrument_device_id = [self.RR2.create(any_old(RT.InstrumentDevice)) for _ in range(9)] platform_device_id = [self.RR2.create(any_old(RT.PlatformDevice)) for _ in range(4)] instrument_site_id = [self.RR2.create(any_old(RT.InstrumentSite, {"planned_uplink_port": IonObject(OT.PlatformPort, reference_designator="instport_%d" % (i+1))})) for i in range(9)] platform_site_id = [self.RR2.create(any_old(RT.PlatformSite, {"planned_uplink_port": IonObject(OT.PlatformPort, reference_designator="platport_%d" % (i+1))})) for i in range(4)] def instrument_model_at(platform_idx, instrument_idx): m = platform_idx * 2 if instrument_idx > 0: m += 1 return m def platform_model_at(platform_idx): if platform_idx > 0: return 1 return 0 def instrument_at(platform_idx, instrument_idx): return platform_idx * 3 + instrument_idx # set up the structure for p in range(3): m = platform_model_at(p) self.RR2.assign_platform_model_to_platform_site_with_has_model(platform_model_id[m], platform_site_id[p]) self.RR2.assign_platform_model_to_platform_device_with_has_model(platform_model_id[m], platform_device_id[p]) self.RR2.assign_platform_device_to_platform_device_with_has_device(platform_device_id[p], platform_device_id[3]) self.RR2.assign_platform_site_to_platform_site_with_has_site(platform_site_id[p], platform_site_id[3]) for i in range(3): m = instrument_model_at(p, i) idx = instrument_at(p, i) self.RR2.assign_instrument_model_to_instrument_site_with_has_model(instrument_model_id[m], instrument_site_id[idx]) self.RR2.assign_instrument_model_to_instrument_device_with_has_model(instrument_model_id[m], instrument_device_id[idx]) self.RR2.assign_instrument_device_to_platform_device_with_has_device(instrument_device_id[idx], platform_device_id[p]) self.RR2.assign_instrument_site_to_platform_site_with_has_site(instrument_site_id[idx], platform_site_id[p]) # top level models self.RR2.assign_platform_model_to_platform_device_with_has_model(platform_model_id[2], platform_device_id[3]) self.RR2.assign_platform_model_to_platform_site_with_has_model(platform_model_id[2], platform_site_id[3]) # verify structure for p in range(3): parent_id = self.RR2.find_platform_device_id_by_platform_device_using_has_device(platform_device_id[p]) self.assertEqual(platform_device_id[3], parent_id) parent_id = self.RR2.find_platform_site_id_by_platform_site_using_has_site(platform_site_id[p]) self.assertEqual(platform_site_id[3], parent_id) for i in range(len(platform_site_id)): self.assertEqual(self.RR2.find_platform_model_of_platform_device_using_has_model(platform_device_id[i]), self.RR2.find_platform_model_of_platform_site_using_has_model(platform_site_id[i])) for i in range(len(instrument_site_id)): self.assertEqual(self.RR2.find_instrument_model_of_instrument_device_using_has_model(instrument_device_id[i]), self.RR2.find_instrument_model_of_instrument_site_using_has_model(instrument_site_id[i])) port_assignments = {} for p in range(3): port_assignments[platform_device_id[p]] = "platport_%d" % (p+1) for i in range(3): idx = instrument_at(p, i) port_assignments[instrument_device_id[idx]] = "instport_%d" % (idx+1) deployment_id = self.RR2.create(any_old(RT.Deployment, {"context": deployment_context, "port_assignments": port_assignments})) log.debug("assigning device/site to %s deployment", deployment_context_type) if OT.RemotePlatformDeploymentContext == deployment_context_type: self.RR2.assign_deployment_to_platform_device_with_has_deployment(deployment_id, platform_device_id[3]) self.RR2.assign_deployment_to_platform_site_with_has_deployment(deployment_id, platform_site_id[3]) elif OT.CabledInstrumentDeploymentContext == deployment_context_type: self.RR2.assign_deployment_to_instrument_device_with_has_deployment(deployment_id, instrument_device_id[1]) self.RR2.assign_deployment_to_instrument_site_with_has_deployment(deployment_id, instrument_site_id[1]) elif OT.CabledNodeDeploymentContext == deployment_context_type: self.RR2.assign_deployment_to_platform_device_with_has_deployment(deployment_id, platform_device_id[1]) self.RR2.assign_deployment_to_platform_site_with_has_deployment(deployment_id, platform_site_id[1]) log.debug("activation of %s deployment", deployment_context_type) self.omsclient.activate_deployment(deployment_id) log.debug("validation of %s deployment", deployment_context_type) if OT.RemotePlatformDeploymentContext == deployment_context_type: # verify proper associations for i, d in enumerate(platform_device_id): self.assertEqual(d, self.RR2.find_platform_device_id_of_platform_site_using_has_device(platform_site_id[i])) for i, d in enumerate(instrument_device_id): self.assertEqual(d, self.RR2.find_instrument_device_id_of_instrument_site_using_has_device(instrument_site_id[i])) elif OT.CabledInstrumentDeploymentContext == deployment_context_type: self.assertEqual(instrument_device_id[1], self.RR2.find_instrument_device_id_of_instrument_site_using_has_device(instrument_site_id[1])) elif OT.CabledNodeDeploymentContext == deployment_context_type: expected_platforms = [1] expected_instruments = [3, 4, 5] # verify proper associations for i, d in enumerate(platform_device_id): self.assertEqual(i in expected_platforms, d in self.RR2.find_platform_device_ids_of_platform_site_using_has_device(platform_site_id[i])) for i, d in enumerate(instrument_device_id): self.assertEqual(i in expected_instruments, d in self.RR2.find_instrument_device_ids_of_instrument_site_using_has_device(instrument_site_id[i]))