Esempio n. 1
0
    def test_execute_set_state(self):

        # Test Setup
        processor = self._create_processor_with_graph()

        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(0, ActionType.SET_STATE, targets, props)

        event_queue, action_executor = self._init_executer()

        # Test Action - do
        action_executor.execute(
            [ActionInfo(action_spec, ActionMode.DO, None, None)])
        self._consume_queue(event_queue, processor)

        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(
            [ActionInfo(action_spec, ActionMode.UNDO, None, None)])
        self._consume_queue(event_queue, processor)

        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)
Esempio n. 2
0
    def test_execute_add_vertex(self):

        # Test Setup
        processor = self._create_processor_with_graph()

        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(0, 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, action_executor = self._init_executer()

        # Test Action
        action_executor.execute(
            [ActionInfo(action_spec, ActionMode.DO, None, None)])
        self._consume_queue(event_queue, processor)

        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)
Esempio n. 3
0
    def test_execute_mark_down(self):

        # Test Setup
        processor = self._create_processor_with_graph()

        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(0, ActionType.MARK_DOWN, targets, props)

        event_queue, action_executor = self._init_executer()

        # Test Action - do
        action_executor.execute(
            [ActionInfo(action_spec, ActionMode.DO, None, None)])
        self._consume_queue(event_queue, processor)

        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(
            [ActionInfo(action_spec, ActionMode.UNDO, None, None)])
        self._consume_queue(event_queue, processor)

        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))
Esempio n. 4
0
    def test_execute_add_edge(self):

        # Test Setup
        processor = self._create_processor_with_graph()

        vertex_attrs = {VProps.VITRAGE_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.VITRAGE_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,
            TFields.SOURCE: alarm2
        }
        action_spec = ActionSpecs(
            0, ActionType.ADD_CAUSAL_RELATIONSHIP, targets, {})

        event_queue, action_executor = self._init_executer()

        before_edge = processor.entity_graph.get_edge(alarm2.vertex_id,
                                                      alarm1.vertex_id,
                                                      EdgeLabel.CAUSES)
        # Test Action - do
        action_executor.execute(
            [ActionInfo(action_spec, ActionMode.DO, None, None)])
        self._consume_queue(event_queue, processor)

        new_edge = processor.entity_graph.get_edge(alarm2.vertex_id,
                                                   alarm1.vertex_id,
                                                   EdgeLabel.CAUSES)
        # Test Assertions
        self.assertIsNone(before_edge)
        self.assertIsNotNone(new_edge)
Esempio n. 5
0
    def test_execute_add_and_remove_vertex(self):

        # Test Setup
        processor = self._create_processor_with_graph()

        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(0, 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, action_executor = self._init_executer()

        # Test Action - undo
        action_executor.execute(
            [ActionInfo(action_spec, ActionMode.UNDO, None, None)])
        self._consume_queue(event_queue, processor)

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

        # Test Assertions
        self.assertEqual(len(before_alarms) - 1, len(after_alarms))