def test_not_operator(self):
        basic_correct_not_condition_path = \
            '%s/templates/not_operator/basic_correct_not_condition.yaml' % \
            utils.get_resources_dir()
        basic_correct_not_condition_template = \
            file_utils.load_yaml_file(basic_correct_not_condition_path)
        self._execute_and_assert_with_correct_result(
            basic_correct_not_condition_template)

        basic_incorrect_not_condition_path = \
            '%s/templates/not_operator/basic_incorrect_not_condition.yaml' % \
            utils.get_resources_dir()
        basic_incorrect_not_condition_template = \
            file_utils.load_yaml_file(basic_incorrect_not_condition_path)
        self._execute_and_assert_with_fault_result(
            basic_incorrect_not_condition_template, 86)

        complicated_correct_not_condition_path = \
            '%s/templates/not_operator/' \
            'complicated_correct_not_condition.yaml' % \
            utils.get_resources_dir()
        complicated_correct_not_condition_template = \
            file_utils.load_yaml_file(complicated_correct_not_condition_path)
        self._execute_and_assert_with_correct_result(
            complicated_correct_not_condition_template)

        complicated_incorrect_not_condition_path = \
            '%s/templates/not_operator/' \
            'complicated_incorrect_not_condition.yaml' % \
            utils.get_resources_dir()
        complicated_incorrect_not_condition_template = \
            file_utils.load_yaml_file(complicated_incorrect_not_condition_path)
        self._execute_and_assert_with_fault_result(
            complicated_incorrect_not_condition_template, 86)
Esempio n. 2
0
 def __init__(self, conf):
     super(SnmpSender, self).__init__(conf)
     self.hosts = load_yaml_file(self.conf.snmp.consumers, True)
     self.oid_tree = load_yaml_file(self.conf.snmp.oid_tree, True)
     self.alarm_mapping = \
         load_yaml_file(self.conf.snmp.alarm_oid_mapping, True)
     self.oids, self.var_fields = self._build_oids()
Esempio n. 3
0
 def _get_cluster_name(self):
     kubeconf = file_utils.load_yaml_file(self.conf.kubernetes.config_file)
     contexts = kubeconf['contexts']
     for context in contexts:
         if context['name'] == kubeconf['current-context']:
             cluster_name = context['context']['cluster']
     return cluster_name
 def test_basic_regex(self):
     basic_regex_path = \
         REGEX_TEMPLATE_DIR % (utils.get_resources_dir(),
                               "basic_regex.yaml")
     basic_regex_template = \
         file_utils.load_yaml_file(basic_regex_path)
     self._execute_and_assert_with_correct_result(basic_regex_template)
    def test_template_with_no_defs_only_includes(self):
        template_path = '/templates/only_using_def_template_definitions.yaml'
        template = file_utils.load_yaml_file(self.def_templates_tests_path +
                                             template_path)

        self._execute_and_assert_with_correct_result(template,
                                                     self.def_templates)
Esempio n. 6
0
    def test_def_template_with_scenario_section(self):

        def_template_path = self.def_template_dir_path + \
            '/definition_templates/with_scenarios.yaml'
        def_template = file_utils.load_yaml_file(def_template_path)
        self._test_execution_with_fault_result_for_def_template(
            def_template, 143)
    def test_template_with_include(self):

        template_path = '/templates/basic_with_include.yaml'
        template = file_utils.load_yaml_file(self.def_templates_tests_path +
                                             template_path)
        self._execute_and_assert_with_correct_result(template,
                                                     self.def_templates)
 def test_faulty_regex(self):
     faulty_regex_path = \
         REGEX_TEMPLATE_DIR % (utils.get_resources_dir(),
                               "faulty_regex.yaml")
     faulty_regex_template = \
         file_utils.load_yaml_file(faulty_regex_path)
     self._execute_and_assert_with_fault_result(faulty_regex_template, 47)
