def setUp(self): super(TestConsistencyFunctional, self).setUp() self.conf_reregister_opts(self.CONSISTENCY_OPTS, 'consistency') self.conf_reregister_opts(self.EVALUATOR_OPTS, 'evaluator') self.add_db() self.load_datasources() self.graph = NXGraph("Entity Graph") self.processor = Processor(self.graph) self.event_queue = queue.Queue() def actions_callback(event_type, data): """Mock notify method Mocks vitrage.messaging.VitrageNotifier.notify(event_type, data) :param event_type: is currently always the same and is ignored :param data: """ self.event_queue.put(data) scenario_repo = ScenarioRepository() self.evaluator = ScenarioEvaluator(self.processor.entity_graph, scenario_repo, actions_callback) self.consistency_enforcer = ConsistencyEnforcer( self.processor.entity_graph, actions_callback)
def setUpClass(cls): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') cls.conf.register_opts(cls.EVALUATOR_OPTS, group='evaluator') cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') TestScenarioEvaluator.load_datasources(cls.conf) cls.scenario_repository = ScenarioRepository(cls.conf)
def setUpClass(cls): super(RegExTemplateTest, cls).setUpClass() cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group='evaluator') cls.add_db(cls.conf) cls.add_templates(cls.conf.evaluator.templates_dir) cls.scenario_repository = ScenarioRepository(cls.conf)
def setUpClass(cls): super(TestConsistencyFunctional, cls).setUpClass() cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.CONSISTENCY_OPTS, group='consistency') cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') cls.conf.register_opts(cls.EVALUATOR_OPTS, group='evaluator') cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') cls.add_db(cls.conf) cls.load_datasources(cls.conf) cls.graph = NXGraph("Entity Graph") cls.processor = Processor(cls.conf, cls.graph) cls.event_queue = queue.Queue() def actions_callback(event_type, data): """Mock notify method Mocks vitrage.messaging.VitrageNotifier.notify(event_type, data) :param event_type: is currently always the same and is ignored :param data: """ cls.event_queue.put(data) scenario_repo = ScenarioRepository(cls.conf) cls.evaluator = ScenarioEvaluator(cls.conf, cls.processor.entity_graph, scenario_repo, actions_callback) cls.consistency_enforcer = ConsistencyEnforcer( cls.conf, cls.processor.entity_graph, actions_callback)
def setUp(self): super(ScenarioRepositoryTest, self).setUp() self.add_db() templates_dir = utils.get_resources_dir() + '/templates/general' self.add_templates(templates_dir) templates_dir_path = templates_dir self.template_defs = file_utils.load_yaml_files(templates_dir_path) self.scenario_repository = ScenarioRepository()
def setUpClass(cls): cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group='evaluator') templates_dir_path = cls.conf.evaluator.templates_dir cls.template_defs = file_utils.load_yaml_files(templates_dir_path) cls.scenario_repository = ScenarioRepository(cls.conf)
def test_template_loader(self): # Test Action scenario_repository = ScenarioRepository(self.conf) # Test assertions self.assertIsNotNone(scenario_repository) path, dirs, files = next(os.walk(self.conf.evaluator.templates_dir)) self.assertEqual(len(files), len(scenario_repository.templates))
def _init_instance(self): scenario_repo = ScenarioRepository(self.worker_id, self._workers_num) actions_callback = messaging.VitrageNotifier( publisher_id='vitrage_evaluator', topics=[EVALUATOR_TOPIC]).notify self._evaluator = ScenarioEvaluator(self._entity_graph, scenario_repo, actions_callback, enabled=False) self._evaluator.scenario_repo.log_enabled_scenarios()
def _enable_evaluator_templates(self, template_names): scenario_repo = ScenarioRepository(self._conf) for s in scenario_repo._all_scenarios: s.enabled = False for template_name in template_names: if s.id.startswith(template_name): s.enabled = True self._evaluator.scenario_repo = scenario_repo self._evaluator.scenario_repo.log_enabled_scenarios() self._evaluator.enabled = True
def init(): conf = service.prepare_service() event_queue = multiprocessing.Queue() e_graph = entity_graph.EntityGraph( 'Entity Graph', '%s:%s' % (EntityCategory.RESOURCE, OPENSTACK_CLUSTER)) scenario_repo = ScenarioRepository(conf) evaluator = ScenarioEvaluator(conf, e_graph, scenario_repo, event_queue) initialization_status = InitializationStatus() return conf, event_queue, evaluator, e_graph, initialization_status
def init(conf): mp_queue = multiprocessing.Queue() evaluator_q = queue.Queue() e_graph = entity_graph.EntityGraph( 'Entity Graph', '%s:%s' % (EntityCategory.RESOURCE, OPENSTACK_CLUSTER)) scenario_repo = ScenarioRepository(conf) evaluator = ScenarioEvaluator(conf, e_graph, scenario_repo, evaluator_q) return mp_queue, evaluator_q, evaluator, e_graph
def setUpClass(cls): super(EquivalentScenarioTest, cls).setUpClass() cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group='evaluator') cls.add_db(cls.conf) cls.add_templates(cls.conf.evaluator.templates_dir) cls.add_templates(cls.conf.evaluator.equivalences_dir, TType.EQUIVALENCE) cls.add_templates(cls.conf.evaluator.def_templates_dir, TType.DEFINITION) cls.scenario_repository = ScenarioRepository(cls.conf)
def test_template_loader(self): # Test Action scenario_repository = ScenarioRepository(self.conf) # Test assertions self.assertIsNotNone(scenario_repository) self.assertThat( scenario_repository.templates, matchers.HasLength(2), 'scenario_repository.templates ' 'should contain all valid templates')
def setUp(self): super(EquivalentScenarioTest, self).setUp() templates_dir = utils.get_resources_dir() + \ '/templates/equivalent_scenarios/' equivalences_dir = templates_dir + '/equivalences' def_templates_dir = utils.get_resources_dir() + \ '/templates/def_template_tests' self.add_db() self.add_templates(templates_dir) self.add_templates(equivalences_dir, TType.EQUIVALENCE) self.add_templates(def_templates_dir, TType.DEFINITION) self.scenario_repository = ScenarioRepository()
def _template_action(self, template_names, action_mode): # Here, we create a temporary ScenarioRepo to execute the needed # templates. Once _reload_templates is called, it will create a # non temporary ScenarioRepo, to replace this one scenario_repo = ScenarioRepository(self._conf) for s in scenario_repo._all_scenarios: s.enabled = False for template_name in template_names: if s.id.startswith(template_name): s.enabled = True self._evaluator.scenario_repo = scenario_repo self._evaluator.scenario_repo.log_enabled_scenarios() self._evaluator.run_evaluator(action_mode)
def _add_worker(self, enabled=False): """Create an EvaluatorWorker and it's task queue The new worker is initialized with a scenario repository that only contains a portion of the templates """ scenario_repo = ScenarioRepository(self._conf, len(self._worker_queues), self._workers_num) tasks_queue = multiprocessing.JoinableQueue() w = EvaluatorWorker(self._conf, tasks_queue, self._entity_graph, scenario_repo, enabled) self._p_launcher.launch_service(w) self._worker_queues.append(tasks_queue)
def setUpClass(cls): super(TestConsistencyFunctional, cls).setUpClass() cls.initialization_status = InitializationStatus() cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.CONSISTENCY_OPTS, group='consistency') cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph') cls.conf.register_opts(cls.EVALUATOR_OPTS, group='evaluator') cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources') cls.load_datasources(cls.conf) cls.processor = Processor(cls.conf, cls.initialization_status) cls.event_queue = queue.Queue() scenario_repo = ScenarioRepository(cls.conf) cls.evaluator = ScenarioEvaluator(cls.conf, cls.processor.entity_graph, scenario_repo, cls.event_queue) cls.consistency_enforcer = ConsistencyEnforcer( cls.conf, cls.event_queue, cls.evaluator, cls.processor.entity_graph, cls.initialization_status)
def main(): """Starts all the Entity graph services 1. Starts the Entity graph service 2. Starts the api_handler service 3. Starts the Consistency service """ print(VITRAGE_TITLE) conf = service.prepare_service() e_graph = entity_graph.get_graph_driver(conf)('Entity Graph') launcher = os_service.ServiceLauncher(conf) full_scenario_repo = ScenarioRepository(conf) clear_db(conf) launcher.launch_service(VitrageGraphService(conf, e_graph)) launcher.launch_service( VitrageApiHandlerService(conf, e_graph, full_scenario_repo)) launcher.launch_service(VitrageConsistencyService(conf, e_graph)) launcher.wait()
def setUp(self): super(RegExTemplateTest, self).setUp() templates_dir = utils.get_resources_dir() + '/templates/regex' self.add_db() self.add_templates(templates_dir) self.scenario_repository = ScenarioRepository()
def _reload_templates(self): LOG.info("reloading evaluator scenarios") scenario_repo = ScenarioRepository(self._conf, self.worker_id, self._workers_num) self._evaluator.scenario_repo = scenario_repo self._evaluator.scenario_repo.log_enabled_scenarios()