Exemplo n.º 1
0
    def test_template_add(self):
        """template add test

        test standard , definition and equivalence templates
        """
        # TODO(ikinory): add folder of templates
        # Add standard ,equivalence and definition templates
        self._add_templates()
        # assert standard template
        db_row = v_utils.get_first_template(
            name='host_high_memory_usage_scenarios', type=TTypes.STANDARD)
        self.assertEqual(db_row['name'], 'host_high_memory_usage_scenarios',
                         'standard template not found in list')

        # assert equivalence template
        db_row = v_utils.get_first_template(name='entity equivalence example',
                                            type=TTypes.EQUIVALENCE)
        self.assertEqual(db_row['name'], 'entity equivalence example',
                         'equivalence template not found in list')

        # assert definition template
        db_row = v_utils.get_first_template(name='basic_def_template',
                                            type=TTypes.DEFINITION,
                                            status=TemplateStatus.ACTIVE)

        self.assertEqual(db_row['name'], 'basic_def_template',
                         'definition template not found in list')

        # assert corrupted template - validate failed
        db_row = v_utils.get_first_template(name='corrupted_template',
                                            type=TTypes.STANDARD,
                                            status=TemplateStatus.ERROR)
        self.assertIsNotNone(db_row,
                             'corrupted template template presented in list')
Exemplo n.º 2
0
 def _rollback_to_default(self, templates):
     try:
         for t in templates:
             db_row = vitrage_utils.get_first_template(name=t)
             vitrage_utils.delete_template(db_row['uuid'])
     except Exception as e:
         raise VitrageError('Rollback to default failed %s', e)
 def setUpClass(cls):
     super(TestLongProcessing, cls).setUpClass()
     logger = logging.getLogger('vitrageclient.v1.client').logger
     logger.setLevel(logging.INFO)
     if v_utils.get_first_template(name=TEMPLATE_NAME):
         v_utils.delete_template(name=TEMPLATE_NAME)
         time.sleep(SLEEP)
    def test_db_init(self):
        try:
            v_utils.add_template(TEMPLATE_NAME)
            time.sleep(SLEEP)

            # 1. check template works well
            self._check_template_instance_3rd_degree_scenarios()

            # 2. check fast fail-over - start from database
            topo1 = TempestClients.vitrage().topology.get(all_tenants=True)
            v_utils.restart_graph()
            time.sleep(MAX_FAIL_OVER_TIME)
            for i in range(5):
                self._check_template_instance_3rd_degree_scenarios()
                topo2 = TempestClients.vitrage().topology.get(all_tenants=True)
                self.assert_graph_equal(
                    topo1, topo2, 'comparing graph items iteration ' + str(i))
                time.sleep(self.conf.datasources.snapshots_interval)

            v_utils.delete_template(name=TEMPLATE_NAME)
            time.sleep(SLEEP)
            self._check_template_instance_3rd_degree_scenarios_deleted()

        except Exception as e:
            self._handle_exception(e)
            if v_utils.get_first_template(name=TEMPLATE_NAME):
                v_utils.delete_template(name=TEMPLATE_NAME)
                time.sleep(SLEEP)
            raise
    def test_template_delete(self):
        try:

            # add standard template
            v_utils.add_template(STANDARD_TEMPLATE,
                                 template_type=TTypes.STANDARD)
            db_row = v_utils.get_first_template(
                name='host_high_memory_usage_scenarios',
                type=TTypes.STANDARD,
                status=TemplateStatus.ACTIVE)
            self.assertIsNotNone(db_row,
                                 'Template should appear in templates list')

            # delete template
            uuid = db_row['uuid']
            v_utils.delete_template(uuid)
            db_row = v_utils.get_first_template(
                name='host_high_memory_usage_scenarios', type=TTypes.STANDARD)
            self.assertIsNone(db_row, 'Template should not appear in list')

        except Exception as e:
            self._handle_exception(e)
            raise
Exemplo n.º 6
0
    def _add_delete_template_with_name(self):
        """A helper function:

            Adds and deletes a template.
            Returns its name.
        """

        # add a template
        v_utils.add_template(STANDARD_TEMPLATE, template_type=TTypes.STANDARD)
        db_row = v_utils.get_first_template(
            name='host_high_memory_usage_scenarios',
            type=TTypes.STANDARD,
            status=TemplateStatus.ACTIVE)
        self.assertIsNotNone(db_row,
                             'Template should appear in templates list')

        # delete it
        name = db_row['name']
        v_utils.delete_template_with_name(name)
        db_row = v_utils.get_first_template(
            name='host_high_memory_usage_scenarios', type=TTypes.STANDARD)
        self.assertIsNone(db_row, 'Template should not appear in list')

        return name
    def test_evaluator_reload_with_multiple_new_template(self):
        """Test reload new template e2e

        1. raise trigger alarm (template is not loaded yet)
        2. add 2 new templates.
        3. check both actions are executed
        This checks that the evaluators are reloaded for both templates
         and run on all existing vertices.
        """
        second_template = None
        try:
            host_id = self.orig_host.get(VProps.VITRAGE_ID)
            self._trigger_do_action(TRIGGER_ALARM_1)
            self._trigger_do_action(TRIGGER_ALARM_2)
            v_util.add_template(folder=FOLDER_PATH)
            self.added_template = v_util.get_first_template(name=INFILE_NAME)
            second_template = v_util.get_first_template(name=INFILE_NAME_2)
            self._check_deduced(1, DEDUCED_PROPS, host_id)
            self._check_deduced(1, DEDUCED_PROPS_2, host_id)
        finally:
            if second_template:
                v_util.delete_template(second_template['uuid'])
            self._trigger_undo_action(TRIGGER_ALARM_1)
            self._trigger_undo_action(TRIGGER_ALARM_2)
