def _generate_vim_data(self, vim_file, name, description, vim_type, version=None): data = yaml.safe_load(read_file(vim_file)) password = data['password'] username = data['username'] project_name = data['project_name'] auth_url = data['auth_url'] if version: if ('v2' == version and (not auth_url.endswith("/v2.0") or not auth_url.endswith("/v2.0/"))): auth_url += "/v2.0" elif (not auth_url.endswith("/v3") or not auth_url.endswith("/v3/")): auth_url += "/v3" domain_name = data.get('domain_name', None) vim_arg = {'vim': {'name': name, 'description': description, 'type': vim_type, 'auth_url': auth_url, 'auth_cred': {'username': username, 'password': password, 'user_domain_name': domain_name}, 'vim_project': {'name': project_name, 'project_domain_name': domain_name}, 'is_default': False}} return data, vim_arg
def test_assign_floatingip_to_vdu(self): mead_file = 'sample_tosca_assign_floatingip_to_vdu.yaml' mea_name = 'Assign Floating IP to VDU' values_str = read_file(mead_file) template = yaml.safe_load(values_str) mea_arg = {'mea': {'mead_template': template, 'name': mea_name}} self.connect_public_and_private_nw_with_router() mea_instance = self.client.create_mea(body=mea_arg) mea_id = mea_instance['mea']['id'] self.addCleanup(self.wait_until_mea_delete, mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT) self.addCleanup(self.client.delete_mea, mea_id) self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) mea_show_out = self.client.show_mea(mea_id)['mea'] self.assertIsNotNone(mea_show_out['mgmt_url']) stack_id = mea_show_out['instance_id'] fip_res = self.get_heat_stack_resource(stack_id, 'FIP1') floating_ip_address = fip_res['attributes']['floating_ip_address'] self.assertIsNotNone(floating_ip_address) fip_port_id = fip_res['attributes']['port_id'] port_res = self.get_heat_stack_resource(stack_id, 'CP1') port_id = port_res['attributes']['id'] self.assertEqual(fip_port_id, port_id)
def heatclient(cls): data = yaml.safe_load(read_file('local-vim.yaml')) data['auth_url'] = data['auth_url'] + '/v3' domain_name = data.pop('domain_name') data['user_domain_name'] = domain_name data['project_domain_name'] = domain_name return clients.OpenstackClients(auth_attr=data).heat
def _test_create_nsd(self, tosca_nsd_file, nsd_name): input_yaml = read_file(tosca_nsd_file) tosca_dict = yaml.safe_load(input_yaml) tosca_arg = { 'nsd': { 'name': nsd_name, 'attributes': { 'nsd': tosca_dict } } } nsd_instance = self.client.create_nsd(body=tosca_arg) self.assertIsNotNone(nsd_instance) return nsd_instance['nsd']['id']
def _test_mead_create(self, mead_file, mead_name): yaml_input = read_file(mead_file) req_dict = {'mead': {'name': mead_name, 'attributes': {'mead': yaml_input}}} # Create mead mead_instance = self.client.create_mead(body=req_dict) self.assertIsNotNone(mead_instance) mead_id = mead_instance['mead']['id'] self.assertIsNotNone(mead_id) self.verify_mead_events( mead_id, evt_constants.RES_EVT_CREATE, evt_constants.RES_EVT_ONBOARDED) return mead_instance
def _test_create_tosca_mead(self, tosca_mead_file, mead_name): input_yaml = read_file(tosca_mead_file) tosca_dict = yaml.safe_load(input_yaml) tosca_arg = { 'mead': { 'name': mead_name, 'attributes': { 'mead': tosca_dict } } } mead_instance = self.client.create_mead(body=tosca_arg) self.assertEqual(mead_instance['mead']['name'], mead_name) self.assertIsNotNone(mead_instance) meads = self.client.list_meads().get('meads') self.assertIsNotNone(meads, "List of meads are Empty after Creation") return mead_instance['mead']['id']
def _test_mea_with_monitoring(self, mead_file, mea_name): data = dict() data['tosca'] = read_file(mead_file) toscal = data['tosca'] tosca_arg = { 'mead': { 'name': mea_name, 'attributes': { 'mead': toscal } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_arg = {'mea': {'mead_id': mead_id, 'name': mea_name}} mea_instance = self.client.create_mea(body=mea_arg) # Verify mea goes from ACTIVE->DEAD->ACTIVE states self.verify_mea_restart(mead_instance, mea_instance) # Delete mea_instance with mea_id mea_id = mea_instance['mea']['id'] try: self.client.delete_mea(mea_id) except Exception: assert False, ("Failed to delete mea %s after the monitor test" % mea_id) # Verify MEA monitor events captured for states, ACTIVE and DEAD mea_state_list = [evt_constants.ACTIVE, evt_constants.DEAD] self.verify_mea_monitor_events(mea_id, mea_state_list) # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id) self.addCleanup(self.wait_until_mea_delete, mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT)
def _test_create_list_delete_tosca_mead(self, tosca_mead_file, mead_name): input_yaml = read_file(tosca_mead_file) tosca_dict = yaml.safe_load(input_yaml) tosca_arg = {'mead': {'name': mead_name, 'attributes': {'mead': tosca_dict}}} mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) meads = self.client.list_meads().get('meads') self.assertIsNotNone(meads, "List of meads are Empty after Creation") mead_id = mead_instance['mead']['id'] self.verify_mead_events( mead_id, evt_constants.RES_EVT_CREATE, evt_constants.RES_EVT_ONBOARDED) try: self.client.delete_mead(mead_id) except Exception: assert False, "mead Delete failed" self.verify_mead_events(mead_id, evt_constants.RES_EVT_DELETE, evt_constants.RES_EVT_NA_STATE)
def test_mea_param_tosca_template(self): mead_name = 'cirros_mead_tosca_param' mead_instance = self._test_mead_create( 'sample-tosca-mead-param.yaml', mead_name) values_str = read_file('sample-tosca-mea-values.yaml') values_dict = yaml.safe_load(values_str) mea_instance, param_values_dict = self._test_mea_create(mead_instance, 'test_mea_with_parameters_tosca_template', values_dict) self.assertEqual(values_dict, param_values_dict) self._test_mea_delete(mea_instance) mea_id = mea_instance['mea']['id'] self.verify_mea_crud_events( mea_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE, cnt=2) self.verify_mea_crud_events( mea_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE) self.wait_until_mea_delete(mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_DELETE, evt_constants.PENDING_DELETE, cnt=2) self.addCleanup(self.client.delete_mead, mead_instance['mead']['id'])
def test_create_delete_mea_tosca_no_monitoring(self): mead_name = 'tosca_mead_with_auto_image' input_yaml = read_file('sample-tosca-mead-image.yaml') tosca_dict = yaml.safe_load(input_yaml) tosca_arg = { 'mead': { 'name': mead_name, 'attributes': { 'mead': tosca_dict } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_name = 'tosca_mea_with_auto_image' mea_arg = {'mea': {'mead_id': mead_id, 'name': mea_name}} mea_instance = self.client.create_mea(body=mea_arg) self.validate_mea_instance(mead_instance, mea_instance) mea_id = mea_instance['mea']['id'] self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) self.assertIsNotNone(self.client.show_mea(mea_id)['mea']['mgmt_url']) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE, cnt=2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE) servers = self.novaclient().servers.list() vdu_server = None for server in servers: if 'VDU1_image_func' in server.name: vdu_server = server break self.assertIsNotNone(vdu_server) image_id = vdu_server.image["id"] nova_images = self.novaclient().images image = nova_images.get(image_id) self.assertIsNotNone(image) self.assertEqual(True, "MEAImage_image_func" in image.name) # Delete mea_instance with mea_id try: self.client.delete_mea(mea_id) except Exception: assert False, "mea Delete failed" self.wait_until_mea_delete(mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_DELETE, evt_constants.PENDING_DELETE, cnt=2) # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id) self.assertRaises(exceptions.NotFound, nova_images.delete, [image_id])
def test_create_delete_tosca_mea_with_multiple_vdus(self): input_yaml = read_file('sample-tosca-mead-multi-vdu.yaml') tosca_dict = yaml.safe_load(input_yaml) mead_name = 'sample-tosca-mead-multi-vdu' tosca_arg = { 'mead': { 'name': mead_name, 'attributes': { 'mead': tosca_dict } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_arg = { 'mea': { 'mead_id': mead_id, 'name': "test_tosca_mea_with_multiple_vdus" } } mea_instance = self.client.create_mea(body=mea_arg) mea_id = mea_instance['mea']['id'] self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) self.assertEqual('ACTIVE', self.client.show_mea(mea_id)['mea']['status']) self.validate_mea_instance(mead_instance, mea_instance) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE, cnt=2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE) # Validate mgmt_url with input yaml file mgmt_url = self.client.show_mea(mea_id)['mea']['mgmt_url'] self.assertIsNotNone(mgmt_url) mgmt_dict = yaml.safe_load(str(mgmt_url)) input_dict = yaml.safe_load(input_yaml) toscautils.updateimports(input_dict) tosca = tosca_template.ToscaTemplate(parsed_params={}, a_file=False, yaml_dict_tpl=input_dict) vdus = toscautils.findvdus(tosca) self.assertEqual(len(vdus), len(mgmt_dict.keys())) for vdu in vdus: self.assertIsNotNone(mgmt_dict[vdu.name]) self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu.name])) # Delete mea_instance with mea_id try: self.client.delete_mea(mea_id) except Exception: assert False, "mea Delete of test_mea_with_multiple_vdus failed" self.wait_until_mea_delete(mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_DELETE, evt_constants.PENDING_DELETE, cnt=2) # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id)
def _test_create_delete_ns(self, nsd_file, ns_name, template_source='onboarded'): mead1_id = self._test_create_tosca_mead('test-ns-mead1.yaml', 'test-ns-mead1') mead2_id = self._test_create_tosca_mead('test-ns-mead2.yaml', 'test-ns-mead2') if template_source == 'onboarded': nsd_id = self._test_create_nsd(nsd_file, 'test-ns-nsd') ns_arg = { 'ns': { 'nsd_id': nsd_id, 'name': ns_name, 'attributes': { "param_values": { "nsd": { "vl2_name": "net0", "vl1_name": "net_mgmt" } } } } } ns_instance = self.client.create_ns(body=ns_arg) ns_id = ns_instance['ns']['id'] if template_source == 'inline': input_yaml = read_file(nsd_file) template = yaml.safe_load(input_yaml) ns_arg = { 'ns': { 'name': ns_name, 'attributes': { "param_values": { "nsd": { "vl2_name": "net0", "vl1_name": "net_mgmt" } } }, 'nsd_template': template } } ns_instance = self.client.create_ns(body=ns_arg) ns_id = ns_instance['ns']['id'] self._wait_until_ns_status(ns_id, 'ACTIVE', constants.NS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) ns_show_out = self.client.show_ns(ns_id)['ns'] self.assertIsNotNone(ns_show_out['mgmt_urls']) try: self.client.delete_ns(ns_id) except Exception as e: print("Exception:", e) assert False, "ns Delete failed" if template_source == 'onboarded': self._wait_until_ns_delete(ns_id, constants.NS_DELETE_TIMEOUT) self._test_delete_nsd(nsd_id) self._test_delete_mead(mead1_id) self._test_delete_mead(mead2_id)
def get_credentials(cls): vim_params = yaml.safe_load(read_file('local-vim.yaml')) vim_params['auth_url'] += '/v3' return vim_params
def _test_create_mea(self, mead_file, mea_name, template_source="onboarded"): data = dict() values_str = read_file(mead_file) data['tosca'] = values_str toscal = data['tosca'] tosca_arg = { 'mead': { 'name': mea_name, 'attributes': { 'mead': toscal } } } if template_source == "onboarded": # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_arg = {'mea': {'mead_id': mead_id, 'name': mea_name}} mea_instance = self.client.create_mea(body=mea_arg) self.validate_mea_instance(mead_instance, mea_instance) if template_source == 'inline': # create mea directly from template template = yaml.safe_load(values_str) mea_arg = {'mea': {'mead_template': template, 'name': mea_name}} mea_instance = self.client.create_mea(body=mea_arg) mead_id = mea_instance['mea']['mead_id'] mea_id = mea_instance['mea']['id'] self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) mea_show_out = self.client.show_mea(mea_id)['mea'] self.assertIsNotNone(mea_show_out['mgmt_url']) input_dict = yaml.safe_load(values_str) prop_dict = input_dict['topology_template']['node_templates']['CP1'][ 'properties'] # Verify if ip_address is static, it is same as in show_mea if prop_dict.get('ip_address'): mgmt_url_input = prop_dict.get('ip_address') mgmt_info = yaml.safe_load(mea_show_out['mgmt_url']) self.assertEqual(mgmt_url_input, mgmt_info['VDU1']) # Verify anti spoofing settings stack_id = mea_show_out['instance_id'] template_dict = input_dict['topology_template']['node_templates'] for field in template_dict.keys(): prop_dict = template_dict[field]['properties'] if prop_dict.get('anti_spoofing_protection'): self.verify_antispoofing_in_stack(stack_id=stack_id, resource_name=field) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE, cnt=2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE) return mead_id, mea_id
def test_create_delete_tosca_meac(self): input_yaml = read_file('sample_tosca_meac.yaml') tosca_dict = yaml.safe_load(input_yaml) path = os.path.abspath( os.path.join(os.path.dirname(__file__), "../../etc/samples")) mead_name = 'sample-tosca-meac' tosca_dict['topology_template']['node_templates' ]['firewall_meac' ]['interfaces' ]['Standard']['create'] = path \ + '/install_meac.sh' tosca_arg = { 'mead': { 'name': mead_name, 'attributes': { 'mead': tosca_dict } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_arg = {'mea': {'mead_id': mead_id, 'name': "test_tosca_meac"}} mea_instance = self.client.create_mea(body=mea_arg) mea_id = mea_instance['mea']['id'] self.wait_until_mea_active(mea_id, constants.MEAC_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) self.assertEqual('ACTIVE', self.client.show_mea(mea_id)['mea']['status']) self.validate_mea_instance(mead_instance, mea_instance) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE, cnt=2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE) # Validate mgmt_url with input yaml file mgmt_url = self.client.show_mea(mea_id)['mea']['mgmt_url'] self.assertIsNotNone(mgmt_url) mgmt_dict = yaml.safe_load(str(mgmt_url)) input_dict = yaml.safe_load(input_yaml) toscautils.updateimports(input_dict) tosca = tosca_template.ToscaTemplate(parsed_params={}, a_file=False, yaml_dict_tpl=input_dict) vdus = toscautils.findvdus(tosca) self.assertEqual(len(vdus), len(mgmt_dict.keys())) for vdu in vdus: self.assertIsNotNone(mgmt_dict[vdu.name]) self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu.name])) # Check the status of SoftwareDeployment heat_stack_id = self.client.show_mea(mea_id)['mea']['instance_id'] resource_types = self.h_client.resources resources = resource_types.list(stack_id=heat_stack_id) for resource in resources: resource = resource.to_dict() if resource['resource_type'] == \ SOFTWARE_DEPLOYMENT: self.assertEqual('CREATE_COMPLETE', resource['resource_status']) break # Delete mea_instance with mea_id try: self.client.delete_mea(mea_id) except Exception: assert False, "mea Delete of test_mea_with_multiple_vdus failed" self.wait_until_mea_delete(mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_DELETE, evt_constants.PENDING_DELETE, cnt=2) # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id)
def _test_create_delete_mea(self, mea_name, mead_name, vim_id=None): data = dict() data['tosca'] = read_file('sample-tosca-mead-no-monitor.yaml') toscal = data['tosca'] tosca_arg = { 'mead': { 'name': mead_name, 'attributes': { 'mead': toscal } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_arg = {'mea': {'mead_id': mead_id, 'name': mea_name}} if vim_id: mea_arg['mea']['vim_id'] = vim_id mea_instance = self.client.create_mea(body=mea_arg) self.validate_mea_instance(mead_instance, mea_instance) mea_id = mea_instance['mea']['id'] self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) self.assertIsNotNone(self.client.show_mea(mea_id)['mea']['mgmt_url']) if vim_id: self.assertEqual(vim_id, mea_instance['mea']['vim_id']) # Get mea details when mea is in active state mea_details = self.client.list_mea_resources(mea_id)['resources'][0] self.assertIn('name', mea_details) self.assertIn('id', mea_details) self.assertIn('type', mea_details) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.PENDING_CREATE, cnt=2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE) # update VIM name when MEAs are active. # check for exception. vim0_id = mea_instance['mea']['vim_id'] msg = "VIM %s is still in use by MEA" % vim0_id try: update_arg = {'vim': {'name': "mea_vim"}} self.client.update_vim(vim0_id, update_arg) except Exception as err: self.assertEqual(err.message, msg) else: self.assertTrue( False, "Name of vim(s) with active mea(s) should not be changed!") # Delete mea_instance with mea_id try: self.client.delete_mea(mea_id) except Exception: assert False, "mea Delete failed" self.wait_until_mea_delete(mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_DELETE, evt_constants.PENDING_DELETE, cnt=2) # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id)
def test_mea_tosca_scale(self): data = dict() data['tosca'] = read_file('sample-tosca-scale-all.yaml') mead_name = 'test_tosca_mea_scale_all' toscal = data['tosca'] tosca_arg = { 'mead': { 'name': mead_name, 'attributes': { 'mead': toscal } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_name = 'test_tosca_mea_scale_all' mea_arg = {'mea': {'mead_id': mead_id, 'name': mea_name}} mea_instance = self.client.create_mea(body=mea_arg) self.validate_mea_instance(mead_instance, mea_instance) mea_id = mea_instance['mea']['id'] # TODO(kanagaraj-manickam) once load-balancer support is enabled, # update this logic to validate the scaling def _wait(count): self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) mea = self.client.show_mea(mea_id)['mea'] # {"VDU1": ["10.0.0.14", "10.0.0.5"]} self.assertEqual(count, len(json.loads(mea['mgmt_url'])['VDU1'])) _wait(2) # Get nested resources when mea is in active state mea_details = self.client.list_mea_resources(mea_id)['resources'] resources_list = list() for mea_detail in mea_details: resources_list.append(mea_detail['name']) self.assertIn('VDU1', resources_list) self.assertIn('CP1', resources_list) self.assertIn('SP1_group', resources_list) def _scale(type, count): body = {"scale": {'type': type, 'policy': 'SP1'}} self.client.scale_mea(mea_id, body) _wait(count) # scale out time.sleep(constants.SCALE_WINDOW_SLEEP_TIME) _scale('out', 3) # scale in time.sleep(constants.SCALE_WINDOW_SLEEP_TIME) _scale('in', 2) # Verifying that as part of SCALE OUT, MEA states PENDING_SCALE_OUT # and ACTIVE occurs and as part of SCALE IN, MEA states # PENDING_SCALE_IN and ACTIVE occur. self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_SCALE, evt_constants.ACTIVE, cnt=2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_SCALE, evt_constants.PENDING_SCALE_OUT, cnt=1) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_SCALE, evt_constants.PENDING_SCALE_IN, cnt=1) # Delete mea_instance with mea_id try: self.client.delete_mea(mea_id) except Exception: assert False, "mea Delete failed" # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id) self.addCleanup(self.wait_until_mea_delete, mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT)
def _test_mea_tosca_alarm(self, mead_file, mea_name): mea_trigger_path = '/meas/%s/triggers' data = dict() data['tosca'] = read_file(mead_file) tosca_dict = yaml.safe_load(data['tosca']) toscal = data['tosca'] tosca_arg = { 'mead': { 'name': mea_name, 'attributes': { 'mead': toscal } } } # Create mead with tosca template mead_instance = self.client.create_mead(body=tosca_arg) self.assertIsNotNone(mead_instance) # Create mea with mead_id mead_id = mead_instance['mead']['id'] mea_arg = {'mea': {'mead_id': mead_id, 'name': mea_name}} mea_instance = self.client.create_mea(body=mea_arg) self.validate_mea_instance(mead_instance, mea_instance) mea_id = mea_instance['mea']['id'] def _waiting_time(count): self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) mea = self.client.show_mea(mea_id)['mea'] # {"VDU1": ["10.0.0.14", "10.0.0.5"]} self.assertEqual(count, len(json.loads(mea['mgmt_url'])['VDU1'])) def trigger_mea(mea, policy_name, policy_action): credential = 'g0jtsxu9' body = { "trigger": { 'policy_name': policy_name, 'action_name': policy_action, 'params': { 'data': { 'alarm_id': '35a80852-e24f-46ed-bd34-e2f831d00172', 'current': 'alarm' }, # noqa 'credential': credential } } } self.client.post(mea_trigger_path % mea, body) def _inject_monitoring_policy(mead_dict): polices = mead_dict['topology_template'].get('policies', []) mon_policy = dict() for policy_dict in polices: for name, policy in policy_dict.items(): if policy['type'] == constants.POLICY_ALARMING: triggers = policy['triggers'] for trigger_name, trigger_dict in triggers.items(): policy_action_list = trigger_dict['action'] for policy_action_name in policy_action_list: mon_policy[trigger_name] = policy_action_name return mon_policy def verify_policy(policy_dict, kw_policy): for name, action in policy_dict.items(): if kw_policy in name: return name # trigger alarm monitoring_policy = _inject_monitoring_policy(tosca_dict) for mon_policy_name, mon_policy_action in monitoring_policy.items(): if mon_policy_action in constants.DEFAULT_ALARM_ACTIONS: self.wait_until_mea_active(mea_id, constants.MEA_CIRROS_CREATE_TIMEOUT, constants.ACTIVE_SLEEP_TIME) trigger_mea(mea_id, mon_policy_name, mon_policy_action) else: if 'scaling_out' in mon_policy_name: _waiting_time(2) time.sleep(constants.SCALE_WINDOW_SLEEP_TIME) # scaling-out backend action scaling_out_action = mon_policy_action + '-out' trigger_mea(mea_id, mon_policy_name, scaling_out_action) _waiting_time(3) scaling_in_name = verify_policy(monitoring_policy, kw_policy='scaling_in') if scaling_in_name: time.sleep(constants.SCALE_WINDOW_SLEEP_TIME) # scaling-in backend action scaling_in_action = mon_policy_action + '-in' trigger_mea(mea_id, scaling_in_name, scaling_in_action) _waiting_time(2) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_SCALE, evt_constants.ACTIVE, cnt=2) self.verify_mea_crud_events( mea_id, evt_constants.RES_EVT_SCALE, evt_constants.PENDING_SCALE_OUT, cnt=1) self.verify_mea_crud_events(mea_id, evt_constants.RES_EVT_SCALE, evt_constants.PENDING_SCALE_IN, cnt=1) # Delete mea_instance with mea_id try: self.client.delete_mea(mea_id) except Exception: assert False, ("Failed to delete mea %s after the monitor test" % mea_id) # Verify MEA monitor events captured for states, ACTIVE and DEAD mea_state_list = [evt_constants.ACTIVE, evt_constants.DEAD] self.verify_mea_monitor_events(mea_id, mea_state_list) # Delete mead_instance self.addCleanup(self.client.delete_mead, mead_id) self.addCleanup(self.wait_until_mea_delete, mea_id, constants.MEA_CIRROS_DELETE_TIMEOUT)