def test_agreement_state_set_pending_on_creation(self): """ Test that the agreement state is set to pending on creation """ api.build() # instantiate api for backends self.entity.mixins.append(self._get_sample_provider_mixins()[0][0]) self.agree_back.create(self.entity, self.extras) entity_state = self.entity.attributes["occi.agreement.state"] self.assertEqual(entity_state, "pending") LOG.info("Agreement has inital state set to 'pending'.")
def test_no_policy_creation(self): """ Check that if no link (aka device id) exist, no policy is created """ gold = core_model.Mixin('', 'gold', [occi_sla.AGREEMENT_TEMPLATE]) compute = core_model.Mixin('', 'compute', [occi_sla.AGREEMENT_TEMPLATE]) availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [gold, compute, availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = { 'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-11-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2015-11-02T02:20:27+00:00' } northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources.registry.populate_resources() myrulesengine = rulesengine.RulesEngine(resources.registry) myrulesengine.active_policies = {} myrulesengine.active_agreements = {} # myrulesengine.registry=registry myrulesengine.start_engine(0) temp_policy_record = DB.policies.find({'agreement_id': self.id}, {'_id': 0}) self.assertEqual(temp_policy_record.count(), 0)
def test_past_agreement_non_detection(self): """ Check that the temp agreement with pending state is not detected as active agreement. """ gold = core_model.Mixin('', 'gold', [occi_sla.AGREEMENT_TEMPLATE]) compute = core_model.Mixin('', 'compute', [occi_sla.AGREEMENT_TEMPLATE]) availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [gold, compute, availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = { 'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-10-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2014-11-02T02:20:27+00:00' } northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources.registry.populate_resources() active_agreements = resources.registry.get_active_agreement_resources() self.assertEqual(active_agreements.__len__(), 0)
def test_active_agreement_detection(self): """ Check that the temp agreement is detected as active agreement. """ gold = core_model.Mixin('', 'gold', [occi_sla.AGREEMENT_TEMPLATE]) compute = core_model.Mixin('', 'compute', [occi_sla.AGREEMENT_TEMPLATE]) availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [gold, compute, availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = { 'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-11-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2015-11-02T02:20:27+00:00' } northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources.registry.populate_resources() active_agreements = resources.registry.get_active_agreement_resources() if active_agreements.__len__() == 1: self.assertEqual(active_agreements[0].identifier, self.id) else: for agr in active_agreements: self.assertTrue(agr.identifier == self.id)
def test_active_agreement_detection(self): """ Check that the temp agreement is detected as active agreement. """ gold = core_model.Mixin('', 'gold', [occi_sla.AGREEMENT_TEMPLATE]) compute = core_model.Mixin('', 'compute', [occi_sla.AGREEMENT_TEMPLATE]) availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [gold, compute, availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = {'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-11-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2015-11-02T02:20:27+00:00' } northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources.registry.populate_resources() active_agreements = resources.registry.get_active_agreement_resources() if active_agreements.__len__() == 1: self.assertEqual(active_agreements[0].identifier, self.id) else: for agr in active_agreements: self.assertTrue(agr.identifier == self.id)
def setUp(self): self.db = self._get_db_connection() self.api = api.build() self.api.register_backend(test_data.epc_mixin, backends.AgreementTemplate()) self.api.register_backend(test_data.ran_mixin, backends.AgreementTemplate())
def test_no_policy_creation(self): """ Check that if no link (aka device id) exist, no policy is created """ gold = core_model.Mixin('', 'gold', [occi_sla.AGREEMENT_TEMPLATE]) compute = core_model.Mixin('', 'compute', [occi_sla.AGREEMENT_TEMPLATE]) availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [gold, compute, availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = {'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-11-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2015-11-02T02:20:27+00:00' } northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources.registry.populate_resources() myrulesengine = rulesengine.RulesEngine(resources.registry) myrulesengine.active_policies = {} myrulesengine.active_agreements = {} # myrulesengine.registry=registry myrulesengine.start_engine(0) temp_policy_record = DB.policies.find({'agreement_id': self.id}, {'_id': 0}) self.assertEqual(temp_policy_record.count(), 0)
def test_provider_login_credentials_when_none(self): """ No security details provided """ extras = {} self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] self.assertRaises(AttributeError, self.agree_back.create, self.entity, extras)
def test_attribute_effective_Until_in_attributes(self): """ Ensures that the 'occi.agreement.effectiveUntil' attribute is set """ self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] del self.entity.attributes["occi.agreement.effectiveUntil"] self.assertRaises(AttributeError, self.agree_back.create, self.entity, self.extras)
def test_provider_login_credentials_correct(self): """ Compares the submitted user credentials against the database """ extras = {"security": {"unknown": "incorrect"}} self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] self.assertRaises(AttributeError, self.agree_back.create, self.entity, extras)
def test_customer_id_added_to_entity(self): """ Ensures that customer id is added to the agreement """ self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] extras = {"security": {"DSS": "dss_pass"}, "customer": "customer_1234"} self.agree_back.create(self.entity, extras) self.assertEqual(self.entity.customer, "customer_1234")
def test_provider_id_added_to_entity(self): """ Ensures that provider id is added to a newly created agreement """ self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] DB.providers.insert({"username": "******", "password": "******"}) extras = {"security": {"prov_123": "pass"}, "customer": "test"} self.agree_back.create(self.entity, extras) self.assertEqual(self.entity.provider, "prov_123") DB.providers.remove({"username": "******"})
def test_agreement_period_positive(self): """ Check that the time between 'occi.agreement.effectiveFrom' and 'occi.agreement.effectiveUntil' is positive """ self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] times = {"occi.agreement.effectiveFrom": "2014-11-02T02:20:26Z", "occi.agreement.effectiveUntil": "2014-11-02T02:17:26Z"} self.entity.attributes = times self.assertRaises(AttributeError, self.agree_back.create, self.entity, self.extras)
def test_add_attributes_from_terms_to_agreement(self): """ Takes attributes from the terms and adds them to the agreement """ expected_attrs = {"silver.compute.vcpu": 1, "silver.compute.os": "ubuntu", "silver.compute.memory": 1024, "silver.availability.uptime": 85} self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] self.agree_back.create(self.entity, self.extras) issub_set = all(item in self.entity.attributes.items() for item in expected_attrs.items()) self.assertTrue(issub_set)
def test_agreement_period_positive(self): """ Check that the time between 'occi.agreement.effectiveFrom' and 'occi.agreement.effectiveUntil' is positive """ self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] times = { "occi.agreement.effectiveFrom": "2014-11-02T02:20:26Z", "occi.agreement.effectiveUntil": "2014-11-02T02:17:26Z" } self.entity.attributes = times self.assertRaises(AttributeError, self.agree_back.create, self.entity, self.extras)
def test_create_all_terms_for_a_template(self): """ Checks that the correct terms are added for a given template """ # api being build self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) cmp_trm = nrth_bnd_api.registry.get_category("/compute/", None) avl_trm = nrth_bnd_api.registry.get_category("/availability/", None) expctd_mxns = [tmp_mxn, cmp_trm, avl_trm] self.entity.mixins = [tmp_mxn] self.agree_back.create(self.entity, self.extras) # Add temp so now the entity should have terms and silver template mixin self.assertEqual(set(self.entity.mixins), set(expctd_mxns))
def test_retrieve_correct_resource_with_mixins_from_dictionary(self): """ retrieve a resource from the dictionary with the same mixins """ test_resource_id = "/agreement/retrieve-mixins-from-dictionary" test_resource = core_model.Resource(test_resource_id, None, [test_data.epc_mixin]) registry = api.build().registry resources = EntityDictionary(registry) resources[test_resource_id] = test_resource returned_resource = resources[test_resource_id] rtrnd_mxn = returned_resource.mixins[0] self.assertEqual(test_resource.mixins[0].location, rtrnd_mxn.location) self.assertEqual(test_resource.mixins[0].term, rtrnd_mxn.term) self.assertEqual(test_resource.mixins[0].scheme, rtrnd_mxn.scheme)
def test_add_attributes_from_terms_to_agreement(self): """ Takes attributes from the terms and adds them to the agreement """ expected_attrs = { "silver.compute.vcpu": 1, "silver.compute.os": "ubuntu", "silver.compute.memory": 1024, "silver.availability.uptime": 85 } self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] self.agree_back.create(self.entity, self.extras) issub_set = all(item in self.entity.attributes.items() for item in expected_attrs.items()) self.assertTrue(issub_set)
def test_policy_creation(self): """ Check that an active agreement has been detected and a record inserted into the database """ availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = { 'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-11-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2015-11-02T02:20:27+00:00' } comp_res = core_model.Resource(self.compute_id, infrastructure.COMPUTE, []) comp_res.attributes = {} link_res = core_model.Link(self.link_id, occi_sla.AGREEMENT_LINK, [], res, comp_res) link_res.attributes = {} res.links = [link_res] northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources[self.compute_id] = comp_res resources[self.link_id] = link_res resources.registry.populate_resources() myrulesengine = rulesengine.RulesEngine(resources.registry) myrulesengine.active_policies = {} myrulesengine.active_agreements = {} myrulesengine.start_engine(0) temp_policy_record = DB.policies.find({'agreement_id': self.id}, {'_id': 0}) self.assertEqual(temp_policy_record.count(), 1)
def test_term_type_attributes_added_on_creation(self): """ Ensures that the agreement terms attributes are added for each term """ expctd_attrs = {"compute.term.type": 'SERVICE-TERM', "compute.term.state": 'undefined', "compute.term.desc": "", "availability.term.type": 'SLO-TERM', "availability.term.state": 'undefined', "availability.term.desc": '' } self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] self.agree_back.create(self.entity, self.extras) issub_set = all(item in self.entity.attributes.items() for item in expctd_attrs.items()) self.assertTrue(issub_set)
def test_past_agreement_non_detection(self): """ Check that the temp agreement with pending state is not detected as active agreement. """ gold = core_model.Mixin('', 'gold', [occi_sla.AGREEMENT_TEMPLATE]) compute = core_model.Mixin('', 'compute', [occi_sla.AGREEMENT_TEMPLATE]) availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [gold, compute, availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = {'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-10-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2014-11-02T02:20:27+00:00' } northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources.registry.populate_resources() active_agreements = resources.registry.get_active_agreement_resources() self.assertEqual(active_agreements.__len__(), 0)
def test_policy_creation(self): """ Check that an active agreement has been detected and a record inserted into the database """ availability = core_model.Mixin('', 'availability', [occi_sla.AGREEMENT_TEMPLATE]) mixins = [availability] res = core_model.Resource(self.id, occi_sla.AGREEMENT, mixins) res.attributes = {'occi.agreement.state': 'accepted', 'occi.agreement.effectiveFrom': '2014-11-02T02:20:26+00:00', 'occi.agreement.effectiveUntil': '2015-11-02T02:20:27+00:00' } comp_res = core_model.Resource(self.compute_id, infrastructure.COMPUTE, []) comp_res.attributes = {} link_res = core_model.Link(self.link_id, occi_sla.AGREEMENT_LINK, [], res, comp_res) link_res.attributes = {} res.links = [link_res] northbound_api = api.build() resources = EntityDictionary(northbound_api.registry) resources[self.id] = res resources[self.compute_id] = comp_res resources[self.link_id] = link_res resources.registry.populate_resources() myrulesengine = rulesengine.RulesEngine(resources.registry) myrulesengine.active_policies = {} myrulesengine.active_agreements = {} myrulesengine.start_engine(0) temp_policy_record = DB.policies.find({'agreement_id': self.id}, {'_id': 0}) self.assertEqual(temp_policy_record.count(), 1)
def test_term_type_attributes_added_on_creation(self): """ Ensures that the agreement terms attributes are added for each term """ expctd_attrs = { "compute.term.type": 'SERVICE-TERM', "compute.term.state": 'undefined', "compute.term.desc": "", "availability.term.type": 'SLO-TERM', "availability.term.state": 'undefined', "availability.term.desc": '' } self._load_template_database() nrth_bnd_api = api.build() tmp_mxn = nrth_bnd_api.registry.get_category("/silver/", None) self.entity.mixins = [tmp_mxn] self.agree_back.create(self.entity, self.extras) issub_set = all(item in self.entity.attributes.items() for item in expctd_attrs.items()) self.assertTrue(issub_set)
def setUp(self): api_n = api.build() self.agreement_link = api_n.registry.get_category("/agreement_link/", None)
def setUp(self): api_n = api.build() self.agreement_template = api_n.registry.get_category( "/agreement_tpl/", None)
temps_dss = json.load(file("configs/template_definition_DSS.json")) templates.load_templates(temps_dss) #Add Providers login credentials provider_details.load_providers() #Add monitoring capabilities and Collectos's API monitoring_details.load_monitoring_capabilities() clean_violation_from_db() if __name__ == "__main__": try: LOG.info("Starting OCCI server") init_environment() northbound_api = api.build() #start RulesEngine myRulesEngine = rulesengine.RulesEngine(northbound_api.registry) # Prepare intellect rules engine RE_thread = threading.Thread(target=myRulesEngine.start_engine, args=(15,)) RE_thread.daemon = True RE_thread.start() httpd = make_server('0.0.0.0', 8888, northbound_api) httpd.serve_forever() #tmps = json.load(file("tests/sample_data/template_definition.json")) #templates.load_templates(tmps) except KeyboardInterrupt: print "Ctrl-c received! Killing OCCI Server..."
def setUp(self): api_n = api.build() self.agreement_link = api_n.registry.get_category( "/agreement_link/", None)
def _create_occi_server(self): api = api.build() occi_server = None self.occi_server = server.OcciServer(api=api) self.occi_server.start()
templates.load_templates(temps_dss) #Add Providers login credentials provider_details.load_providers() #Add monitoring capabilities and Collectos's API monitoring_details.load_monitoring_capabilities() clean_violation_from_db() if __name__ == "__main__": try: LOG.info("Starting OCCI server") init_environment() northbound_api = api.build() #start RulesEngine myRulesEngine = rulesengine.RulesEngine( northbound_api.registry) # Prepare intellect rules engine RE_thread = threading.Thread(target=myRulesEngine.start_engine, args=(15, )) RE_thread.daemon = True RE_thread.start() httpd = make_server('0.0.0.0', 8888, northbound_api) httpd.serve_forever() #tmps = json.load(file("tests/sample_data/template_definition.json")) #templates.load_templates(tmps) except KeyboardInterrupt:
def setUp(self): api_n = api.build() self.agreement_template = api_n.registry.get_category("/agreement_tpl/", None)