Exemplo n.º 8
0
 def test_template_show_with_name(self):
     """Compare template content from file to DB"""
     # add standard template
     template_path = \
         g_utils.tempest_resources_dir() + '/templates/api/' \
         + STANDARD_TEMPLATE
     v_utils.add_template(STANDARD_TEMPLATE, template_type=TTypes.STANDARD)
     name = 'host_high_memory_usage_scenarios'
     db_row = v_utils.get_first_template(name=name,
                                         type=TTypes.STANDARD,
                                         status=TemplateStatus.ACTIVE)
     payload_from_db = self.vitrage_client.template.show(name)
     with open(template_path, 'r') as stream:
         payload_from_file = yaml.load(stream, Loader=yaml.BaseLoader)
     self.assert_dict_equal(payload_from_file, payload_from_db,
                            "Template content doesn't match")
     v_utils.delete_template(db_row['uuid'])
    def test_high_availability_events(self):
        """The purpose of the test is to check that events are stored

        That is, during different stages in vitrage-graph lifetime:
        before graph read from db (during init)
        after graph read from db (during init)
        during get_all
        after get_all
        """
        try:
            # adding a template just to create more load (to slow things down)
            v_utils.add_template(TEMPLATE_NAME)
            time.sleep(SLEEP)
            self.keep_sending_events = True
            self.num_of_sent_events = 0

            doctor_events_thread = self._async_doctor_events()
            time.sleep(10)
            v_utils.stop_graph()
            time.sleep(10)
            v_utils.restart_graph()
            v_utils.delete_template(name=TEMPLATE_NAME)

            # sleep to allow get_all to start and finish at least once:
            time.sleep(4 * self.conf.datasources.snapshots_interval)

            v_utils.restart_graph()
            self.keep_sending_events = False
            time.sleep(MAX_FAIL_OVER_TIME)
            doctor_events_thread.join(timeout=10)

            alarm_count = TempestClients.vitrage().alarm.count(
                all_tenants=True)
            self.assertTrue(self.num_of_sent_events > 0,
                            'Test did not create events')
            self.assertEqual(self.num_of_sent_events, alarm_count['CRITICAL'],
                             'CRITICAL doctor events expected')

        except Exception as e:
            self._handle_exception(e)
            raise
        finally:
            self._remove_doctor_events()
            if v_utils.get_first_template(name=TEMPLATE_NAME):
                v_utils.delete_template(name=TEMPLATE_NAME)
            time.sleep(SLEEP)
Exemplo n.º 10
0
 def test_template_show(self):
     """Compare template content from file to DB"""
     try:
         # add standard template
         template_path = \
             g_utils.tempest_resources_dir() + '/templates/api/'\
             + STANDARD_TEMPLATE
         v_utils.add_template(STANDARD_TEMPLATE,
                              template_type=TTypes.STANDARD)
         db_row = v_utils.get_first_template(
             name='host_high_memory_usage_scenarios',
             type=TTypes.STANDARD,
             status=TemplateStatus.ACTIVE)
         payload_from_db = self.client.template.show(db_row['uuid'])
         payload_from_file = file.load_yaml_file(template_path)
         self.assertEqual(payload_from_file, payload_from_db,
                          "Template content doesn't match")
         v_utils.delete_template(db_row['uuid'])
     except Exception as e:
         self._handle_exception(e)
         raise
 def setUpClass(cls):
     super(TestLongProcessing, cls).setUpClass()
     if v_utils.get_first_template(name=TEMPLATE_NAME):
         v_utils.delete_template(name=TEMPLATE_NAME)
         time.sleep(SLEEP)
Exemplo n.º 12
0
 def _rollback_to_default(templates):
     for t in templates:
         db_row = vitrage_utils.get_first_template(name=t)
         vitrage_utils.delete_template(db_row['uuid'])
 def tearDown(self):
     super(TestLongProcessing, self).tearDown()
     if v_utils.get_first_template(name=TEMPLATE_NAME):
         v_utils.delete_template(name=TEMPLATE_NAME)
         time.sleep(SLEEP)