def test_observatory_structure(self): """ """ c = self.client c2 = DotDict() c2.resource_registry = self.client.RR #generate a function that finds direct associations, using the more complex one in the service def gen_find_oms_association(output_type): def freeze(): def finder_fun(obj_id): log.debug("Finding related %s frames", output_type) ret = c.OMS.find_related_frames_of_reference(obj_id, [output_type]) return ret[output_type] return finder_fun return freeze() ############################################### # # Assumptions or Order of Events for R2 Preloaded resources # # - orgs # - sites # - models # - agents # - devices # - instances # - attachments # ############################################### ############################################### # # orgs # ############################################### org_id = self.client.OMS.create_marine_facility(any_old(RT.Org)) def add_to_org_fn(generic_resource_id): log.info("Associating with Org") self.client.OMS.assign_resource_to_observatory_org(generic_resource_id, org_id) ############################################### # # sites # ############################################### log.info("Create an observatory") observatory_id = self.perform_fcruf_script(RT.Observatory, "observatory", self.client.OMS, actual_obj=None, extra_fn=add_to_org_fn) log.info("Create a subsite") subsite_id = self.perform_fcruf_script(RT.Subsite, "subsite", self.client.OMS, actual_obj=None, extra_fn=add_to_org_fn) log.info("Create a platform site") platform_site_id = self.perform_fcruf_script(RT.PlatformSite, "platform_site", self.client.OMS, actual_obj=None, extra_fn=add_to_org_fn) log.info("Create instrument site") instSite_obj = IonObject(RT.InstrumentSite, name="instrument_site", reference_designator="GA01SUMO-FI003-01-CTDMO0999") instrument_site_id = self.perform_fcruf_script(RT.InstrumentSite, "instrument_site", self.client.OMS, actual_obj=instSite_obj, extra_fn=add_to_org_fn) ############################################### # # models # ############################################### log.info("Create a platform model") platform_model_id = self.perform_fcruf_script(RT.PlatformModel, "platform_model", self.client.IMS) log.info("Create instrument model") instModel_obj = IonObject(RT.InstrumentModel, name='SBE37IMModel', description="SBE37IMModel", custom_attributes= {'streams':{'raw': 'ctd_raw_param_dict' , 'parsed': 'ctd_parsed_param_dict' }}) instrument_model_id = self.perform_fcruf_script(RT.InstrumentModel, "instrument_model", self.client.IMS, actual_obj=instModel_obj) log.info("Create sensor model") sensor_model_id = self.perform_fcruf_script(RT.SensorModel, "sensor_model", self.client.IMS) ############################################### # # agents # ############################################### log.info("Create platform agent") platform_agent_id = self.perform_fcruf_script(RT.PlatformAgent, "platform_agent", self.client.IMS) log.info("Create instrument agent") instAgent_obj = IonObject(RT.InstrumentAgent, name='agent007', description="SBE37IMAgent", driver_uri=DRV_URI_GOOD) instrument_agent_id = self.perform_fcruf_script(RT.InstrumentAgent, "instrument_agent", self.client.IMS, actual_obj=instAgent_obj) ############################################### # # devices # ############################################### log.info("Create a platform device") platform_device_id = self.perform_fcruf_script(RT.PlatformDevice, "platform_device", self.client.IMS, actual_obj=None, extra_fn=add_to_org_fn) log.info("Create an instrument device") instrument_device_id = self.perform_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, actual_obj=None, extra_fn=add_to_org_fn) log.info("Create a sensor device") sensor_device_id = self.perform_fcruf_script(RT.SensorDevice, "sensor_device", self.client.IMS, actual_obj=None, extra_fn=add_to_org_fn) ############################################### # # instances # ############################################### # we create instrument agent instance below, to verify some lcs checks ############################################### # # # attachments and LCS stuff # # ############################################### #---------------------------------------------- # # orgs # #---------------------------------------------- #---------------------------------------------- # # sites # #---------------------------------------------- log.info("Associate subsite with observatory") self.perform_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Observatory), gen_find_oms_association(RT.Subsite), observatory_id, subsite_id) log.info("Associate platform site with subsite") self.perform_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Subsite), gen_find_oms_association(RT.PlatformSite), subsite_id, platform_site_id) log.info("Associate instrument site with platform site") self.perform_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.PlatformSite), gen_find_oms_association(RT.InstrumentSite), platform_site_id, instrument_site_id) #---------------------------------------------- # # models # #---------------------------------------------- log.info("Associate platform model with platform site") self.perform_association_script(c.OMS.assign_platform_model_to_platform_site, self.RR2.find_platform_sites_by_platform_model_using_has_model, self.RR2.find_platform_models_of_platform_site_using_has_model, platform_site_id, platform_model_id) log.info("Associate instrument model with instrument site") self.perform_association_script(c.OMS.assign_instrument_model_to_instrument_site, self.RR2.find_instrument_sites_by_instrument_model_using_has_model, self.RR2.find_instrument_models_of_instrument_site_using_has_model, instrument_site_id, instrument_model_id) #---------------------------------------------- # # agents # # - model required for DEVELOP # - egg required for INTEGRATE # - certification required for DEPLOY #---------------------------------------------- self.assert_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.PLAN, LCS.PLANNED) self.assert_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP) log.info("Associate platform model with platform agent") self.perform_association_script(c.IMS.assign_platform_model_to_platform_agent, self.RR2.find_platform_agents_by_platform_model_using_has_model, self.RR2.find_platform_models_of_platform_agent_using_has_model, platform_agent_id, platform_model_id) self.assert_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.assert_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.EGG_URL]) self.assert_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.assert_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.CERTIFICATION, "platform attachment"]) self.assert_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY, LCS.DEPLOYED) self.assert_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.PLAN, LCS.PLANNED) self.assert_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP) log.info("Associate instrument model with instrument agent") self.perform_association_script(c.IMS.assign_instrument_model_to_instrument_agent, c.IMS.find_instrument_agent_by_instrument_model, c.IMS.find_instrument_model_by_instrument_agent, instrument_agent_id, instrument_model_id) self.assert_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.assert_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.EGG_URL]) self.assert_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.assert_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.CERTIFICATION]) self.assert_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY, LCS.DEPLOYED) #---------------------------------------------- # # devices # #---------------------------------------------- log.info("LCS plan") self.assert_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.PLAN, LCS.PLANNED) log.info("LCS develop") self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) x = self.client.IMS.read_platform_device(platform_device_id) x.serial_number = "12345" self.client.IMS.update_platform_device(x) self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) log.info("Associate platform model with platform device") self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) self.perform_association_script(c.IMS.assign_platform_model_to_platform_device, c.IMS.find_platform_device_by_platform_model, c.IMS.find_platform_model_by_platform_device, platform_device_id, platform_model_id) self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) add_keyworded_attachment(self.client.RR, platform_device_id, [KeywordFlag.VENDOR_TEST_RESULTS]) self.assert_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP, LCS.DEVELOPED) log.info("LCS integrate") self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_device_id, [KeywordFlag.VENDOR_TEST_RESULTS]) self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) platform_agent_instance_id = self.create_plat_agent_instance(platform_agent_id, platform_device_id) self.assert_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE, LCS.INTEGRATED) log.info("LCS deploy") self.assert_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEPLOY) log.info("LCS plan") self.assert_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.PLAN, LCS.PLANNED) log.info("LCS develop") self.assert_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP) x = self.client.IMS.read_instrument_device(instrument_device_id) x.serial_number = "12345" self.client.IMS.update_instrument_device(x) self.assert_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP) log.info("Associate instrument model with instrument device") self.perform_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id, instrument_model_id) self.assert_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP) add_keyworded_attachment(self.client.RR, instrument_device_id, [KeywordFlag.VENDOR_TEST_RESULTS]) self.assert_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP, LCS.DEVELOPED) log.info("LCS integrate") self.assert_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.INTEGRATE) log.info("Associate instrument device with platform device") self.perform_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id) self.assert_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.INTEGRATE) log.info("Create instrument agent instance") instrument_agent_instance_id = self.create_inst_agent_instance(instrument_agent_id, instrument_device_id) self.assert_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.INTEGRATE, LCS.INTEGRATED) log.info("LCS deploy") self.assert_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEPLOY) log.info("Associate sensor model with sensor device") self.perform_association_script(c.IMS.assign_sensor_model_to_sensor_device, self.RR2.find_sensor_devices_by_sensor_model_using_has_model, self.RR2.find_sensor_models_of_sensor_device_using_has_model, sensor_device_id, sensor_model_id) log.info("Associate sensor device with instrument device") self.perform_association_script(c.IMS.assign_sensor_device_to_instrument_device, self.RR2.find_instrument_devices_by_sensor_device_using_has_device, self.RR2.find_sensor_devices_of_instrument_device_using_has_device, instrument_device_id, sensor_device_id) #---------------------------------------------- # # instances # #---------------------------------------------- #---------------------------------------------- # # data production chain and swapping # #---------------------------------------------- #------------------------------------------------------------------------------------------------ # create a stream definition for the data from the ctd simulator #------------------------------------------------------------------------------------------------ pdict_id = self.dataset_management.read_parameter_dictionary_by_name('ctd_parsed_param_dict', id_only=True) ctd_stream_def_id = self.client.PSMS.create_stream_definition(name='Simulated CTD data', parameter_dictionary_id=pdict_id) log.debug("Created stream def id %s", ctd_stream_def_id) #create data products for instrument data dp_obj = self.create_data_product_obj() #log.debug("Created an IonObject for a data product: %s", dp_obj) #------------------------------------------------------------------------------------------------ # Create a set of ParameterContext objects to define the parameters in the coverage, add each to the ParameterDictionary #------------------------------------------------------------------------------------------------ dp_obj.name = 'Data Product' inst_data_product_id = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id) #assign data products appropriately c.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=inst_data_product_id) port_assignments={} pp_obj = IonObject(OT.PlatformPort, reference_designator='GA01SUMO-FI003-01-CTDMO0999', port_type= PortTypeEnum.PAYLOAD, ip_address='1' ) port_assignments[instrument_device_id] = pp_obj deployment_obj = IonObject(RT.Deployment, name='deployment', port_assignments=port_assignments, context=IonObject(OT.CabledNodeDeploymentContext)) deployment_id = self.perform_fcruf_script(RT.Deployment, "deployment", c.OMS, actual_obj=deployment_obj, extra_fn=add_to_org_fn) c.OMS.assign_site_to_deployment(platform_site_id, deployment_id) self.RR2.find_deployment_id_of_platform_site_using_has_deployment(platform_site_id) c.OMS.assign_device_to_deployment(platform_device_id, deployment_id) self.RR2.find_deployment_of_platform_device_using_has_deployment(platform_device_id) c.OMS.activate_deployment(deployment_id, True) self.assertLess(0, len(self.RR2.find_instrument_sites_by_instrument_device_using_has_device(instrument_device_id))) self.assertLess(0, len(self.RR2.find_instrument_devices_of_instrument_site_using_has_device(instrument_site_id))) self.assertLess(0, len(self.RR2.find_platform_sites_by_platform_device_using_has_device(platform_device_id))) self.assertLess(0, len(self.RR2.find_platform_devices_of_platform_site_using_has_device(platform_site_id))) self.assert_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.DEPLOY, LCS.DEPLOYED) self.assert_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEPLOY, LCS.DEPLOYED) idev_lcs = self.client.RR.read(instrument_device_id).lcstate log.info("L4-CI-SA-RQ-334 DEPLOY: Proposed change - Instrument activation shall support transition to " + "the active state for instruments - state is %s" % idev_lcs) #now along comes a new device log.info("Create instrument device 2") instrument_device_id2 = self.perform_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, actual_obj=None, extra_fn=add_to_org_fn) log.info("Associate instrument model with instrument device 2") self.perform_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id2, instrument_model_id) log.info("Associate instrument device with platform device 2") self.perform_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id2) dp_obj.name = 'Instrument Data Product 2' inst_data_product_id2 = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id) c.DAMS.assign_data_product(input_resource_id=instrument_device_id2, data_product_id=inst_data_product_id2) # create a new deployment for the new device deployment_obj = any_old(RT.Deployment, {"context": IonObject(OT.CabledNodeDeploymentContext)}) deployment_id2 = self.perform_fcruf_script(RT.Deployment, "deployment", c.OMS, actual_obj=deployment_obj, extra_fn=add_to_org_fn) log.debug("Associating instrument site with new deployment") c.OMS.assign_site_to_deployment(instrument_site_id, deployment_id2) log.debug("Associating instrument device with new deployment") c.OMS.assign_device_to_deployment(instrument_device_id2, deployment_id2) # activate the new deployment -- changing the primary device -- but don't switch subscription log.debug("Activating new deployment") c.OMS.activate_deployment(deployment_id2, False) #todo: assert site hasDevice instrument_device_id2 assocs = self.client.RR.find_associations(instrument_site_id, PRED.hasDevice, instrument_device_id2, id_only=True) self.assertIsNotNone(assocs) #---------------------------------------------- # # generic find ops # #---------------------------------------------- log.info("Find an instrument site by observatory") entities = c.OMS.find_related_frames_of_reference(observatory_id, [RT.InstrumentSite]) self.assertIn(RT.InstrumentSite, entities) inst_sites = entities[RT.InstrumentSite] self.assertEqual(1, len(inst_sites)) self.assertEqual(instrument_site_id, inst_sites[0]._id) c.IMS.delete_instrument_agent(instrument_agent_id) instr_agent_obj_read = self.client.RR.read(instrument_agent_id) self.assertEquals(instr_agent_obj_read.lcstate, LCS.DELETED) log.info("L4-CI-SA-RQ-382: Instrument activation shall manage the life cycle of Instrument Agents") c.IMS.delete_instrument_device(instrument_device_id) # Check whether the instrument device has been retired instrument_obj_read = self.client.RR.read(instrument_device_id) log.debug("The instruments lcs state has been set to %s after the delete operation" % instrument_obj_read.lcstate) self.assertEquals(instrument_obj_read.lcstate, LCS.DELETED) log.debug("L4-CI-SA-RQ-334 DELETED") log.debug("L4-CI-SA-RQ-335: Instrument activation shall support transition to the retired state of instruments") #---------------------------------------------- # # force_deletes # #---------------------------------------------- # need to "pluck" some resources out of associations self.RR2.pluck(instrument_model_id) self.RR2.pluck(platform_model_id) self.RR2.pluck(instrument_agent_id) self.RR2.pluck(platform_agent_id) self.RR2.pluck(deployment_id) self.RR2.pluck(deployment_id2) self.perform_fd_script(observatory_id, "observatory", c.OMS) self.perform_fd_script(subsite_id, "subsite", c.OMS) self.perform_fd_script(platform_site_id, "platform_site", c.OMS) self.perform_fd_script(instrument_site_id, "instrument_site", c.OMS) self.perform_fd_script(platform_model_id, "platform_model", c.IMS) self.perform_fd_script(instrument_model_id, "instrument_model", c.IMS) self.perform_fd_script(platform_agent_id, "platform_agent", c.IMS) self.perform_fd_script(instrument_agent_id, "instrument_agent", c.IMS) self.perform_fd_script(platform_device_id, "platform_device", c.IMS) self.perform_fd_script(instrument_device_id, "instrument_device", c.IMS) self.perform_fd_script(sensor_device_id, "sensor_device", c.IMS) self.perform_fd_script(sensor_model_id, "sensor_model", c.IMS) self.perform_fd_script(platform_agent_instance_id, "platform_agent_instance", c.IMS) self.perform_fd_script(instrument_agent_instance_id, "instrument_agent_instance", c.IMS) self.perform_fd_script(deployment_id, "deployment", c.OMS) self.perform_fd_script(deployment_id2, "deployment", c.OMS)
def test_observatory_structure(self): c = self.client c2 = DotDict() c2.resource_registry = self.client.RR instrument_site_impl = InstrumentSiteImpl(c2) platform_site_impl = PlatformSiteImpl(c2) platform_agent_impl = PlatformAgentImpl(c2) instrument_device_impl = InstrumentDeviceImpl(c2) sensor_device_impl = SensorDeviceImpl(c2) #generate a function that finds direct associations, using the more complex one in the service def gen_find_oms_association(output_type): def freeze(): def finder_fun(obj_id): ret = c.OMS.find_related_frames_of_reference( obj_id, [output_type]) return ret[output_type] return finder_fun return freeze() #resource_ids = self._low_level_init() ############################################### # # Assumptions or Order of Events for R2 Preloaded resources # # - orgs # - sites # - models # - agents # - devices # - instances # - attachments # ############################################### ############################################### # # orgs # ############################################### ############################################### # # sites # ############################################### log.info("Create an observatory") observatory_id = self.generic_fcruf_script(RT.Observatory, "observatory", self.client.OMS, True) log.info("Create a subsite") subsite_id = self.generic_fcruf_script(RT.Subsite, "subsite", self.client.OMS, True) log.info("Create a platform site") platform_site_id = self.generic_fcruf_script(RT.PlatformSite, "platform_site", self.client.OMS, True) log.info("Create instrument site") instrument_site_id = self.generic_fcruf_script(RT.InstrumentSite, "instrument_site", self.client.OMS, True) ############################################### # # models # ############################################### log.info("Create a platform model") platform_model_id = self.generic_fcruf_script(RT.PlatformModel, "platform_model", self.client.IMS, True) log.info("Create instrument model") instrument_model_id = self.generic_fcruf_script( RT.InstrumentModel, "instrument_model", self.client.IMS, True) log.info("Create sensor model") sensor_model_id = self.generic_fcruf_script(RT.SensorModel, "sensor_model", self.client.IMS, True) ############################################### # # agents # ############################################### log.info("Create platform agent") platform_agent_id = self.generic_fcruf_script(RT.PlatformAgent, "platform_agent", self.client.IMS, False) log.info("Create instrument agent") instrument_agent_id = self.generic_fcruf_script( RT.InstrumentAgent, "instrument_agent", self.client.IMS, False) ############################################### # # devices # ############################################### log.info("Create a platform device") platform_device_id = self.generic_fcruf_script(RT.PlatformDevice, "platform_device", self.client.IMS, False) log.info("Create an instrument device") instrument_device_id = self.generic_fcruf_script( RT.InstrumentDevice, "instrument_device", self.client.IMS, False) log.info("Create a sensor device") sensor_device_id = self.generic_fcruf_script(RT.SensorDevice, "sensor_device", self.client.IMS, False) ############################################### # # instances # ############################################### ############################################### # # # attachments and LCS stuff # # ############################################### #---------------------------------------------- # # orgs # #---------------------------------------------- #---------------------------------------------- # # sites # #---------------------------------------------- log.info("Associate subsite with observatory") self.generic_association_script( c.OMS.assign_site_to_site, gen_find_oms_association(RT.Observatory), gen_find_oms_association(RT.Subsite), observatory_id, subsite_id) log.info("Associate platform site with subsite") self.generic_association_script( c.OMS.assign_site_to_site, gen_find_oms_association(RT.Subsite), gen_find_oms_association(RT.PlatformSite), subsite_id, platform_site_id) log.info("Associate instrument site with platform site") self.generic_association_script( c.OMS.assign_site_to_site, gen_find_oms_association(RT.PlatformSite), gen_find_oms_association(RT.InstrumentSite), platform_site_id, instrument_site_id) #---------------------------------------------- # # models # #---------------------------------------------- log.info("Associate platform model with platform site") self.generic_association_script( c.OMS.assign_platform_model_to_platform_site, platform_site_impl.find_having_model, platform_site_impl.find_stemming_model, platform_site_id, platform_model_id) log.info("Associate instrument model with instrument site") self.generic_association_script( c.OMS.assign_instrument_model_to_instrument_site, instrument_site_impl.find_having_model, instrument_site_impl.find_stemming_model, instrument_site_id, instrument_model_id) #---------------------------------------------- # # agents # # - model required for DEVELOP # - egg required for INTEGRATE # - certification required for DEPLOY #---------------------------------------------- self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP) log.info("Associate platform model with platform agent") self.generic_association_script( c.IMS.assign_platform_model_to_platform_agent, platform_agent_impl.find_having_model, platform_agent_impl.find_stemming_model, platform_agent_id, platform_model_id) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY) add_keyworded_attachment( self.client.RR, platform_agent_id, [KeywordFlag.CERTIFICATION, "platform attachment"]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY, LCS.DEPLOYED) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP) log.info("Associate instrument model with instrument agent") self.generic_association_script( c.IMS.assign_instrument_model_to_instrument_agent, c.IMS.find_instrument_agent_by_instrument_model, c.IMS.find_instrument_model_by_instrument_agent, instrument_agent_id, instrument_model_id) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.CERTIFICATION]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY, LCS.DEPLOYED) #platform instrument DELETEME just for find/replace #---------------------------------------------- # # devices # #---------------------------------------------- log.info("Associate platform model with platform device") self.generic_association_script( c.IMS.assign_platform_model_to_platform_device, c.IMS.find_platform_device_by_platform_model, c.IMS.find_platform_model_by_platform_device, platform_device_id, platform_model_id) log.info("Associate platform device with platform site") self.generic_association_script( c.OMS.assign_device_to_site, platform_site_impl.find_having_device, platform_site_impl.find_stemming_device, platform_site_id, platform_device_id) log.info("Associate instrument model with instrument device") self.generic_association_script( c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id, instrument_model_id) log.info("Associate instrument device with instrument site") self.generic_association_script( c.OMS.assign_device_to_site, instrument_site_impl.find_having_device, instrument_site_impl.find_stemming_device, instrument_site_id, instrument_device_id) log.info("Associate instrument device with platform device") self.generic_association_script( c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id) log.info("Associate sensor model with sensor device") self.generic_association_script( c.IMS.assign_sensor_model_to_sensor_device, sensor_device_impl.find_having_model, sensor_device_impl.find_stemming_model, sensor_device_id, sensor_model_id) log.info("Associate sensor device with instrument device") self.generic_association_script( c.IMS.assign_sensor_device_to_instrument_device, instrument_device_impl.find_having_device, instrument_device_impl.find_stemming_device, instrument_device_id, sensor_device_id) #---------------------------------------------- # # instances # #---------------------------------------------- #generic find ops for whatever log.info("Find an instrument site by observatory") entities = c.OMS.find_related_frames_of_reference( observatory_id, [RT.InstrumentSite]) self.assertIn(RT.InstrumentSite, entities) inst_sites = entities[RT.InstrumentSite] self.assertEqual(1, len(inst_sites)) self.assertEqual(instrument_site_id, inst_sites[0]._id)
def test_observatory_structure(self): c = self.client c2 = DotDict() c2.resource_registry = self.client.RR instrument_site_impl = InstrumentSiteImpl(c2) platform_site_impl = PlatformSiteImpl(c2) platform_agent_impl = PlatformAgentImpl(c2) instrument_device_impl = InstrumentDeviceImpl(c2) sensor_device_impl = SensorDeviceImpl(c2) #generate a function that finds direct associations, using the more complex one in the service def gen_find_oms_association(output_type): def freeze(): def finder_fun(obj_id): ret = c.OMS.find_related_frames_of_reference(obj_id, [output_type]) return ret[output_type] return finder_fun return freeze() #resource_ids = self._low_level_init() ############################################### # # Assumptions or Order of Events for R2 Preloaded resources # # - orgs # - sites # - models # - agents # - devices # - instances # - attachments # ############################################### ############################################### # # orgs # ############################################### ############################################### # # sites # ############################################### log.info("Create an observatory") observatory_id = self.generic_fcruf_script(RT.Observatory, "observatory", self.client.OMS, True) log.info("Create a subsite") subsite_id = self.generic_fcruf_script(RT.Subsite, "subsite", self.client.OMS, True) log.info("Create a platform site") platform_site_id = self.generic_fcruf_script(RT.PlatformSite, "platform_site", self.client.OMS, True) log.info("Create instrument site") instrument_site_id = self.generic_fcruf_script(RT.InstrumentSite, "instrument_site", self.client.OMS, True) ############################################### # # models # ############################################### log.info("Create a platform model") platform_model_id = self.generic_fcruf_script(RT.PlatformModel, "platform_model", self.client.IMS, True) log.info("Create instrument model") instrument_model_id = self.generic_fcruf_script(RT.InstrumentModel, "instrument_model", self.client.IMS, True) log.info("Create sensor model") sensor_model_id = self.generic_fcruf_script(RT.SensorModel, "sensor_model", self.client.IMS, True) ############################################### # # agents # ############################################### log.info("Create platform agent") platform_agent_id = self.generic_fcruf_script(RT.PlatformAgent, "platform_agent", self.client.IMS, False) log.info("Create instrument agent") instrument_agent_id = self.generic_fcruf_script(RT.InstrumentAgent, "instrument_agent", self.client.IMS, False) ############################################### # # devices # ############################################### log.info("Create a platform device") platform_device_id = self.generic_fcruf_script(RT.PlatformDevice, "platform_device", self.client.IMS, False) log.info("Create an instrument device") instrument_device_id = self.generic_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, False) log.info("Create a sensor device") sensor_device_id = self.generic_fcruf_script(RT.SensorDevice, "sensor_device", self.client.IMS, False) ############################################### # # instances # ############################################### ############################################### # # # attachments and LCS stuff # # ############################################### #---------------------------------------------- # # orgs # #---------------------------------------------- #---------------------------------------------- # # sites # #---------------------------------------------- log.info("Associate subsite with observatory") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Observatory), gen_find_oms_association(RT.Subsite), observatory_id, subsite_id) log.info("Associate platform site with subsite") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Subsite), gen_find_oms_association(RT.PlatformSite), subsite_id, platform_site_id) log.info("Associate instrument site with platform site") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.PlatformSite), gen_find_oms_association(RT.InstrumentSite), platform_site_id, instrument_site_id) #---------------------------------------------- # # models # #---------------------------------------------- log.info("Associate platform model with platform site") self.generic_association_script(c.OMS.assign_platform_model_to_platform_site, platform_site_impl.find_having_model, platform_site_impl.find_stemming_model, platform_site_id, platform_model_id) log.info("Associate instrument model with instrument site") self.generic_association_script(c.OMS.assign_instrument_model_to_instrument_site, instrument_site_impl.find_having_model, instrument_site_impl.find_stemming_model, instrument_site_id, instrument_model_id) #---------------------------------------------- # # agents # # - model required for DEVELOP # - egg required for INTEGRATE # - certification required for DEPLOY #---------------------------------------------- self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP) log.info("Associate platform model with platform agent") self.generic_association_script(c.IMS.assign_platform_model_to_platform_agent, platform_agent_impl.find_having_model, platform_agent_impl.find_stemming_model, platform_agent_id, platform_model_id) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.CERTIFICATION, "platform attachment"]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY, LCS.DEPLOYED) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP) log.info("Associate instrument model with instrument agent") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_agent, c.IMS.find_instrument_agent_by_instrument_model, c.IMS.find_instrument_model_by_instrument_agent, instrument_agent_id, instrument_model_id) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.CERTIFICATION]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY, LCS.DEPLOYED) #platform instrument DELETEME just for find/replace #---------------------------------------------- # # devices # #---------------------------------------------- self.generic_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) log.info("Associate platform model with platform device") self.generic_association_script(c.IMS.assign_platform_model_to_platform_device, c.IMS.find_platform_device_by_platform_model, c.IMS.find_platform_model_by_platform_device, platform_device_id, platform_model_id) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) log.info("Associate instrument model with instrument device") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id, instrument_model_id) log.info("Associate platform device with platform site") self.generic_association_script(c.OMS.assign_device_to_site, platform_site_impl.find_having_device, platform_site_impl.find_stemming_device, platform_site_id, platform_device_id) log.info("Associate instrument device with instrument site") self.generic_association_script(c.OMS.assign_device_to_site, instrument_site_impl.find_having_device, instrument_site_impl.find_stemming_device, instrument_site_id, instrument_device_id) log.info("Associate instrument device with platform device") self.generic_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id) log.info("Associate sensor model with sensor device") self.generic_association_script(c.IMS.assign_sensor_model_to_sensor_device, sensor_device_impl.find_having_model, sensor_device_impl.find_stemming_model, sensor_device_id, sensor_model_id) log.info("Associate sensor device with instrument device") self.generic_association_script(c.IMS.assign_sensor_device_to_instrument_device, instrument_device_impl.find_having_device, instrument_device_impl.find_stemming_device, instrument_device_id, sensor_device_id) #---------------------------------------------- # # instances # #---------------------------------------------- #generic find ops for whatever log.info("Find an instrument site by observatory") entities = c.OMS.find_related_frames_of_reference(observatory_id, [RT.InstrumentSite]) self.assertIn(RT.InstrumentSite, entities) inst_sites = entities[RT.InstrumentSite] self.assertEqual(1, len(inst_sites)) self.assertEqual(instrument_site_id, inst_sites[0]._id)
def test_observatory_structure(self): """ """ c = self.client c2 = DotDict() c2.resource_registry = self.client.RR instrument_site_impl = InstrumentSiteImpl(c2) platform_site_impl = PlatformSiteImpl(c2) platform_agent_impl = PlatformAgentImpl(c2) instrument_device_impl = InstrumentDeviceImpl(c2) sensor_device_impl = SensorDeviceImpl(c2) #generate a function that finds direct associations, using the more complex one in the service def gen_find_oms_association(output_type): def freeze(): def finder_fun(obj_id): ret = c.OMS.find_related_frames_of_reference(obj_id, [output_type]) return ret[output_type] return finder_fun return freeze() #resource_ids = self._low_level_init() ############################################### # # Assumptions or Order of Events for R2 Preloaded resources # # - orgs # - sites # - models # - agents # - devices # - instances # - attachments # ############################################### ############################################### # # orgs # ############################################### ############################################### # # sites # ############################################### log.info("Create an observatory") observatory_id = self.generic_fcruf_script(RT.Observatory, "observatory", self.client.OMS, True) log.info("Create a subsite") subsite_id = self.generic_fcruf_script(RT.Subsite, "subsite", self.client.OMS, True) log.info("Create a platform site") platform_site_id = self.generic_fcruf_script(RT.PlatformSite, "platform_site", self.client.OMS, True) log.info("Create instrument site") instrument_site_id = self.generic_fcruf_script(RT.InstrumentSite, "instrument_site", self.client.OMS, True) ############################################### # # models # ############################################### log.info("Create a platform model") platform_model_id = self.generic_fcruf_script(RT.PlatformModel, "platform_model", self.client.IMS, True) log.info("Create instrument model") instrument_model_id = self.generic_fcruf_script(RT.InstrumentModel, "instrument_model", self.client.IMS, True) log.info("Create sensor model") sensor_model_id = self.generic_fcruf_script(RT.SensorModel, "sensor_model", self.client.IMS, True) ############################################### # # agents # ############################################### log.info("Create platform agent") platform_agent_id = self.generic_fcruf_script(RT.PlatformAgent, "platform_agent", self.client.IMS, False) log.info("Create instrument agent") instrument_agent_id = self.generic_fcruf_script(RT.InstrumentAgent, "instrument_agent", self.client.IMS, False) ############################################### # # devices # ############################################### log.info("Create a platform device") platform_device_id = self.generic_fcruf_script(RT.PlatformDevice, "platform_device", self.client.IMS, False) log.info("Create an instrument device") instrument_device_id = self.generic_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, False) log.info("Create a sensor device") sensor_device_id = self.generic_fcruf_script(RT.SensorDevice, "sensor_device", self.client.IMS, False) ############################################### # # instances # ############################################### ############################################### # # # attachments and LCS stuff # # ############################################### #---------------------------------------------- # # orgs # #---------------------------------------------- #---------------------------------------------- # # sites # #---------------------------------------------- log.info("Associate subsite with observatory") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Observatory), gen_find_oms_association(RT.Subsite), observatory_id, subsite_id) log.info("Associate platform site with subsite") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Subsite), gen_find_oms_association(RT.PlatformSite), subsite_id, platform_site_id) log.info("Associate instrument site with platform site") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.PlatformSite), gen_find_oms_association(RT.InstrumentSite), platform_site_id, instrument_site_id) #---------------------------------------------- # # models # #---------------------------------------------- log.info("Associate platform model with platform site") self.generic_association_script(c.OMS.assign_platform_model_to_platform_site, platform_site_impl.find_having_model, platform_site_impl.find_stemming_model, platform_site_id, platform_model_id) log.info("Associate instrument model with instrument site") self.generic_association_script(c.OMS.assign_instrument_model_to_instrument_site, instrument_site_impl.find_having_model, instrument_site_impl.find_stemming_model, instrument_site_id, instrument_model_id) #---------------------------------------------- # # agents # # - model required for DEVELOP # - egg required for INTEGRATE # - certification required for DEPLOY #---------------------------------------------- self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP) log.info("Associate platform model with platform agent") self.generic_association_script(c.IMS.assign_platform_model_to_platform_agent, platform_agent_impl.find_having_model, platform_agent_impl.find_stemming_model, platform_agent_id, platform_model_id) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.CERTIFICATION, "platform attachment"]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY, LCS.DEPLOYED) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP) log.info("Associate instrument model with instrument agent") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_agent, c.IMS.find_instrument_agent_by_instrument_model, c.IMS.find_instrument_model_by_instrument_agent, instrument_agent_id, instrument_model_id) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.CERTIFICATION]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY, LCS.DEPLOYED) #---------------------------------------------- # # devices # #---------------------------------------------- self.generic_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) log.info("Associate platform model with platform device") self.generic_association_script(c.IMS.assign_platform_model_to_platform_device, c.IMS.find_platform_device_by_platform_model, c.IMS.find_platform_model_by_platform_device, platform_device_id, platform_model_id) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) log.info("Associate instrument model with instrument device") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id, instrument_model_id) log.info("Associate instrument device with platform device") self.generic_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id) log.info("Associate sensor model with sensor device") self.generic_association_script(c.IMS.assign_sensor_model_to_sensor_device, sensor_device_impl.find_having_model, sensor_device_impl.find_stemming_model, sensor_device_id, sensor_model_id) log.info("Associate sensor device with instrument device") self.generic_association_script(c.IMS.assign_sensor_device_to_instrument_device, instrument_device_impl.find_having_device, instrument_device_impl.find_stemming_device, instrument_device_id, sensor_device_id) #---------------------------------------------- # # instances # #---------------------------------------------- #---------------------------------------------- # # data production chain and swapping # #---------------------------------------------- #------------------------------------------------------------------------------------------------ # create a stream definition for the data from the ctd simulator #------------------------------------------------------------------------------------------------ ctd_stream_def = ctd_stream_definition() ctd_stream_def_id = self.client.PSMS.create_stream_definition(container=ctd_stream_def, name='Simulated CTD data') log.debug("Created stream def id %s" % ctd_stream_def_id) #create data products for instrument data log.debug('test_createDataProduct: Creating new data product w/o a stream definition: %s' % ctd_stream_def_id) craft = CoverageCraft sdom, tdom = craft.create_domains() sdom = sdom.dump() tdom = tdom.dump() parameter_dictionary = craft.create_parameters() parameter_dictionary = parameter_dictionary.dump() dp_obj = IonObject(RT.DataProduct, name='DP1', description='some new dp', temporal_domain = tdom, spatial_domain = sdom) log.debug("Created an IonObject for a data product: %s" % dp_obj) #------------------------------------------------------------------------------------------------ # Create a set of ParameterContext objects to define the parameters in the coverage, add each to the ParameterDictionary #------------------------------------------------------------------------------------------------ log.debug("parameter dictionary: %s" % parameter_dictionary) inst_data_product_id = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id, parameter_dictionary) log_data_product_id = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id, parameter_dictionary) #assign data products appropriately c.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=inst_data_product_id) c.OMS.create_site_data_product(instrument_site_id, log_data_product_id) deployment_id = self.generic_fcruf_script(RT.Deployment, "deployment", c.OMS, False) c.OMS.deploy_instrument_site(instrument_site_id, deployment_id) c.IMS.deploy_instrument_device(instrument_device_id, deployment_id) c.OMS.activate_deployment(deployment_id, True) #now along comes a new device log.info("Create instrument device 2") instrument_device_id2 = self.generic_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, False) log.info("Associate instrument model with instrument device 2") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id2, instrument_model_id) log.info("Associate instrument device with platform device 2") self.generic_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id2) inst_data_product_id2 = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id, parameter_dictionary) c.DAMS.assign_data_product(input_resource_id=instrument_device_id2, data_product_id=inst_data_product_id2) # create a new deployment for the new device deployment_id2 = self.generic_fcruf_script(RT.Deployment, "deployment", c.OMS, False) c.OMS.deploy_instrument_site(instrument_site_id, deployment_id2) c.IMS.deploy_instrument_device(instrument_device_id2, deployment_id2) # activate the new deployment -- changing the primary device -- but don't switch subscription c.OMS.activate_deployment(deployment_id2, False) #todo: assert site hasDevice instrument_device_id2 c.OMS.transfer_site_subscription(instrument_site_id) #---------------------------------------------- # # generic find ops # #---------------------------------------------- log.info("Find an instrument site by observatory") entities = c.OMS.find_related_frames_of_reference(observatory_id, [RT.InstrumentSite]) self.assertIn(RT.InstrumentSite, entities) inst_sites = entities[RT.InstrumentSite] self.assertEqual(1, len(inst_sites)) self.assertEqual(instrument_site_id, inst_sites[0]._id)
def test_observatory_structure(self): """ """ c = self.client c2 = DotDict() c2.resource_registry = self.client.RR instrument_site_impl = InstrumentSiteImpl(c2) platform_site_impl = PlatformSiteImpl(c2) platform_agent_impl = PlatformAgentImpl(c2) instrument_device_impl = InstrumentDeviceImpl(c2) sensor_device_impl = SensorDeviceImpl(c2) resource_impl = ResourceImpl(c2) #generate a function that finds direct associations, using the more complex one in the service def gen_find_oms_association(output_type): def freeze(): def finder_fun(obj_id): ret = c.OMS.find_related_frames_of_reference(obj_id, [output_type]) return ret[output_type] return finder_fun return freeze() #resource_ids = self._low_level_init() ############################################### # # Assumptions or Order of Events for R2 Preloaded resources # # - orgs # - sites # - models # - agents # - devices # - instances # - attachments # ############################################### ############################################### # # orgs # ############################################### ############################################### # # sites # ############################################### log.info("Create an observatory") observatory_id = self.generic_fcruf_script(RT.Observatory, "observatory", self.client.OMS, True) log.info("Create a subsite") subsite_id = self.generic_fcruf_script(RT.Subsite, "subsite", self.client.OMS, True) log.info("Create a platform site") platform_site_id = self.generic_fcruf_script(RT.PlatformSite, "platform_site", self.client.OMS, True) log.info("Create instrument site") instrument_site_id = self.generic_fcruf_script(RT.InstrumentSite, "instrument_site", self.client.OMS, True) ############################################### # # models # ############################################### log.info("Create a platform model") platform_model_id = self.generic_fcruf_script(RT.PlatformModel, "platform_model", self.client.IMS, True) log.info("Create instrument model") instModel_obj = IonObject(RT.InstrumentModel, name='SBE37IMModel', description="SBE37IMModel", custom_attributes= {'streams':{'raw': 'ctd_raw_param_dict' , 'parsed': 'ctd_parsed_param_dict' }}) instrument_model_id = self.generic_fcruf_script(RT.InstrumentModel, "instrument_model", self.client.IMS, True, actual_obj=instModel_obj) log.info("Create sensor model") sensor_model_id = self.generic_fcruf_script(RT.SensorModel, "sensor_model", self.client.IMS, True) ############################################### # # agents # ############################################### log.info("Create platform agent") platform_agent_id = self.generic_fcruf_script(RT.PlatformAgent, "platform_agent", self.client.IMS, False) log.info("Create instrument agent") instAgent_obj = IonObject(RT.InstrumentAgent, name='agent007', description="SBE37IMAgent", driver_module="mi.instrument.seabird.sbe37smb.ooicore.driver", driver_class="SBE37Driver" ) instrument_agent_id = self.generic_fcruf_script(RT.InstrumentAgent, "instrument_agent", self.client.IMS, False, actual_obj=instAgent_obj) ############################################### # # devices # ############################################### log.info("Create a platform device") platform_device_id = self.generic_fcruf_script(RT.PlatformDevice, "platform_device", self.client.IMS, False) log.info("Create an instrument device") instrument_device_id = self.generic_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, False) log.info("Create a sensor device") sensor_device_id = self.generic_fcruf_script(RT.SensorDevice, "sensor_device", self.client.IMS, False) ############################################### # # instances # ############################################### # we create instrument agent instance below, to verify some lcs checks ############################################### # # # attachments and LCS stuff # # ############################################### #---------------------------------------------- # # orgs # #---------------------------------------------- #---------------------------------------------- # # sites # #---------------------------------------------- log.info("Associate subsite with observatory") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Observatory), gen_find_oms_association(RT.Subsite), observatory_id, subsite_id) log.info("Associate platform site with subsite") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.Subsite), gen_find_oms_association(RT.PlatformSite), subsite_id, platform_site_id) log.info("Associate instrument site with platform site") self.generic_association_script(c.OMS.assign_site_to_site, gen_find_oms_association(RT.PlatformSite), gen_find_oms_association(RT.InstrumentSite), platform_site_id, instrument_site_id) #---------------------------------------------- # # models # #---------------------------------------------- log.info("Associate platform model with platform site") self.generic_association_script(c.OMS.assign_platform_model_to_platform_site, platform_site_impl.find_having_model, platform_site_impl.find_stemming_model, platform_site_id, platform_model_id) log.info("Associate instrument model with instrument site") self.generic_association_script(c.OMS.assign_instrument_model_to_instrument_site, instrument_site_impl.find_having_model, instrument_site_impl.find_stemming_model, instrument_site_id, instrument_model_id) #---------------------------------------------- # # agents # # - model required for DEVELOP # - egg required for INTEGRATE # - certification required for DEPLOY #---------------------------------------------- self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP) log.info("Associate platform model with platform agent") self.generic_association_script(c.IMS.assign_platform_model_to_platform_agent, platform_agent_impl.find_having_model, platform_agent_impl.find_stemming_model, platform_agent_id, platform_model_id) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, platform_agent_id, [KeywordFlag.CERTIFICATION, "platform attachment"]) self.generic_lcs_pass(self.client.IMS, "platform_agent", platform_agent_id, LCE.DEPLOY, LCS.DEPLOYED) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.PLAN, LCS.PLANNED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP) log.info("Associate instrument model with instrument agent") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_agent, c.IMS.find_instrument_agent_by_instrument_model, c.IMS.find_instrument_model_by_instrument_agent, instrument_agent_id, instrument_model_id) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEVELOP, LCS.DEVELOPED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.EGG_URL]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.INTEGRATE, LCS.INTEGRATED) self.generic_lcs_fail(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY) add_keyworded_attachment(self.client.RR, instrument_agent_id, [KeywordFlag.CERTIFICATION]) self.generic_lcs_pass(self.client.IMS, "instrument_agent", instrument_agent_id, LCE.DEPLOY, LCS.DEPLOYED) #---------------------------------------------- # # devices # #---------------------------------------------- log.info("LCS plan") self.generic_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.PLAN, LCS.PLANNED) log.info("LCS develop") self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) x = self.client.IMS.read_platform_device(platform_device_id) x.serial_number = "12345" self.client.IMS.update_platform_device(x) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) log.info("Associate platform model with platform device") self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) self.generic_association_script(c.IMS.assign_platform_model_to_platform_device, c.IMS.find_platform_device_by_platform_model, c.IMS.find_platform_model_by_platform_device, platform_device_id, platform_model_id) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP) add_keyworded_attachment(self.client.RR, platform_device_id, [KeywordFlag.VENDOR_TEST_RESULTS]) self.generic_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.DEVELOP, LCS.DEVELOPED) log.info("LCS integrate") self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) add_keyworded_attachment(self.client.RR, platform_device_id, [KeywordFlag.VENDOR_TEST_RESULTS]) self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE) platform_agent_instance_id = self.create_plat_agent_instance(platform_agent_id, platform_device_id) self.generic_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.INTEGRATE, LCS.INTEGRATED) log.info("LCS deploy") self.generic_lcs_fail(self.client.IMS, "platform_device", platform_device_id, LCE.DEPLOY) log.info("LCS plan") self.generic_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.PLAN, LCS.PLANNED) log.info("LCS develop") self.generic_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP) x = self.client.IMS.read_instrument_device(instrument_device_id) x.serial_number = "12345" self.client.IMS.update_instrument_device(x) self.generic_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP) log.info("Associate instrument model with instrument device") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id, instrument_model_id) self.generic_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP) add_keyworded_attachment(self.client.RR, instrument_device_id, [KeywordFlag.VENDOR_TEST_RESULTS]) self.generic_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEVELOP, LCS.DEVELOPED) log.info("LCS integrate") self.generic_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.INTEGRATE) log.info("Associate instrument device with platform device") self.generic_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id) self.generic_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.INTEGRATE) log.info("Create instrument agent instance") instrument_agent_instance_id = self.create_inst_agent_instance(instrument_agent_id, instrument_device_id) self.generic_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.INTEGRATE, LCS.INTEGRATED) log.info("LCS deploy") self.generic_lcs_fail(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEPLOY) log.info("Associate sensor model with sensor device") self.generic_association_script(c.IMS.assign_sensor_model_to_sensor_device, sensor_device_impl.find_having_model, sensor_device_impl.find_stemming_model, sensor_device_id, sensor_model_id) log.info("Associate sensor device with instrument device") self.generic_association_script(c.IMS.assign_sensor_device_to_instrument_device, instrument_device_impl.find_having_device, instrument_device_impl.find_stemming_device, instrument_device_id, sensor_device_id) #---------------------------------------------- # # instances # #---------------------------------------------- #---------------------------------------------- # # data production chain and swapping # #---------------------------------------------- #------------------------------------------------------------------------------------------------ # create a stream definition for the data from the ctd simulator #------------------------------------------------------------------------------------------------ pdict_id = self.dataset_management.read_parameter_dictionary_by_name('ctd_parsed_param_dict', id_only=True) ctd_stream_def_id = self.client.PSMS.create_stream_definition(name='Simulated CTD data', parameter_dictionary_id=pdict_id) log.debug("Created stream def id %s", ctd_stream_def_id) #create data products for instrument data dp_obj = self.create_data_product_obj() log.debug("Created an IonObject for a data product: %s", dp_obj) #------------------------------------------------------------------------------------------------ # Create a set of ParameterContext objects to define the parameters in the coverage, add each to the ParameterDictionary #------------------------------------------------------------------------------------------------ dp_obj.name = 'Data Product' inst_data_product_id = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id) dp_obj.name = 'Log Data Product' log_data_product_id = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id) #assign data products appropriately c.DAMS.assign_data_product(input_resource_id=instrument_device_id, data_product_id=inst_data_product_id) c.OMS.create_site_data_product(instrument_site_id, log_data_product_id) deployment_id = self.generic_fcruf_script(RT.Deployment, "deployment", c.OMS, False) c.OMS.deploy_platform_site(platform_site_id, deployment_id) c.IMS.deploy_platform_device(platform_device_id, deployment_id) c.OMS.deploy_instrument_site(instrument_site_id, deployment_id) c.IMS.deploy_instrument_device(instrument_device_id, deployment_id) c.OMS.activate_deployment(deployment_id, True) self.assertLess(0, len(instrument_site_impl.find_having_device(instrument_device_id))) self.assertLess(0, len(instrument_site_impl.find_stemming_device(instrument_site_id))) self.assertLess(0, len(platform_site_impl.find_having_device(platform_device_id))) self.assertLess(0, len(platform_site_impl.find_stemming_device(platform_site_id))) self.generic_lcs_pass(self.client.IMS, "platform_device", platform_device_id, LCE.DEPLOY, LCS.DEPLOYED) self.generic_lcs_pass(self.client.IMS, "instrument_device", instrument_device_id, LCE.DEPLOY, LCS.DEPLOYED) #now along comes a new device log.info("Create instrument device 2") instrument_device_id2 = self.generic_fcruf_script(RT.InstrumentDevice, "instrument_device", self.client.IMS, False) log.info("Associate instrument model with instrument device 2") self.generic_association_script(c.IMS.assign_instrument_model_to_instrument_device, c.IMS.find_instrument_device_by_instrument_model, c.IMS.find_instrument_model_by_instrument_device, instrument_device_id2, instrument_model_id) log.info("Associate instrument device with platform device 2") self.generic_association_script(c.IMS.assign_instrument_device_to_platform_device, c.IMS.find_platform_device_by_instrument_device, c.IMS.find_instrument_device_by_platform_device, platform_device_id, instrument_device_id2) dp_obj.name = 'Instrument Data Product 2' inst_data_product_id2 = c.DPMS.create_data_product(dp_obj, ctd_stream_def_id) c.DAMS.assign_data_product(input_resource_id=instrument_device_id2, data_product_id=inst_data_product_id2) # create a new deployment for the new device deployment_id2 = self.generic_fcruf_script(RT.Deployment, "deployment", c.OMS, False) log.debug("Associating instrument site with new deployment") c.OMS.deploy_instrument_site(instrument_site_id, deployment_id2) log.debug("Associating instrument device with new deployment") c.IMS.deploy_instrument_device(instrument_device_id2, deployment_id2) # activate the new deployment -- changing the primary device -- but don't switch subscription log.debug("Activating new deployment") c.OMS.activate_deployment(deployment_id2, False) #todo: assert site hasDevice instrument_device_id2 assocs = self.client.RR.find_associations(instrument_site_id, PRED.hasDevice, instrument_device_id2, id_only=True) self.assertIsNotNone(assocs) log.debug("L4-CI-SA-RQ-334 DEPLOY: Proposed change - Instrument activation shall support transition to the active state for instruments") log.debug("Transferring site subscriptions") c.OMS.transfer_site_subscription(instrument_site_id) #---------------------------------------------- # # generic find ops # #---------------------------------------------- log.info("Find an instrument site by observatory") entities = c.OMS.find_related_frames_of_reference(observatory_id, [RT.InstrumentSite]) self.assertIn(RT.InstrumentSite, entities) inst_sites = entities[RT.InstrumentSite] self.assertEqual(1, len(inst_sites)) self.assertEqual(instrument_site_id, inst_sites[0]._id) c.IMS.delete_instrument_agent(instrument_agent_id) instr_agent_obj_read = self.client.RR.read(instrument_agent_id) self.assertEquals(instr_agent_obj_read.lcstate,LCS.RETIRED) log.debug("L4-CI-SA-RQ-382: Proposed change - Instrument activation shall manage the life cycle of Instrument Agents") c.IMS.delete_instrument_device(instrument_device_id) # Check whether the instrument device has been retired instrument_obj_read = self.client.RR.read(instrument_device_id) log.debug("The instruments lcs state has been set to %s after the delete operation" % instrument_obj_read.lcstate) self.assertEquals(instrument_obj_read.lcstate, LCS.RETIRED) log.debug("L4-CI-SA-RQ-334 RETIRE") log.debug("L4-CI-SA-RQ-335: Instrument activation shall support transition to the retired state of instruments") #---------------------------------------------- # # force_deletes # #---------------------------------------------- # need to "pluck" some resources out of associations resource_impl.pluck(instrument_model_id) resource_impl.pluck(platform_model_id) resource_impl.pluck(instrument_agent_id) resource_impl.pluck(platform_agent_id) resource_impl.pluck(deployment_id) resource_impl.pluck(deployment_id2) self.generic_fd_script(observatory_id, "observatory", c.OMS) self.generic_fd_script(subsite_id, "subsite", c.OMS) self.generic_fd_script(platform_site_id, "platform_site", c.OMS) self.generic_fd_script(instrument_site_id, "instrument_site", c.OMS) self.generic_fd_script(platform_model_id, "platform_model", c.IMS) self.generic_fd_script(instrument_model_id, "instrument_model", c.IMS) self.generic_fd_script(sensor_model_id, "sensor_model", c.IMS) self.generic_fd_script(platform_agent_id, "platform_agent", c.IMS) self.generic_fd_script(instrument_agent_id, "instrument_agent", c.IMS) self.generic_fd_script(platform_device_id, "platform_device", c.IMS) self.generic_fd_script(instrument_device_id, "instrument_device", c.IMS) self.generic_fd_script(sensor_device_id, "sensor_device", c.IMS) self.generic_fd_script(platform_agent_instance_id, "platform_agent_instance", c.IMS) self.generic_fd_script(instrument_agent_instance_id, "instrument_agent_instance", c.IMS) self.generic_fd_script(deployment_id, "deployment", c.OMS) self.generic_fd_script(deployment_id2, "deployment", c.OMS)