def test_scenario_1(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario1', '3', None, [ ActionSpecs( 'valid actions-scenario1-action0', 'add_causal_relationship', { 'target': 'host_ssh_alarm', 'source': 'host_network_alarm', }, {}), ], [ NXGraph( vertices=[ Vertex('host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex('host_network_alarm', { 'rawtext': 'host network interface is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex('host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }) ], edges=[ Edge('host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }), Edge('host_network_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]) ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal( expected_scenario, observed_scenarios[1])
def test_scenario_5(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario5', '3', None, [ ActionSpecs( 'valid actions-scenario5-action0', 'mark_down', {'target': 'host'}, {}), ], [ NXGraph( vertices=[ Vertex('host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex('instance', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.instance', 'vitrage_is_deleted': False, }), Vertex('host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ], edges=[ Edge('host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': True, 'negative_condition': True }), Edge('host', 'instance', 'contains', { 'vitrage_is_deleted': True, 'negative_condition': True }) ] ), ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal( expected_scenario, observed_scenarios[5])
def test_scenario_2(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario2', '3', None, [ ActionSpecs( 'valid actions-scenario2-action0', 'raise_alarm', {'target': 'instance'}, { 'severity': 'WARNING', 'alarm_name': 'instance is down', 'causing_alarm': 'get_attr(host_ssh_alarm, vitrage_id)', }), ActionSpecs('valid actions-scenario2-action1', 'set_state', {'target': 'instance'}, {'state': 'SUBOPTIMAL'}), ], [ NXGraph(vertices=[ Vertex( 'host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'instance', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.instance', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ], edges=[ Edge( 'host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }), Edge( 'host', 'instance', 'contains', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]) ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[2])
def test_scenario_0(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario0', '3', None, [ ActionSpecs( 'valid actions-scenario0-action0', 'set_state', {'target': 'host'}, {'state': 'ERROR'}), ActionSpecs( 'valid actions-scenario0-action1', 'raise_alarm', {'target': 'host'}, {'severity': 'WARNING', 'alarm_name': 'ddd'}), ActionSpecs( 'valid actions-scenario0-action2', 'mark_down', {'target': 'host'}, {}), ActionSpecs( 'valid actions-scenario0-action3', 'execute_mistral', {'target': 'host'}, {'input': {'farewell': 'get_attr(host, name) bla bla'}, 'workflow': 'wf_1234'}), ], [ NXGraph( vertices=[ Vertex('host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex('host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }) ], edges=[ Edge('host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]) ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal( expected_scenario, observed_scenarios[0])
def relation_str(matchobj): source = matchobj.group(1) label = matchobj.group(2) target = matchobj.group(3) relation_id = '%s__%s__%s' % (source, label, target) extracted_relationships[relation_id] = EdgeDescription( Edge(source, target, label, dict()), entities[source], entities[target]) return relation_id
def _extract_relationship_info(self, relationship_dict): source_id = relationship_dict[TFields.SOURCE] target_id = relationship_dict[TFields.TARGET] edge = Edge(source_id, target_id, relationship_dict[TFields.RELATIONSHIP_TYPE], self._extract_properties(relationship_dict)) source = self.entities[source_id] target = self.entities[target_id] return EdgeDescription(edge, source, target)
def topology_to_graph(topology): graph = NXGraph() nodes = topology['nodes'] for n in nodes: graph.add_vertex(Vertex(n['vitrage_id'], n)) edges = topology['links'] for i in range(len(edges)): s_id = nodes[edges[i]['source']]['vitrage_id'] t_id = nodes[edges[i]['target']]['vitrage_id'] graph.add_edge(Edge(s_id, t_id, edges[i]['relationship_type'])) return graph
def _create_graph_from_graph_dictionary(api_graph): graph = NXGraph() nodes = api_graph['nodes'] for i in xrange(len(nodes)): graph.add_vertex(Vertex(str(i), nodes[i])) edges = api_graph['links'] for i in xrange(len(edges)): graph.add_edge( Edge(str(edges[i]['source']), str(edges[i]['target']), edges[i]['relationship_type'])) return graph
def _create_graph_from_graph_dictionary(self, api_graph): self.assertIsNotNone(api_graph) graph = NXGraph() nodes = api_graph['nodes'] for i in range(len(nodes)): graph.add_vertex(Vertex(str(i), nodes[i])) edges = api_graph['links'] for i in range(len(edges)): graph.add_edge(Edge(str(edges[i]['source']), str(edges[i]['target']), edges[i][EdgeProperties.RELATIONSHIP_TYPE])) return graph
def do_replay_events(db, graph, event_id): events = db.events.get_replay_events(event_id=event_id) for event in events: if event.is_vertex: v_id = event.payload['vertex_id'] del event.payload['vertex_id'] v = Vertex(v_id, event.payload) graph.update_vertex(v) else: source_id = event.payload['source_id'] target_id = event.payload['target_id'] label = event.payload['label'] del event.payload['source_id'] del event.payload['target_id'] del event.payload['label'] e = Edge(source_id, target_id, label, event.payload) graph.update_edge(e) return len(events)
def replay_events(self, graph, event_id): LOG.info('Getting events from database') events = self.db.events.get_replay_events(event_id=event_id) LOG.info('Applying %s database events', len(events)) for event in events: if event.is_vertex: v_id = event.payload['vertex_id'] del event.payload['vertex_id'] v = Vertex(v_id, event.payload) graph.update_vertex(v) else: source_id = event.payload['source_id'] target_id = event.payload['target_id'] label = event.payload['label'] del event.payload['source_id'] del event.payload['target_id'] del event.payload['label'] e = Edge(source_id, target_id, label, event.payload) graph.update_edge(e)
def get_rca(self, ctx, root, all_tenants): LOG.debug("RcaApis get_rca - root: %s, all_tenants=%s", root, all_tenants) project_id = ctx.get(TenantProps.TENANT, None) is_admin_project = ctx.get(TenantProps.IS_ADMIN, False) if all_tenants: db_nodes, db_edges = self.db.history_facade.alarm_rca(root) else: db_nodes, db_edges = self.db.history_facade.alarm_rca( root, project_id=project_id, admin=is_admin_project) for n in db_nodes: start_timestamp = \ self.db.history_facade.add_utc_timezone(n.start_timestamp) n.payload[HProps.START_TIMESTAMP] = str(start_timestamp) if n.end_timestamp <= db_time(): end_timestamp = \ self.db.history_facade.add_utc_timezone(n.end_timestamp) n.payload[HProps.END_TIMESTAMP] = str(end_timestamp) # TODO(annarez): implement state change in processor and DB n.payload[VProps.STATE] = AProps.INACTIVE_STATE vertices = [ Vertex(vertex_id=n.vitrage_id, properties=n.payload) for n in db_nodes ] edges = [ Edge(source_id=e.source_id, target_id=e.target_id, label=e.label, properties=e.payload) for e in db_edges ] rca_graph = NXGraph(vertices=vertices, edges=edges) json_graph = rca_graph.json_output_graph( inspected_index=self._find_rca_index(rca_graph, root)) return json_graph
def _create_graph_from_tree_dictionary(self, api_graph, graph=None, ancestor=None): children = [] graph = NXGraph() if not graph else graph if 'children' in api_graph: children = api_graph.copy()['children'] del api_graph['children'] vertex = Vertex(api_graph[VProps.VITRAGE_ID], api_graph) graph.add_vertex(vertex) if ancestor: graph.add_edge( Edge(ancestor[VProps.VITRAGE_ID], vertex[VProps.VITRAGE_ID], 'label')) for entity in children: self._create_graph_from_tree_dictionary(entity, graph, vertex) return graph
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 = TemplateLoader().load(template_definition) entities = template_data.entities relationships = template_data.relationships scenarios = template_data.scenarios definitions = template_definition[TFields.DEFINITIONS] # Assertions for definition in definitions[TFields.ENTITIES]: for key, value in definition['entity'].items(): new_key = TemplateLoader.PROPS_CONVERSION[key] if key in \ TemplateLoader.PROPS_CONVERSION else key del definition['entity'][key] definition['entity'][new_key] = value self._validate_entities(entities, definitions[TFields.ENTITIES]) relate_def = definitions[TFields.RELATIONSHIPS] self._validate_relationships(relationships, relate_def, entities) self._validate_scenarios(scenarios, entities) expected_entities = { 'alarm': Vertex(vertex_id='alarm', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: NAGIOS_DATASOURCE, VProps.NAME: 'host_problem' }), 'resource': Vertex(vertex_id='resource', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE }) } expected_relationships = { 'alarm_on_host': EdgeDescription(edge=Edge( source_id='alarm', target_id='resource', label=EdgeLabel.ON, properties={EdgeProperties.RELATIONSHIP_TYPE: EdgeLabel.ON}), source=expected_entities['alarm'], target=expected_entities['resource']) } expected_scenario = Scenario( id='basic_template-scenario0', version=1, condition=[[ ConditionVar(symbol_name='alarm_on_host', positive=True) ]], actions=[ ActionSpecs( id='basic_template-scenario0-action0', type=ActionType.SET_STATE, targets={'target': 'resource'}, properties={'state': OperationalResourceState.SUBOPTIMAL}) ], # TODO(yujunz): verify the built subgraph is consistent with # scenario definition. For now the observed value is # assigned to make test passing subgraphs=template_data.scenarios[0].subgraphs, entities=expected_entities, relationships=expected_relationships) self._validate_strict_equal(template_data, expected_entities, expected_relationships, expected_scenario)
def test_basic_template_with_include(self): # Test setup template_path = self.DEF_TEMPLATE_TESTS_DIR +\ '/templates/%s' % self.BASIC_TEMPLATE_WITH_INCLUDE template_definition = file_utils.load_yaml_file(template_path, True) def_templates_path = self.DEF_TEMPLATE_TESTS_DIR + \ '/definition_templates' def_demplates_list = file_utils.load_yaml_files(def_templates_path) def_templates_dict = utils.get_def_templates_dict_from_list( def_demplates_list) template_data = \ TemplateLoader().load(template_definition, def_templates_dict) entities = template_data.entities relationships = template_data.relationships scenarios = template_data.scenarios definitions = template_definition[TFields.DEFINITIONS] def_template = file_utils.load_yaml_file(def_templates_path + '/basic_def_template.yaml') def_template_entities = \ def_template[TFields.DEFINITIONS][TFields.ENTITIES] def_template_relationships = \ def_template[TFields.DEFINITIONS][TFields.RELATIONSHIPS] definitions[TFields.ENTITIES] += def_template_entities definitions[TFields.RELATIONSHIPS] = def_template_relationships # Assertions for definition in definitions[TFields.ENTITIES]: for key, value in definition['entity'].items(): new_key = TemplateLoader.PROPS_CONVERSION[key] if key in \ TemplateLoader.PROPS_CONVERSION else key del definition['entity'][key] definition['entity'][new_key] = value self._validate_entities(entities, definitions[TFields.ENTITIES]) relate_def = def_template_relationships self._validate_relationships(relationships, relate_def, entities) self._validate_scenarios(scenarios, entities) expected_entities = { 'alarm11': Vertex(vertex_id='alarm11', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: NAGIOS_DATASOURCE, VProps.NAME: 'host_problem' }), 'resource11': Vertex(vertex_id='resource11', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE }), 'alarm': Vertex(vertex_id='alarm', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: NAGIOS_DATASOURCE, VProps.NAME: 'host_problem' }), 'resource': Vertex(vertex_id='resource', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE }) } expected_relationships = { 'alarm_on_host': EdgeDescription(edge=Edge( source_id='alarm', target_id='resource', label=EdgeLabel.ON, properties={EdgeProperties.RELATIONSHIP_TYPE: EdgeLabel.ON}), source=expected_entities['alarm'], target=expected_entities['resource']), } scenario_entities = { 'alarm': Vertex(vertex_id='alarm', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: NAGIOS_DATASOURCE, VProps.NAME: 'host_problem' }), 'resource': Vertex(vertex_id='resource', properties={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE }) } expected_scenario = Scenario( id='basic_template_with_include-scenario0', version=1, condition=[[ ConditionVar(symbol_name='alarm_on_host', positive=True) ]], actions=[ ActionSpecs( id='basic_template_with_include-scenario0-action0', type=ActionType.SET_STATE, targets={'target': 'resource'}, properties={'state': OperationalResourceState.SUBOPTIMAL}) ], subgraphs=template_data.scenarios[0].subgraphs, entities=scenario_entities, relationships=expected_relationships) self._validate_strict_equal(template_data, expected_entities, expected_relationships, expected_scenario)
def _file_to_edge(self, filename, source_id, target_id): props = self._load_resource_file(filename, 'edges') return Edge(source_id, target_id, props[EdgeProperties.RELATIONSHIP_TYPE], props)
def _file_to_edge(relative_path, source_id, target_id): full_path = RESOURCES_PATH + "/edges/" props = utils.load_specs(relative_path, full_path) return Edge(source_id, target_id, props[EdgeProperties.RELATIONSHIP_TYPE], props)
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) expected_entities = { 'alarm': Vertex(vertex_id='alarm', properties={ 'category': 'ALARM', 'type': 'nagios', 'name': 'host_problem' }), 'resource': Vertex(vertex_id='resource', properties={ 'category': 'RESOURCE', 'type': 'nova.host' }) } expected_relationships = { 'alarm_on_host': EdgeDescription(edge=Edge(source_id='alarm', target_id='resource', label='on', properties={'relationship_type': 'on'}), source=expected_entities['alarm'], target=expected_entities['resource']) } expected_scenario = Scenario( id='basic_template-scenario0', condition=[[ ConditionVar(symbol_name='alarm_on_host', positive=True) ]], actions=[ ActionSpecs(type='set_state', targets={'target': 'resource'}, properties={'state': 'SUBOPTIMAL'}) ], # TODO(yujunz): verify the built subgraph is consistent with # scenario definition. For now the observed value is # assigned to make test passing subgraphs=template_data.scenarios[0].subgraphs, entities=expected_entities, relationships=expected_relationships) self._validate_strict_equal(template_data, expected_entities, expected_relationships, expected_scenario)
class TemplateLoaderV3Test(BaseTest, TestConfiguration): expected_entities = { 'host_ssh_alarm': Vertex('host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_type': 'zabbix' }), 'host': Vertex('host', {'vitrage_type': 'nova.host'}), 'foo': Vertex('foo', {'name.regex': 'kuku'}), 'host_network_alarm': Vertex( 'host_network_alarm', { 'rawtext': 'host network interface is down', 'vitrage_type': 'zabbix', }), 'instance': Vertex('instance', {'vitrage_type': 'nova.instance'}), } expected_relationships = { 'host_ssh_alarm__on__host': EdgeDescription( Edge('host_ssh_alarm', 'host', 'on', {}), Vertex('host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_type': 'zabbix' }), Vertex('host', {'vitrage_type': 'nova.host'})), 'host__contains__instance': EdgeDescription(Edge('host', 'instance', 'contains', {}), Vertex('host', {'vitrage_type': 'nova.host'}), Vertex('instance', {'vitrage_type': 'nova.instance'})), 'host_network_alarm__on__host': EdgeDescription( Edge('host_network_alarm', 'host', 'on', {}), Vertex( 'host_network_alarm', { 'rawtext': 'host network interface is down', 'vitrage_type': 'zabbix' }), Vertex('host', {'vitrage_type': 'nova.host'})), } @classmethod def setUpClass(cls): super(TemplateLoaderV3Test, cls).setUpClass() cls.conf = cfg.ConfigOpts() cls.add_db(cls.conf) def _load_scenarios(self, file=None, content=None): if file and not content: content = self._get_yaml(file) return get_template_data(content).scenarios def _assert_scenario_equal(self, expected, observed): # Basic self.assertEqual(expected.id, observed.id) self.assertEqual(expected.version, observed.version) self.assertEqual(expected.condition, observed.condition) # is None # Actions self.assertEqual(len(expected.actions), len(observed.actions), 'actions count') for j in range(len(expected.actions)): expected_action = expected.actions[j] observed_action = observed.actions[j] self.assertEqual(expected_action.id, observed_action.id) self.assertEqual(expected_action.type, observed_action.type) self.assertEqual(expected_action.properties, observed_action.properties) if expected_action.type == 'execute_mistral': continue self.assertEqual(expected_action.targets, observed_action.targets) # Subgraphs self.assertEqual(len(expected.subgraphs), len(observed.subgraphs), 'subgraphs count') for j in range(len(expected.subgraphs)): expected_subgraph = expected.subgraphs[j] observed_subgraph = observed.subgraphs[j] self.assert_graph_equal(expected_subgraph, observed_subgraph) # Entities self.assert_dict_equal(expected.entities, observed.entities, 'entities comparison') self.assert_dict_equal(expected.relationships, observed.relationships, 'relationships comparison') @staticmethod def _get_yaml(filename): path = '%s/templates/v3_templates/%s' % (get_resources_dir(), filename) return file_utils.load_yaml_file(path) def test_scenarios(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') self.assertEqual(6, len(observed_scenarios), 'scenarios count') def test_scenario_0(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario0', '3', None, [ ActionSpecs('valid actions-scenario0-action0', 'set_state', {'target': 'host'}, {'state': 'ERROR'}), ActionSpecs('valid actions-scenario0-action1', 'raise_alarm', {'target': 'host'}, { 'severity': 'WARNING', 'alarm_name': 'ddd' }), ActionSpecs('valid actions-scenario0-action2', 'mark_down', {'target': 'host'}, {}), ActionSpecs('valid actions-scenario0-action3', 'execute_mistral', {'target': 'host'}, { 'input': { 'farewell': 'get_attr(host, name) bla bla' }, 'workflow': 'wf_1234' }), ], [ NXGraph(vertices=[ Vertex( 'host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }) ], edges=[ Edge( 'host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]) ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[0]) def test_scenario_1(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario1', '3', None, [ ActionSpecs('valid actions-scenario1-action0', 'add_causal_relationship', { 'target': 'host_ssh_alarm', 'source': 'host_network_alarm', }, {}), ], [ NXGraph(vertices=[ Vertex( 'host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'host_network_alarm', { 'rawtext': 'host network interface is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }) ], edges=[ Edge( 'host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }), Edge( 'host_network_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]) ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[1]) def test_scenario_2(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario2', '3', None, [ ActionSpecs( 'valid actions-scenario2-action0', 'raise_alarm', {'target': 'instance'}, { 'severity': 'WARNING', 'alarm_name': 'instance is down', 'causing_alarm': 'get_attr(host_ssh_alarm, vitrage_id)', }), ActionSpecs('valid actions-scenario2-action1', 'set_state', {'target': 'instance'}, {'state': 'SUBOPTIMAL'}), ], [ NXGraph(vertices=[ Vertex( 'host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'instance', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.instance', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ], edges=[ Edge( 'host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': False, 'negative_condition': False }), Edge( 'host', 'instance', 'contains', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]) ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[2]) def test_scenario_3(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario3', '3', None, [ ActionSpecs('valid actions-scenario3-action0', 'mark_down', {'target': 'host'}, {}), ], [ NXGraph(vertices=[ Vertex( 'instance', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.instance', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ], edges=[ Edge( 'host', 'instance', 'contains', { 'vitrage_is_deleted': False, 'negative_condition': False }) ]), NXGraph(vertices=[ Vertex( 'host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ], edges=[ Edge( 'host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': True, 'negative_condition': True, }), ]), ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[3]) def test_scenario_4(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario4', '3', None, [ ActionSpecs('valid actions-scenario4-action0', 'mark_down', {'target': 'host'}, {}), ], [ NXGraph(vertices=[ Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ]), ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[4]) def test_scenario_5(self): observed_scenarios = self._load_scenarios('valid_actions.yaml') expected_scenario = Scenario( 'valid actions-scenario5', '3', None, [ ActionSpecs('valid actions-scenario5-action0', 'mark_down', {'target': 'host'}, {}), ], [ NXGraph( vertices=[ Vertex( 'host_ssh_alarm', { 'rawtext': 'host ssh is down', 'vitrage_is_placeholder': False, 'vitrage_type': 'zabbix', 'vitrage_is_deleted': False, }), Vertex( 'instance', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.instance', 'vitrage_is_deleted': False, }), Vertex( 'host', { 'vitrage_is_placeholder': False, 'vitrage_type': 'nova.host', 'vitrage_is_deleted': False, }), ], edges=[ Edge('host_ssh_alarm', 'host', 'on', { 'vitrage_is_deleted': True, 'negative_condition': True }), Edge('host', 'instance', 'contains', { 'vitrage_is_deleted': True, 'negative_condition': True }) ]), ], TemplateLoaderV3Test.expected_entities, TemplateLoaderV3Test.expected_relationships) self._assert_scenario_equal(expected_scenario, observed_scenarios[5])