Esempio n. 9
0
 def __init__(self, worker_id, conf):
     super(SnmpParsingService, self).__init__(worker_id, conf)
     self.conf = conf
     self.listening_port = conf.snmp_parsing.snmp_listening_port
     self.oid_mapping = \
         load_yaml_file(self.conf.snmp_parsing.oid_mapping)
     self._init_oslo_notifier()
    def test_template_with_conflicting_include_entities(self):
        template_path = '/templates/with_conflicting_include_entities.yaml'
        template = file_utils.load_yaml_file(self.def_templates_tests_path +
                                             template_path)

        self._execute_and_assert_with_fault_result(template, 2,
                                                   self.def_templates)
 def _execute_condition_template_with_fault_result(self, template_name,
                                                   status_code):
     template_path = CONDITION_TEMPLATES_DIR % (utils.get_resources_dir(),
                                                template_name)
     template_definition = file_utils.load_yaml_file(template_path, True)
     self._execute_and_assert_with_fault_result(template_definition,
                                                status_code)
Esempio n. 12
0
 def __init__(self):
     try:
         tmfapi639_config_file = CONF.tmfapi639[DSOpts.CONFIG_FILE]
         tmfapi639_config = file_utils.load_yaml_file(tmfapi639_config_file)
         self.endpoints = self._create_mapping(tmfapi639_config)
     except Exception as e:
         LOG.error("Failed initialization: " + str(e))
         self.endpoints = []
 def _load_template_file(file_name):
     try:
         config = file_utils.load_yaml_file(file_name,
                                            with_exception=True)
         if config:
             return config
     except Exception as e:
         return {TemplateFields.METADATA: {TemplateFields.NAME: file_name},
                 EXCEPTION: str(e)}
Esempio n. 14
0
 def _configuration_mapping():
     prometheus_config_file = CONF.prometheus[DSOpts.CONFIG_FILE]
     try:
         prometheus_config = \
             file_utils.load_yaml_file(prometheus_config_file)
         return prometheus_config[PCFProps.ALERTS]
     except Exception:
         LOG.exception('Failed in init the configuration file: %s',
                       prometheus_config_file)
         return {}
Esempio n. 15
0
    def __init__(self, conf):
        try:
            nagios_config_file = conf.nagios[DSOpts.CONFIG_FILE]
            nagios_config = file_utils.load_yaml_file(nagios_config_file)
            nagios = nagios_config[NAGIOS]  # nagios root in the yaml file

            self.mappings = [self._create_mapping(config) for config in nagios]
        except Exception as e:
            LOG.exception('failed in init %s ', e)
            self.mappings = []
Esempio n. 16
0
    def __init__(self, conf):
        try:
            nagios_config_file = conf.nagios['config_file']
            nagios_config = file_utils.load_yaml_file(nagios_config_file)
            nagios = nagios_config[NAGIOS]      # nagios root in the yaml file

            self.mappings = [self._create_mapping(config) for config in nagios]
        except Exception as e:
            LOG.exception('failed in init %s ', e)
            self.mappings = []
Esempio n. 17
0
    def _get_entities_from_file(self, file_, path):
        static_entities = []
        config = file_utils.load_yaml_file(path)

        for entity in config[self.ENTITIES_SECTION]:
            static_entities.append(entity.copy())

        self.cache[file_] = config

        return static_entities
Esempio n. 18
0
    def __init__(self):
        try:
            kapacitor_config_file = CONF.kapacitor[DSOpts.CONFIG_FILE]
            kapacitor_config = file_utils.load_yaml_file(kapacitor_config_file)
            kapacitor = kapacitor_config[KAPACITOR]

            self.mappings = [self._create_mapping(config)
                             for config in kapacitor]
        except Exception:
            LOG.exception('Failed in init.')
            self.mappings = []
Esempio n. 19
0
    def test_standard_template(self):
        template_path = '%s/templates/version/v2/%s' % \
                        (utils.get_resources_dir(), self.STANDARD_TEMPLATE)
        template_definition = file_utils.load_yaml_file(template_path, True)

        template_data = get_template_data(template_definition)
        self.assertIsNotNone(template_data)

        template_type = template_data.template_type
        self.assertIsNotNone(template_type, 'v2 template must include a type')
        self.assertEqual(TemplateTypes.STANDARD, template_type,
                         'template_type should be ' + TemplateTypes.STANDARD)
Esempio n. 20
0
    def _get_entities_from_file(cls, path):
        config = file_utils.load_yaml_file(path)

        if not cls._is_valid_config(config, path):
            return []

        definitions = config[StaticFields.DEFINITIONS]

        entities = definitions[StaticFields.ENTITIES]
        relationships = definitions[StaticFields.RELATIONSHIPS]

        return cls._pack(entities, relationships)
