Exemplo n.º 1
0
    def _test_heat_stack(self, nested, tmpl_file):
        """heat stack test

        This test validate correctness topology graph with heat stack module
        """
        template_file = tempest_resources_dir() + '/heat/' + tmpl_file
        image = glance_utils.get_first_image()
        # Action
        heat_utils.create_stacks(self.NUM_STACKS, nested, template_file,
                                 image['name'])

        # 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_STACKS,
            instance_entities=self.NUM_STACKS,
            instance_edges=3 * self.NUM_STACKS,
            network_entities=self.num_default_networks,
            network_edges=self.num_default_ports + self.NUM_STACKS,
            port_entities=self.num_default_ports + self.NUM_STACKS,
            port_edges=self.num_default_ports + 2 * self.NUM_STACKS,
            stack_entities=self.NUM_STACKS,
            stack_edges=self.NUM_STACKS)
        num_entities = self.num_default_entities + 3 * self.NUM_STACKS + \
            self.num_default_networks + self.num_default_ports
        num_edges = self.num_default_edges + 4 * self.NUM_STACKS + \
            self.num_default_ports

        # Test Assertions
        self._validate_graph_correctness(graph, num_entities, num_edges,
                                         entities)
def add_template(filename='',
                 folder='templates/api',
                 template_type=TemplateTypes.STANDARD,
                 status=TemplateStatus.ACTIVE):
    full_path = g_utils.tempest_resources_dir() + '/' + folder + '/' + filename
    t = TempestClients.vitrage().template.add(full_path, template_type)
    if t and t[0]:
        wait_for_status(
            100,
            get_first_template,
            uuid=t[0]['uuid'], status=status)
        return t[0]
    return None
Exemplo n.º 3
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'])
Exemplo n.º 4
0
    def _create_switches():
        hostname = socket.gethostname()

        # template file
        file_path = \
            tempest_resources_dir() + '/static/static_configuration.yaml'
        with open(file_path, 'r') as f:
            template_data = f.read()
        template_data = template_data.replace('tmp-devstack', hostname)

        # new file
        new_file = open(
            '/etc/vitrage/static_datasources/static_configuration.yaml', 'w')
        new_file.write(template_data)
        new_file.close()

        time.sleep(35)
 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
Exemplo n.º 6
0
class BaseTemplateTest(BaseVitrageTempest):
    """Template test class for Vitrage API tests."""

    TEST_PATH = tempest_resources_dir() + '/templates/api/'

    NON_EXIST_FILE = 'non_exist_file.yaml'
    ERROR_FILE = 'corrupted_template.yaml'
    OK_FILE = 'nagios_alarm_for_alarms.yaml'

    VALIDATION_FAILED = 'validation failed'
    VALIDATION_OK = 'validation OK'
    OK_MSG = 'Template validation is OK'

    def tearDown(self):
        super(BaseTemplateTest, self).tearDown()
        self._delete_templates()

    def _delete_templates(self):
        templates = self.vitrage_client.template.list()
        template_ids = [template['uuid'] for template in templates]
        self.vitrage_client.template.delete(template_ids)

    def _compare_template_lists(self, api_templates, cli_templates):
        self.assertThat(api_templates, IsNotEmpty(),
                        'The template list taken from api is empty')
        self.assertIsNotNone(cli_templates,
                             'The template list taken from cli is empty')

        LOG.debug("The template list taken from cli is : %s", cli_templates)
        LOG.debug("The template list taken by api is : %s", api_templates)

        self._validate_templates_list_length(api_templates, cli_templates)
        self._validate_passed_templates_length(api_templates, cli_templates)
        self._compare_each_template_in_list(api_templates, cli_templates)

    def _validate_templates_list_length(self, api_templates, cli_templates):
        self.assertEqual(len(cli_templates.splitlines()),
                         len(api_templates) + 4)

    def _validate_passed_templates_length(self, api_templates, cli_templates):
        api_passes_templates = g_utils.all_matches(
            api_templates, **{'status details': self.OK_MSG})
        cli_passes_templates = cli_templates.count(' ' + self.OK_MSG + ' ')
        self.assertThat(api_passes_templates,
                        matchers.HasLength(cli_passes_templates))

    def _compare_each_template_in_list(self, api_templates, cli_templates):
        counter = 0
        for api_item in api_templates:
            for line in cli_templates.splitlines():
                name_start = line.count(' ' + api_item['name'] + ' ')
                status_start = line.count(' ' + api_item['status'] + ' ')
                if name_start > 0 and status_start > 0:
                    counter += 1
                    break
        self.assertThat(api_templates, matchers.HasLength(counter))

    def _assert_validate_result(self,
                                validation,
                                path,
                                negative=False,
                                status_code=0):
        self.assertThat(validation['results'], matchers.HasLength(1))
        result = validation['results'][0]
        self.assertIn(path, result['file path'])

        if negative:
            self.assertEqual(self.VALIDATION_FAILED, result['status'])
            self.assertNotEqual(result['message'], self.OK_MSG)
            self.assertEqual(status_code, result['status code'])
            return

        self.assertEqual(self.VALIDATION_OK, result['status'])
        self.assertEqual(self.OK_MSG, result['message'])
        self.assertEqual(0, result['status code'])

    def _assert_add_result(self, result, status, message):
        self.assertThat(result, matchers.HasLength(1))
        self.assertEqual(status, result[0]['status'])
        self.assertThat(result[0]['status details'],
                        matchers.StartsWith(message))

    @staticmethod
    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'])