def test_neutron(self): """neutron test This test validate correctness topology graph with neutron module """ # Action nova_utils.create_instances(num_instances=self.NUM_INSTANCE, set_public_network=True) # Calculate expected results api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1 + self.NUM_INSTANCE, instance_entities=self.NUM_INSTANCE, instance_edges=2 * self.NUM_INSTANCE, network_entities=self.num_default_networks, network_edges=self.num_default_ports + self.NUM_INSTANCE, port_entities=self.num_default_ports + self.NUM_INSTANCE, port_edges=self.num_default_ports + 2 * self.NUM_INSTANCE) num_entities = self.num_default_entities + \ 2 * self.NUM_INSTANCE + \ self.num_default_networks + self.num_default_ports num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \ self.num_default_ports # Test Assertions self._validate_graph_correctness(graph, num_entities, num_edges, entities)
def test_gnocchi_aggregation_by_metrics_threshold_alarm(self): try: # Action nova_utils.create_instances(num_instances=self.NUM_INSTANCE) aodh_utils.create_aodh_metrics_threshold_alarm() api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1 + self.NUM_INSTANCE, instance_entities=self.NUM_INSTANCE, instance_edges=2 * self.NUM_INSTANCE, aodh_entities=self.NUM_ALARM, aodh_edges=0) num_entities = self.num_default_entities + \ 2 * self.NUM_INSTANCE + self.NUM_ALARM + \ self.num_default_networks + self.num_default_ports num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \ self.num_default_ports self._validate_graph_correctness(graph, num_entities, num_edges, entities) except Exception as e: self._handle_exception(e) raise finally: aodh_utils.delete_all_aodh_alarms() aodh_utils.delete_all_gnocchi_metrics() nova_utils.delete_all_instances()
def test_validate_rca(self): """validate_rca test There tests validates correctness of rca of created aodh event alarm and correctness of relationship between host alarm to instance alarms (created by special template file), source alarm - aodh alarm on host target alarms - 2 instance alarms (caused 2 created instance) """ try: nova_utils.create_instances(num_instances=2, set_public_network=True) host_alarm = self._create_alarm(resource_id=self._get_hostname(), alarm_name=RCA_ALARM_NAME) api_rca = self.vitrage_client.rca.get(alarm_id=host_alarm.get( VProps.VITRAGE_ID), all_tenants=True) self._validate_rca(rca=api_rca['nodes']) self._validate_relationship(links=api_rca['links'], alarms=api_rca['nodes']) except Exception as e: self._handle_exception(e) raise finally: self._clean_all()
def test_alarm_with_resource_id(self): try: # Action nova_utils.create_instances(num_instances=self.NUM_INSTANCE) aodh_utils.create_aodh_alarm(self._find_instance_resource_id()) # Calculate expected results api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1 + self.NUM_INSTANCE, instance_entities=self.NUM_INSTANCE, instance_edges=2 * self.NUM_INSTANCE + self.NUM_ALARM, aodh_entities=self.NUM_ALARM, aodh_edges=self.NUM_ALARM) num_entities = self.num_default_entities + \ 2 * self.NUM_INSTANCE + self.NUM_ALARM + \ self.num_default_networks + self.num_default_ports num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \ self.NUM_ALARM + self.num_default_ports # Test Assertions self._validate_graph_correctness(graph, num_entities, num_edges, entities) except Exception as e: self._handle_exception(e) raise finally: aodh_utils.delete_all_aodh_alarms() nova_utils.delete_all_instances()
def test_gnocchi_aggregation_by_resources_threshold(self): # Action nova_utils.create_instances(num_instances=self.NUM_INSTANCE) aodh_utils.create_aodh_resources_threshold_alarm( resource_id=self._find_instance_resource_id()) api_graph = self.vitrage_client.topology.get(all_tenants=True) graph = self._create_graph_from_graph_dictionary(api_graph) entities = self._entities_validation_data( host_entities=1, host_edges=1 + self.NUM_INSTANCE, instance_entities=self.NUM_INSTANCE, instance_edges=2 * self.NUM_INSTANCE + self.NUM_ALARM, aodh_entities=self.NUM_ALARM, aodh_edges=self.NUM_ALARM) num_entities = self.num_default_entities + \ 2 * self.NUM_INSTANCE + self.NUM_ALARM + \ self.num_default_networks + self.num_default_ports num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \ + self.NUM_ALARM + self.num_default_ports self._validate_graph_correctness(graph, num_entities, num_edges, entities)
def test_action_set_state_instance(self): vm_id = "" try: vm_id = nova_utils.create_instances(set_public_network=True)[0].id # Do orig_instance = v_utils.get_first_instance(id=vm_id) self._trigger_do_action(TRIGGER_ALARM_3) curr_instance = v_utils.get_first_instance(id=vm_id) self.assertEqual( 'ERROR', curr_instance.get(VProps.VITRAGE_AGGREGATED_STATE), 'state should change after set_state action') # Undo self._trigger_undo_action(TRIGGER_ALARM_3) curr_instance = v_utils.get_first_instance(id=vm_id) self.assertEqual( orig_instance.get(VProps.VITRAGE_AGGREGATED_STATE), curr_instance.get(VProps.VITRAGE_AGGREGATED_STATE), 'state should change after undo set_state action') except Exception as e: self._handle_exception(e) raise finally: self._trigger_undo_action(TRIGGER_ALARM_3) nova_utils.delete_all_instances(id=vm_id)
def test_compare_cli_and_api(self): """compare_cli_and_api test There test validate correctness of rca of created aodh event alarms, and equals them with cli rca """ try: instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'Failed to create instance') instance_alarm = self._create_alarm( resource_id=instances[0].id, alarm_name='instance_rca_alarm', unic=True) vitrage_id = instance_alarm.get(VProps.VITRAGE_ID) api_rca = self.vitrage_client.rca.get(alarm_id=vitrage_id) cli_rca = utils.run_vitrage_command( 'vitrage rca show ' + vitrage_id, self.conf) self._compare_rca(api_rca, cli_rca) except Exception as e: self._handle_exception(e) raise finally: self._clean_all()
def test_execute_mistral_more_than_once(self): executions = self.mistral_client.executions.list() self.assertIsNotNone(executions, 'Failed to get the list of workflow executions') num_executions = len(executions) # Make sure there are at least two instances in the environment nova_utils.create_instances(num_instances=2, set_public_network=True) num_instances = len(TempestClients.nova().servers.list()) # Add a template that executes the same Mistral workflow for every # instance. This should immediately trigger execute_mistral actions. template = None try: template = v_utils.add_template('v3_execute_mistral_twice.yaml') finally: if template: v_utils.delete_template(template['uuid']) # no longer needed time.sleep(2) # wait for the evaluator to process the new template # Verify that there is an execution for every instance executions = self.mistral_client.executions.list() self.assertIsNotNone(executions, 'Failed to get the list of workflow executions') msg = "There are %d executions. Expected number of executions: %d " \ "(old number of executions) + %d (number of instances)" % \ (len(executions), num_executions, num_instances) self.assertThat(executions, HasLength(num_executions + num_instances), msg) executed_on_instances = set() for i in range(num_instances): # There may be many old executions in the list. The relevant ones # are at the end. Check the last `num_instances` executions. execution = \ self.mistral_client.executions.get(executions[-i].id) execution_input = jsonutils.loads(execution.input) executed_on_instances.add(execution_input['farewell']) msg = "There are %d instances in the graph but only %d distinct " \ "executions" % (num_instances, len(executed_on_instances)) self.assertThat(executed_on_instances, HasLength(num_instances), msg)
def _create_entities(self, num_instances, num_volumes=0, end_sleep=3): resources = nova_utils.create_instances(num_instances) self.assertThat(resources, IsNotEmpty(), 'The instances list is empty') if num_volumes > 0: cinder_utils.create_volume_and_attach('volume-1', 1, resources[0].id, '/tmp/vda') # waiting until all the entities creation were processed by the # entity graph processor time.sleep(end_sleep)
def test_validate_notifier(self): """validate_notifier test There tests validates work of aodh alarm notifier - all created vitrage alarms appears in ceilometer alarms-list. IMPORTANT: enable notifiers=aodh in vitrage.conf file """ try: nova_utils.create_instances(num_instances=2, set_public_network=True) self._create_alarm(resource_id=self._get_hostname(), alarm_name=RCA_ALARM_NAME) vitrage_alarms = TempestClients.vitrage().alarm.list( vitrage_id='all', all_tenants=True) aodh_alarms = TempestClients.aodh().alarm.list() self._validate_notifier(alarms=aodh_alarms, vitrage_alarms=vitrage_alarms) except Exception as e: self._handle_exception(e) raise finally: self._clean_all()
def test_validate_deduce_alarms(self): """validate_deduce_alarms test There tests validates correctness of deduce alarms (created by special template file), and equals there resource_id with created instances id """ instances = nova_utils.create_instances(num_instances=2, set_public_network=True) self._create_alarm(resource_id=self._get_hostname(), alarm_name=RCA_ALARM_NAME) api_alarms = self.vitrage_client.alarm.list(vitrage_id='all', all_tenants=True) self._validate_deduce_alarms(alarms=api_alarms, instances=instances)
def test_resource_list_with_no_existing_type(self): """resource list with no existing type""" try: instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'The instances list is empty') resources = self.vitrage_client.resource.list( resource_type=CINDER_VOLUME_DATASOURCE, all_tenants=True) self.assertThat(resources, IsEmpty()) except Exception as e: self._handle_exception(e) raise finally: nova_utils.delete_all_instances()
def test_validate_set_state(self): """validate_set_state test There tests validates correctness of topology resource state, after alarms creation (by special template file), source state - ERROR target state - SUBOPTIMAL (caused 2 created instance) """ instances = nova_utils.create_instances(num_instances=2, set_public_network=True) self._create_alarm(resource_id=self._get_hostname(), alarm_name=RCA_ALARM_NAME) topology = self.vitrage_client.topology.get(all_tenants=True) self._validate_set_state(topology=topology['nodes'], instances=instances)
def _do_test_action_mark_down_instance(self, trigger_name): vm_id = "" try: vm_id = nova_utils.create_instances(set_public_network=True)[0].id # Do self._trigger_do_action(trigger_name) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ERROR", nova_instance.status) # Undo self._trigger_undo_action(trigger_name) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ACTIVE", nova_instance.status) finally: self._trigger_undo_action(trigger_name) nova_utils.delete_all_instances(id=vm_id)
def test_default_resource_list(self): """resource list with default query get the resources: network, instance, port """ try: instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'The instances list is empty') resources = self.vitrage_client.resource.list(all_tenants=False) self.assertThat(resources, matchers.HasLength(3)) except Exception as e: self._handle_exception(e) raise finally: nova_utils.delete_all_instances()
def test_resource_list_with_existing_type(self): """resource list with existing type get the resource: one instance """ try: instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'The instances list is empty') resources = self.vitrage_client.resource.list( resource_type=NOVA_INSTANCE_DATASOURCE, all_tenants=True) self.assertThat(resources, matchers.HasLength(1)) except Exception as e: self._handle_exception(e) raise finally: nova_utils.delete_all_instances()
def test_resource_list_with_all_tenants(self): """resource list with all tenants get the resources: """ instances = None try: resources_before = self.vitrage_client.resource.list( all_tenants=True) instances = nova_utils.create_instances(num_instances=1, set_public_network=True) resources = self.vitrage_client.resource.list(all_tenants=True) self.assertEqual(len(resources_before) + 2, len(resources)) finally: if instances: nova_utils.delete_created_instances(instances)
def test_action_mark_down_instance(self): vm_id = "" try: vm_id = nova_utils.create_instances(set_public_network=True)[0].id # Do self._trigger_do_action(TRIGGER_ALARM_5) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ERROR", str(nova_instance.status)) # Undo self._trigger_undo_action(TRIGGER_ALARM_5) nova_instance = TempestClients.nova().servers.get(vm_id) self.assertEqual("ACTIVE", str(nova_instance.status)) except Exception as e: self._handle_exception(e) raise finally: pass self._trigger_undo_action(TRIGGER_ALARM_5) nova_utils.delete_all_instances(id=vm_id)
def test_compare_cli_vs_api_resource_list(self): """resource list """ try: instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'The instances list is empty') api_resources = self.vitrage_client.resource.list( all_tenants=True) LOG.info("api_resources = %s", api_resources) cli_resources = utils.run_vitrage_command( 'vitrage resource list --all -f json', self.conf) self._compare_resources(api_resources, cli_resources) except Exception as e: self._handle_exception(e) raise finally: nova_utils.delete_all_instances()
def test_resource_list_with_all_tenants(self): """resource list with all tenants get the resources: """ try: resources_before = self.vitrage_client.resource.list( all_tenants=True) instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'The instances list is empty') resources = self.vitrage_client.resource.list(all_tenants=True) self.assertEqual(len(resources_before) + 2, len(resources)) except Exception as e: self._handle_exception(e) raise finally: nova_utils.delete_all_instances()
def test_compare_cli_vs_api_alarms(self): """Wrapper that returns a test graph.""" try: instances = nova_utils.create_instances(num_instances=1, set_public_network=True) self.assertThat(instances, IsNotEmpty(), 'The instances list is empty') aodh_utils.create_aodh_alarm(resource_id=instances[0].id, name='tempest_aodh_test') api_alarms = TempestClients.vitrage().alarm.list(vitrage_id='all', all_tenants=True) cli_alarms = utils.run_vitrage_command('vitrage alarm list', self.conf) self._compare_alarms_lists(api_alarms, cli_alarms, AODH_DATASOURCE, instances[0].id) except Exception as e: self._handle_exception(e) raise finally: aodh_utils.delete_all_aodh_alarms() nova_utils.delete_all_instances()
def _do_test_action_set_state_instance(self, trigger_name): vm_id = "" try: vm_id = nova_utils.create_instances(set_public_network=True)[0].id # Do orig_instance = v_utils.get_first_instance(id=vm_id) self._trigger_do_action(trigger_name) curr_instance = v_utils.get_first_instance(id=vm_id) self.assertEqual( 'ERROR', curr_instance.get(VProps.VITRAGE_AGGREGATED_STATE), 'state should change after set_state action') # Undo self._trigger_undo_action(trigger_name) curr_instance = v_utils.get_first_instance(id=vm_id) self.assertEqual( orig_instance.get(VProps.VITRAGE_AGGREGATED_STATE), curr_instance.get(VProps.VITRAGE_AGGREGATED_STATE), 'state should change after undo set_state action') finally: self._trigger_undo_action(trigger_name) nova_utils.delete_all_instances(id=vm_id)
def setUpClass(cls): super(TestResource, cls).setUpClass() cls.instances = nova_utils.create_instances(num_instances=1, set_public_network=True)