Esempio n. 21
0
    def _get_entities_from_file(cls, path):
        config = file_utils.load_yaml_file(path)

        if not cls.is_valid_config(config):
            LOG.warning("Skipped invalid config (possible obsoleted): {}".format(path))
            return []

        definitions = config[TopologyFields.DEFINITIONS]

        entities = definitions[TopologyFields.ENTITIES]
        relationships = definitions[TopologyFields.RELATIONSHIPS]

        return cls._pack(entities, relationships)
Esempio n. 22
0
    def _get_entities_from_file(cls, path):
        config = file_utils.load_yaml_file(path)

        if not cls._is_valid_config(config):
            LOG.warning("Skipped invalid config (possible obsoleted): {}"
                        .format(path))
            return []

        definitions = config[StaticFields.DEFINITIONS]

        entities = definitions[StaticFields.ENTITIES]
        relationships = definitions[StaticFields.RELATIONSHIPS]

        return cls._pack(entities, relationships)
Esempio n. 23
0
 def _get_template_single_action(self, template_file):
     template_path = '%s/templates/version/%s' % (utils.get_resources_dir(),
                                                  template_file)
     template_definition = file_utils.load_yaml_file(template_path, True)
     template_data = TemplateLoader().load(template_definition)
     scenarios = template_data.scenarios
     self.assertIsNotNone(scenarios, 'Template should include a scenario')
     self.assertThat(scenarios, matchers.HasLength(1),
                     'Template should include a single scenario')
     actions = scenarios[0].actions
     self.assertIsNotNone(actions, 'Scenario should include an action')
     self.assertThat(actions, matchers.HasLength(1),
                     'Scenario should include a single action')
     return actions[0]
Esempio n. 24
0
    def _get_changes_entities(self):

        entities_updates = []
        files = file_utils.list_files(
            self.cfg.static_physical.directory, '.yaml')

        for file_ in files:
            full_path = self.cfg.static_physical.directory +\
                '/' + file_
            config = file_utils.load_yaml_file(full_path)

            if StaticDriver.is_valid_config(config):
                LOG.warning("Skipped config of new static datasource: {}"
                            .format(file_))
                return []

            if config:
                if file_ in self.cache:
                    if str(config) != str(self.cache[file_]):
                        # TODO(alexey_weyl): need also to remove deleted
                        #                   files from cache
                        old_config = copy.deepcopy(config)

                        self._update_on_existing_entities(
                            self.cache[file_][self.ENTITIES_SECTION],
                            config[self.ENTITIES_SECTION],
                            entities_updates)

                        self._update_on_new_entities(
                            config[self.ENTITIES_SECTION],
                            self.cache[file_][self.ENTITIES_SECTION],
                            entities_updates)

                        self.cache[file_] = old_config
                else:
                    self.cache[file_] = config
                    entities_updates += \
                        self._get_entities_from_file(file_, full_path)

        # iterate over deleted files
        deleted_files = set(self.cache.keys()) - set(files)
        for file_ in deleted_files:
            self._update_on_existing_entities(
                self.cache[file_][self.ENTITIES_SECTION],
                {},
                entities_updates)
            del self.cache[file_]

        return entities_updates
Esempio n. 25
0
    def _get_changes_entities(self):

        entities_updates = []
        files = file_utils.list_files(
            self.cfg.static_physical.directory, '.yaml')

        for file_ in files:
            full_path = self.cfg.static_physical.directory +\
                '/' + file_
            config = file_utils.load_yaml_file(full_path)

            if StaticDriver._is_valid_config(config):
                LOG.warning("Skipped config of new static datasource: {}"
                            .format(file_))
                return []

            if config:
                if file_ in self.cache:
                    if str(config) != str(self.cache[file_]):
                        # TODO(alexey_weyl): need also to remove deleted
                        #                   files from cache
                        old_config = copy.deepcopy(config)

                        self._update_on_existing_entities(
                            self.cache[file_][self.ENTITIES_SECTION],
                            config[self.ENTITIES_SECTION],
                            entities_updates)

                        self._update_on_new_entities(
                            config[self.ENTITIES_SECTION],
                            self.cache[file_][self.ENTITIES_SECTION],
                            entities_updates)

                        self.cache[file_] = old_config
                else:
                    self.cache[file_] = config
                    entities_updates += \
                        self._get_entities_from_file(file_, full_path)

        # iterate over deleted files
        deleted_files = set(self.cache.keys()) - set(files)
        for file_ in deleted_files:
            self._update_on_existing_entities(
                self.cache[file_][self.ENTITIES_SECTION],
                {},
                entities_updates)
            del self.cache[file_]

        return entities_updates
