Ejemplo n.º 1
0
    def _init_executer(self):
        event_queue = queue.Queue()

        def actions_callback(event_type, data):
            event_queue.put(data)

        return event_queue, ActionExecutor(actions_callback)
Ejemplo n.º 2
0
    def test_execute_add_vertex(self):

        # Test Setup
        processor = self._create_processor_with_graph(self.conf)

        vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE}
        host_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=vertex_attrs)

        host = host_vertices[0]

        targets = {TFields.TARGET: host}
        props = {
            TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE',
            TFields.SEVERITY: 'CRITICAL',
            VProps.STATE: AlarmProps.ACTIVE_STATE
        }

        # Raise alarm action adds new vertex with type vitrage to the graph
        action_spec = ActionSpecs(ActionType.RAISE_ALARM, targets, props)

        alarm_vertex_attrs = {VProps.TYPE: VITRAGE_TYPE}
        before_alarms = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarm_vertex_attrs)
        event_queue = queue.Queue()
        action_executor = ActionExecutor(event_queue)

        expected_alarm_id = 'ALARM:vitrage:%s:%s' % (props[TFields.ALARM_NAME],
                                                     host.vertex_id)
        # Test Action
        action_executor.execute(action_spec, ActionMode.DO)
        processor.process_event(event_queue.get())

        after_alarms = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarm_vertex_attrs)

        # Assertions
        self.assertEqual(len(before_alarms) + 1, len(after_alarms))
        self.assert_is_not_empty(after_alarms)

        alarms = [
            alarm for alarm in after_alarms
            if alarm.vertex_id == expected_alarm_id
        ]

        # Expected exactly one alarm with expected  id
        self.assertEqual(1, len(alarms))
        alarm = alarms[0]

        self.assertEqual(alarm.properties[VProps.CATEGORY],
                         EntityCategory.ALARM)
        self.assertEqual(alarm.properties[VProps.TYPE], VITRAGE_TYPE)
        self.assertEqual(alarm.properties[VProps.SEVERITY],
                         props[TFields.SEVERITY])
        self.assertEqual(alarm.properties[VProps.OPERATIONAL_SEVERITY],
                         props[TFields.SEVERITY])
        self.assertEqual(alarm.properties[VProps.STATE],
                         AlarmProps.ACTIVE_STATE)
Ejemplo n.º 3
0
    def test_execute_add_vertex(self):

        # Test Setup
        processor = self._create_processor_with_graph(self.conf)

        vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE}
        host_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=vertex_attrs)

        host = host_vertices[0]

        targets = {TFields.TARGET: host}
        props = {
            TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE',
            TFields.SEVERITY: OperationalAlarmSeverity.CRITICAL,
            VProps.STATE: AlarmProps.ACTIVE_STATE,
            VProps.RESOURCE_ID: host[VProps.ID],
            VProps.VITRAGE_ID: 'DUMMY_ID'
        }

        # Raise alarm action adds new vertex with type vitrage to the graph
        action_spec = ActionSpecs(ActionType.RAISE_ALARM, targets, props)

        alarm_vertex_attrs = {VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE}
        before_alarms = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarm_vertex_attrs)
        event_queue = queue.Queue()
        action_executor = ActionExecutor(self.conf, event_queue)

        # Test Action
        action_executor.execute(action_spec, ActionMode.DO)
        processor.process_event(event_queue.get())

        after_alarms = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarm_vertex_attrs)

        # Assertions
        self.assertEqual(len(before_alarms) + 1, len(after_alarms))
        self.assert_is_not_empty(after_alarms)

        alarm = after_alarms[0]

        self.assertEqual(alarm.properties[VProps.VITRAGE_CATEGORY],
                         EntityCategory.ALARM)
        self.assertEqual(alarm.properties[VProps.VITRAGE_TYPE],
                         VITRAGE_DATASOURCE)
        self.assertEqual(alarm.properties[VProps.SEVERITY],
                         props[TFields.SEVERITY])
        self.assertEqual(alarm.properties[VProps.VITRAGE_OPERATIONAL_SEVERITY],
                         props[TFields.SEVERITY])
        self.assertEqual(alarm.properties[VProps.STATE],
                         AlarmProps.ACTIVE_STATE)
        self.assertEqual(
            alarm.properties[VProps.VITRAGE_RESOURCE_ID],
            action_spec.targets[TTFields.TARGET][VProps.VITRAGE_ID]),
        self.assertEqual(alarm.properties[VProps.VITRAGE_RESOURCE_TYPE],
                         NOVA_HOST_DATASOURCE)
