Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
    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()
Пример #4
0
    def test_compare_cli_and_api(self):
        """compare_cli_and_api test

        There test validate correctness of rca of created
        aodh event alarms, and compare them with cli rca
        """
        try:
            instances = nova_utils.create_instances(num_instances=1,
                                                    set_public_network=True)
            self.assertNotEqual(len(instances), 0, '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()
Пример #5
0
    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 = vitrage_utils.get_first_instance(id=vm_id)
            self._trigger_do_action(TRIGGER_ALARM_3)
            curr_instance = vitrage_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 = vitrage_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)
Пример #6
0
    def _create_entities(self, num_instances=0, num_volumes=0, end_sleep=3):
        if num_instances > 0:
            resources = nova_utils.create_instances(num_instances)

        self.assertNotEqual(len(resources), 0, '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)
Пример #7
0
    def test_neutron(self):
        """neutron test

        This test validate correctness topology graph with neutron module
        """

        try:
            # 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)
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            nova_utils.delete_all_instances()
Пример #8
0
 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.assertNotEqual(len(instances), 0,
                             'The instances list is empty')
         resources = self.vitrage_client.resource.list(
             resource_type=CINDER_VOLUME_DATASOURCE,
             all_tenants=True)
         self.assertEqual(0, len(resources))
     except Exception as e:
         self._handle_exception(e)
         raise
     finally:
         nova_utils.delete_all_instances()
Пример #9
0
    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.assertNotEqual(len(instances), 0,
                                'The instances list is empty')
            resources = self.vitrage_client.resource.list(all_tenants=False)
            self.assertEqual(3, len(resources))
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            nova_utils.delete_all_instances()
Пример #10
0
    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.assertNotEqual(len(instances), 0,
                                'The instances list is empty')
            api_resources = self.vitrage_client.resource.list(
                all_tenants=True)
            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()
Пример #11
0
    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_3)
            nova_instance = TempestClients.nova().servers.get(vm_id)
            self.assertEqual("ERROR", str(nova_instance.status))

            # Undo
            self._trigger_undo_action(TRIGGER_ALARM_3)
            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_3)
            nova_utils.delete_all_instances(id=vm_id)
Пример #12
0
    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.assertNotEqual(len(instances), 0,
                                '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()
Пример #13
0
    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.assertNotEqual(len(instances), 0,
                                '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()
Пример #14
0
    def test_validate_deduce_alarms(self):
        """validate_deduce_alarms test

        There tests validates correctness of deduce alarms
        (created by special template file), and compare there
        resource_id with created instances id
        """
        try:
            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)
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._clean_all()
Пример #15
0
    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)
        """
        try:
            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)
        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._clean_all()
Пример #16
0
    def test_create_instance(self):
        """This function validates creating instance events.

        Create instance generates three ordered events.
        1. neutron port is created.
        2. the port is updated to the created instance.
        3. nova instance is created with the given hostname.
        """
        try:

            # Action
            time_before_action = datetime.datetime.utcnow()
            nova_utils.create_instances(num_instances=1,
                                        name=INSTANCE_NAME,
                                        set_public_network=True)

            writen_events = self._load_db_events(time_before_action)

            port_create_event = get_first_match(writen_events,
                                                PORT_CREATE_EVENT)

            self.assertIsNotNone(port_create_event,
                                 "port.create.end event is not writen to db")

            port_update_event = get_first_match(writen_events,
                                                PORT_UPDATE_EVENT)

            self.assertIsNotNone(port_update_event,
                                 "port.update.end event is not writen to db")

            instance_create_event = get_first_match(writen_events,
                                                    INSTANCE_CREATE_EVENT)

            self.assertIsNotNone(
                instance_create_event,
                "compute.instance.create.end event is not "
                "writen to db")

            # Check correct timestamp order
            events_timestamp_list = \
                [port_create_event.collector_timestamp,
                 port_update_event.collector_timestamp,
                 instance_create_event.collector_timestamp]

            self.assertEqual(sorted(events_timestamp_list),
                             events_timestamp_list,
                             "Events Timestamp order is wrong")

            # Check correct event_id order
            events_id_list = \
                [port_create_event.event_id,
                 port_update_event.event_id,
                 instance_create_event.event_id]

            self.assertEqual(sorted(events_id_list), events_id_list,
                             "Events id order is wrong")

        except Exception as e:
            self._handle_exception(e)
            raise

        finally:
            nova_utils.delete_all_instances()