Esempio n. 26
0
    def _get_entities_from_file(self, file_, path):
        static_entities = []
        config = file_utils.load_yaml_file(path)

        if StaticDriver.is_valid_config(config):
            LOG.warning("Skipped config of new static datasource: {}"
                        .format(file_))
            return []

        for entity in config[self.ENTITIES_SECTION]:
            static_entities.append(entity.copy())

        self.cache[file_] = config

        return static_entities
Esempio n. 27
0
    def _get_entities_from_file(self, file_, path):
        static_entities = []
        config = file_utils.load_yaml_file(path)

        if StaticDriver._is_valid_config(config):
            LOG.warning("Skipped config of new static datasource: {}"
                        .format(file_))
            return []

        for entity in config[self.ENTITIES_SECTION]:
            static_entities.append(entity.copy())

        self.cache[file_] = config

        return static_entities
Esempio n. 28
0
    def _get_event_type(self, snmp_trap):
        yaml_file_content = load_yaml_file(self.conf.snmp_parsing.oid_mapping)
        if not yaml_file_content:
            LOG.warning('No snmp trap is configured!')
            return None

        for mapping_info in yaml_file_content:
            system_oid = extract_field_value(mapping_info, SEProps.SYSTEM_OID)
            conf_system = extract_field_value(mapping_info, SEProps.SYSTEM)
            if conf_system == extract_field_value(snmp_trap, system_oid):
                LOG.debug('snmp trap mapped the system: %s.' % conf_system)
                return extract_field_value(mapping_info, SEProps.EVENT_TYPE)

        LOG.error("Snmp trap does not contain system info!")
        return None
Esempio n. 29
0
    def _check_get_condition_common_targets(self, template_name,
                                            valid_targets):
        template_path = CONDITION_TEMPLATES_DIR % (utils.get_resources_dir(),
                                                   template_name)
        template_definition = file_utils.load_yaml_file(template_path, True)

        template_data = TemplateLoader().load(template_definition)
        definitions_index = template_data.entities.copy()
        definitions_index.update(template_data.relationships)

        common_targets = get_condition_common_targets(
            template_data.scenarios[0].condition, definitions_index,
            self.ConditionSymbolResolver())

        self.assertIsNotNone(common_targets)
        self.assertTrue(common_targets == set(valid_targets))
Esempio n. 30
0
    def _configuration_mapping(conf):
        try:
            zabbix_config_file = conf.zabbix[DSOpts.CONFIG_FILE]
            zabbix_config = file_utils.load_yaml_file(zabbix_config_file)
            zabbix_config_elements = zabbix_config[ZABBIX_DATASOURCE]

            mappings = {}
            for element_config in zabbix_config_elements:
                mappings[element_config['zabbix_host']] = {
                    ZProps.RESOURCE_TYPE: element_config['type'],
                    ZProps.RESOURCE_NAME: element_config['name']
                }

            return mappings
        except Exception:
            LOG.exception('Failed in init.')
            return {}
Esempio n. 31
0
    def _configuration_mapping(conf):
        try:
            collectd_config_file = conf.collectd[DSOpts.CONFIG_FILE]
            collectd_config = file_utils.load_yaml_file(collectd_config_file)
            collectd_config_elements = collectd_config[COLLECTD_DATASOURCE]

            mappings = {}
            for element_config in collectd_config_elements:
                mappings[element_config['collectd_host']] = {
                    CProps.RESOURCE_TYPE: element_config['type'],
                    CProps.RESOURCE_NAME: element_config['name']
                }

            return mappings
        except Exception as e:
            LOG.exception('failed in init %s ', e)
            return {}