Ejemplo n.º 4
0
 def __init__(self,
              e_graph,
              scenario_repo,
              actions_callback,
              enabled=False):
     self._entity_graph = e_graph
     self._db = storage.get_connection_from_config()
     self._scenario_repo = scenario_repo
     self._action_executor = ActionExecutor(actions_callback)
     self._entity_graph.subscribe(self.process_event)
     self.enabled = enabled
     self.connected_component_cache = defaultdict(dict)
Ejemplo n.º 5
0
 def __init__(self,
              conf,
              entity_graph,
              scenario_repo,
              event_queue,
              enabled=False):
     self.conf = conf
     self._entity_graph = entity_graph
     self._graph_algs = create_algorithm(entity_graph)
     self._scenario_repo = scenario_repo
     self._action_executor = ActionExecutor(event_queue)
     self._entity_graph.subscribe(self.process_event)
     self.enabled = enabled
Ejemplo n.º 6
0
    def test_execute_set_state(self):

        # Test Setup
        processor = self._create_processor_with_graph(self.conf)

        vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE}
        host_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=vertex_attrs)
        host_vertex_before = host_vertices[0]

        targets = {TFields.TARGET: host_vertex_before}
        props = {TFields.STATE: OperationalResourceState.SUBOPTIMAL}
        action_spec = ActionSpecs(ActionType.SET_STATE, targets, props)

        event_queue = queue.Queue()
        action_executor = ActionExecutor(self.conf, event_queue)

        # Test Action - do
        action_executor.execute(action_spec, ActionMode.DO)
        processor.process_event(event_queue.get())

        host_vertex_after = processor.entity_graph.get_vertex(
            host_vertex_before.vertex_id)

        # Test Assertions
        agg_state_before = \
            host_vertex_before.get(VProps.VITRAGE_AGGREGATED_STATE)
        self.assertNotEqual(agg_state_before,
                            OperationalResourceState.SUBOPTIMAL)
        self.assertNotIn(VProps.VITRAGE_STATE, host_vertex_before.properties)

        agg_state_after = \
            host_vertex_after.get(VProps.VITRAGE_AGGREGATED_STATE)
        self.assertEqual(agg_state_after, OperationalResourceState.SUBOPTIMAL)
        v_state_after = host_vertex_after.get(VProps.VITRAGE_STATE)
        self.assertEqual(v_state_after, OperationalResourceState.SUBOPTIMAL)

        # Test Action - undo
        action_executor.execute(action_spec, ActionMode.UNDO)
        processor.process_event(event_queue.get())

        host_vertex_after_undo = processor.entity_graph.get_vertex(
            host_vertex_before.vertex_id)

        # Test Assertions
        agg_state_after_undo = \
            host_vertex_before.get(VProps.VITRAGE_AGGREGATED_STATE)
        self.assertEqual(agg_state_after_undo, agg_state_before)
        self.assertNotIn(VProps.VITRAGE_STATE,
                         host_vertex_after_undo.properties)
Ejemplo n.º 7
0
 def __init__(self,
              conf,
              entity_graph,
              scenario_repo,
              event_queue,
              enabled=False):
     self.conf = conf
     self._scenario_repo = scenario_repo
     self._entity_graph = entity_graph
     self._action_executor = ActionExecutor(event_queue)
     self._entity_graph.subscribe(self.process_event)
     self._action_tracker = ActionTracker(DatasourceInfoMapper(self.conf))
     self.enabled = enabled
     self.connected_component_cache = defaultdict(dict)
