def test_construct_conf_manager(self): """Test for building a conf manager""" conf = parsing.construct_conf_manager([DICT_NS_TEST]) self.assertIsInstance(conf, cfg.ConfigOpts) keys = conf.keys() self.assertEqual(1, len(keys)) self.assertIn(u'oslo_concurrency', keys)
def test_construct_conf_manager(self): """Test for building a conf manager""" initial_keys_len = len(cfg.ConfigOpts().keys()) conf = parsing.construct_conf_manager([DICT_NS_TEST]) self.assertIsInstance(conf, cfg.ConfigOpts) keys = conf.keys() self.assertEqual(initial_keys_len + 1, len(keys)) self.assertIn(u'oslo_concurrency', keys)
def process_config(self, file_hash, config, host): """Manages all translations related to a config file. Publish tables to PE. :param file_hash: Hash of the configuration file :param config: object representing the configuration :param host: Remote host name :return: True if config was processed """ try: LOG.debug("process_config hash=%s" % file_hash) template_hash = config['template'] template = self.known_templates.get(template_hash, None) if template is None: waiting = ( self.templates_awaited_by_config.get(template_hash, [])) waiting.append((file_hash, config)) self.templates_awaited_by_config[template_hash] = waiting LOG.debug('Template %s not yet registered' % template_hash) return False host_id = utils.compute_hash(host) namespaces = [self.known_namespaces.get(h, None).get('data', None) for h in template['namespaces']] conf = parsing.construct_conf_manager(namespaces) parsing.add_parsed_conf(conf, config['data']) for tablename in set(self.get_schema()) - set(self.state): self.state[tablename] = set() self.publish(tablename, self.state[tablename], use_snapshot=False) self.translate_conf(conf, file_hash) self.translate_host(host_id, host) self.translate_service( host_id, config['service'], config['version']) file_name = os.path.basename(config['path']) self.translate_file(file_hash, host_id, template_hash, file_name) ns_hashes = {h: self.known_namespaces[h]['name'] for h in template['namespaces']} self.translate_template_namespace(template_hash, template['name'], ns_hashes) for tablename in self.state: self.publish(tablename, self.state[tablename], use_snapshot=True) return True except KeyError: LOG.error('Config %s from %s NOT registered' % (file_hash, host)) return False
def process_config(self, file_hash, config, host): """Manages all translations related to a config file. Publish tables to PE. :param file_hash: Hash of the configuration file :param config: object representing the configuration :param host: Remote host name """ template_hash = config['template'] template = self.known_templates.get(template_hash, None) if template is None: waiting = self.templates_awaited_by_config.get(template_hash, []) waiting.append((file_hash, config)) self.templates_awaited_by_config[template_hash] = waiting LOG.info('Template %s not yet registered' % template_hash) return host_id = utils.compute_hash(host) namespaces = [ self.known_namespaces.get(h, None).get('data', None) for h in template['namespaces'] ] conf = parsing.construct_conf_manager(namespaces) parsing.add_parsed_conf(conf, config['data']) for tablename in set(self.get_schema()) - set(self.state): self.state[tablename] = set() self.publish(tablename, self.state[tablename], use_snapshot=False) self.translate_conf(conf, file_hash) self.translate_host(host_id, host) self.translate_service(host_id, config['service'], config['version']) file_name = os.path.basename(config['path']) self.translate_file(file_hash, host_id, template_hash, file_name) ns_hashes = { h: self.known_namespaces[h]['name'] for h in template['namespaces'] } self.translate_template_namespace(template_hash, template['name'], ns_hashes) for tablename in self.state: self.publish(tablename, self.state[tablename], use_snapshot=True)