Esempio n. 32
0
    def _configuration_mapping(conf):
        try:
            kapacitor_config_file = conf.kapacitor[DSOpts.CONFIG_FILE]
            kapacitor_config = file_utils.load_yaml_file(kapacitor_config_file)
            kapacitor_config_elements = kapacitor_config[KAPACITOR_DATASOURCE]

            mappings = {}
            for element_config in kapacitor_config_elements:
                mappings[element_config['kapacitor_host']] = {
                    KProps.RESOURCE_TYPE: element_config['type'],
                    KProps.RESOURCE_NAME: element_config['name']
                }

            return mappings
        except Exception as e:
            LOG.exception('failed in init %s ', e)
            return {}
Esempio n. 33
0
    def _configuration_mapping(conf):
        try:
            zabbix_config_file = conf.zabbix['config_file']
            zabbix_config = file_utils.load_yaml_file(zabbix_config_file)
            zabbix_config_elements = zabbix_config['zabbix']

            mappings = {}
            for element_config in zabbix_config_elements:
                mappings[element_config['zabbix_host']] = {
                    ZProps.RESOURCE_TYPE: element_config['type'],
                    ZProps.RESOURCE_NAME: element_config['name']
                }

            return mappings
        except Exception as e:
            LOG.exception('failed in init %s ', e)
            return {}
Esempio n. 34
0
    def test_basic_template(self):

        # Test setup
        template_path = "%s/templates/general/%s" % (utils.get_resources_dir(), self.BASIC_TEMPLATE)
        template_definition = file_utils.load_yaml_file(template_path, True)

        template_data = TemplateData(template_definition)
        entities = template_data.entities
        relationships = template_data.relationships
        scenarios = template_data.scenarios
        definitions = template_definition[TFields.DEFINITIONS]

        # Assertions
        entities_definition = definitions[TFields.ENTITIES]
        self._validate_entities(entities, entities_definition)

        relate_def = definitions[TFields.RELATIONSHIPS]
        self._validate_relationships(relationships, relate_def, entities)
        self._validate_scenarios(scenarios, entities)
 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
Esempio n. 36
0
    def test_equivalence_template(self):

        equivalence_path = '%s/templates/general/equivalences/%s' % (
            utils.get_resources_dir(), self.BASIC_TEMPLATE)
        equivalence_definition = file_utils.load_yaml_file(
            equivalence_path, True)
        equivalence_data = EquivalenceData(equivalence_definition)
        equivalences = equivalence_data.equivalences

        expected = [
            frozenset([
                frozenset([('category', 'ALARM'), ('type', 'nagios'),
                           ('name', 'host_problem')]),
                frozenset([('category', 'ALARM'), ('type', 'zabbix'),
                           ('name', 'host_fail')]),
                frozenset([('category', 'ALARM'), ('type', 'vitrage'),
                           ('name', 'host_down')])
            ]),
        ]

        self.assertEqual(expected, equivalences)
Esempio n. 37
0
    def _retrieve_states_and_priorities_from_file(self, full_path):
        states = {}
        priorities = {}
        config = file_utils.load_yaml_file(full_path, with_exception=True)
        category = config['category']

        for item in config['values']:
            aggregated_values = item['aggregated values']
            priority_value = int(aggregated_values['priority'])

            # original to operational value
            for original_state in aggregated_values['original values']:
                original_value = original_state['name']
                operational_value = original_state['operational_value']
                states[original_value.upper()] = operational_value
                priorities[original_value.upper()] = priority_value

        self._check_validity(category, states, priorities, full_path)

        self._add_default_states(states, priorities, category)

        return states, priorities
    def _retrieve_values_and_priorities_from_file(self, full_path):
        values = {}
        priorities = {}
        config = file_utils.load_yaml_file(full_path, with_exception=True)
        vitrage_category = config['category']

        for item in config['values']:
            aggregated_values = item['aggregated values']
            priority_value = int(aggregated_values['priority'])

            # original to operational value
            for value_map in aggregated_values['original values']:
                name = value_map['name']
                operational_value = value_map['operational_value']
                values[name.upper()] = operational_value
                priorities[name.upper()] = priority_value

        self._check_validity(vitrage_category, values, priorities, full_path)

        self._add_default_values(values, priorities, vitrage_category)

        return values, priorities