Ejemplo n.º 8
0
    def test_execute_add_edge(self):

        # Test Setup
        processor = self._create_processor_with_graph(self.conf)

        vertex_attrs = {VProps.TYPE: NOVA_HOST_DATASOURCE}
        host_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=vertex_attrs)

        host_1 = host_vertices[0]
        nagios_event1 = TestActionExecutor._get_nagios_event(
            host_1.get(VProps.ID), NOVA_HOST_DATASOURCE)
        processor.process_event(nagios_event1)

        host_2 = host_vertices[1]
        nagios_event2 = TestActionExecutor._get_nagios_event(
            host_2.get(VProps.ID), NOVA_HOST_DATASOURCE)
        processor.process_event(nagios_event2)

        alarms_attrs = {VProps.TYPE: NAGIOS_DATASOURCE}
        alarms_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarms_attrs)

        alarm1 = alarms_vertices[0]
        alarm2 = alarms_vertices[1]
        targets = {
            TFields.TARGET: alarm1.vertex_id,
            TFields.SOURCE: alarm2.vertex_id
        }
        action_spec = ActionSpecs(ActionType.ADD_CAUSAL_RELATIONSHIP,
                                  targets,
                                  {})

        event_queue = queue.Queue()
        action_executor = ActionExecutor(event_queue)

        before_edge = processor.entity_graph.get_edge(alarm2.vertex_id,
                                                      alarm1.vertex_id,
                                                      EdgeLabels.CAUSES)
        # Test Action - do
        action_executor.execute(action_spec, ActionMode.DO)
        processor.process_event(event_queue.get())

        new_edge = processor.entity_graph.get_edge(alarm2.vertex_id,
                                                   alarm1.vertex_id,
                                                   EdgeLabels.CAUSES)
        # Test Assertions
        self.assertIsNone(before_edge)
        self.assertIsNotNone(new_edge)
Ejemplo n.º 9
0
 def __init__(self,
              conf,
              e_graph,
              scenario_repo,
              actions_callback,
              enabled=False):
     super(ScenarioEvaluator, self).__init__(conf, e_graph)
     self._db_connection = storage.get_connection_from_config(self._conf)
     self._scenario_repo = scenario_repo
     self._action_executor = ActionExecutor(self._conf, actions_callback)
     self._entity_graph.subscribe(self.process_event)
     self._active_actions_tracker = ActiveActionsTracker(
         self._conf, self._db_connection)
     self.enabled = enabled
     self.connected_component_cache = defaultdict(dict)
Ejemplo n.º 10
0
    def test_execute_add_and_remove_vertex(self):

        # Test Setup
        processor = self._create_processor_with_graph(self.conf)

        vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE}
        host_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=vertex_attrs)

        host = host_vertices[0]

        targets = {TFields.TARGET: host}
        props = {
            TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE',
            TFields.SEVERITY: OperationalAlarmSeverity.CRITICAL,
            VProps.STATE: AlarmProps.ACTIVE_STATE,
            VProps.RESOURCE_ID: host[VProps.ID]
        }
        action_spec = ActionSpecs(ActionType.RAISE_ALARM, targets, props)

        add_vertex_event = TestActionExecutor._get_vitrage_add_vertex_event(
            host, props[TFields.ALARM_NAME], props[TFields.SEVERITY])

        processor.process_event(add_vertex_event)

        alarm_vertex_attrs = {
            VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE,
            VProps.VITRAGE_IS_DELETED: False
        }
        before_alarms = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarm_vertex_attrs)

        event_queue = queue.Queue()
        action_executor = ActionExecutor(self.conf, event_queue)

        # Test Action - undo
        action_executor.execute(action_spec, ActionMode.UNDO)
        event = event_queue.get()
        processor.process_event(event)

        after_alarms = processor.entity_graph.get_vertices(
            vertex_attr_filter=alarm_vertex_attrs)

        # Test Assertions
        self.assertEqual(len(before_alarms) - 1, len(after_alarms))
Ejemplo n.º 11
0
    def test_execute_mark_down(self):

        # Test Setup
        processor = self._create_processor_with_graph(self.conf)

        vertex_attrs = {VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE}
        host_vertices = processor.entity_graph.get_vertices(
            vertex_attr_filter=vertex_attrs)
        host_vertex_before = host_vertices[0]

        targets = {TFields.TARGET: host_vertex_before}
        props = {}
        action_spec = ActionSpecs(ActionType.MARK_DOWN, targets, props)

        event_queue = queue.Queue()
        action_executor = ActionExecutor(self.conf, event_queue)

        # Test Action - do
        action_executor.execute(action_spec, ActionMode.DO)
        processor.process_event(event_queue.get())

        host_vertex_after = processor.entity_graph.get_vertex(
            host_vertex_before.vertex_id)

        # Test Assertions
        self.assertTrue(host_vertex_after.get(VProps.IS_MARKED_DOWN))

        # Test Action - undo
        action_executor.execute(action_spec, ActionMode.UNDO)
        processor.process_event(event_queue.get())

        host_vertex_after_undo = processor.entity_graph.get_vertex(
            host_vertex_before.vertex_id)

        # Test Assertions
        self.assertFalse(host_vertex_after_undo.get(VProps.IS_MARKED_DOWN))