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)