diff --git a/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py b/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py index b317f88f0..5ffdfa3c7 100644 --- a/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py +++ b/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py @@ -20,6 +20,7 @@ Collectd plugin for sending notifications to vitrage import collectd import hashlib import six +from vitrage.datasources.collectd import COLLECTD_DATASOURCE from vitrage.datasources.collectd.collectd_vitrage.plugin import CollectDPlugin from vitrage.datasources.collectd.collectd_vitrage.plugin import PluginError @@ -53,7 +54,7 @@ class VitrageNotifier(CollectDPlugin): transport = messaging.get_transport(cfg.CONF, url) self.notifier = messaging.Notifier(transport, driver='messagingv2', - publisher_id='collectd', + publisher_id=COLLECTD_DATASOURCE, topics=['vitrage_notifications']) self.add_notification_callback(self.notify) @@ -72,7 +73,7 @@ class VitrageNotifier(CollectDPlugin): notification_id = str(uuid.uuid4()) self.notifier.info(ctxt={'message_id': notification_id, - 'publisher_id': 'collectd', + 'publisher_id': COLLECTD_DATASOURCE, 'timestamp': datetime.utcnow()}, event_type='collectd.alarm.' + severity.lower(), payload=payload) diff --git a/vitrage/datasources/doctor/properties.py b/vitrage/datasources/doctor/properties.py index a69fa3b1d..55a27c8c3 100644 --- a/vitrage/datasources/doctor/properties.py +++ b/vitrage/datasources/doctor/properties.py @@ -13,11 +13,12 @@ # under the License. from vitrage.common.constants import EventProperties as EventProps +from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE class DoctorProperties(object): HOST_DOWN = 'compute.host.down' - HOST_TYPE = 'nova.host' + HOST_TYPE = NOVA_HOST_DATASOURCE UPDATE_TIME = 'update_time' diff --git a/vitrage/notifier/plugins/aodh/aodh_notifier.py b/vitrage/notifier/plugins/aodh/aodh_notifier.py index 970328577..6503accac 100644 --- a/vitrage/notifier/plugins/aodh/aodh_notifier.py +++ b/vitrage/notifier/plugins/aodh/aodh_notifier.py @@ -15,6 +15,7 @@ from oslo_log import log as logging from vitrage.common.constants import NotifierEventTypes from vitrage.common.constants import VertexProperties as VProps +from vitrage.datasources.aodh import AODH_DATASOURCE from vitrage.datasources.aodh.properties import AodhState from vitrage.entity_graph.mappings.operational_alarm_severity import \ OperationalAlarmSeverity @@ -36,7 +37,7 @@ class AodhNotifier(NotifierBase): @staticmethod def get_notifier_name(): - return 'aodh' + return AODH_DATASOURCE def __init__(self, conf): super(AodhNotifier, self).__init__(conf) diff --git a/vitrage/tests/functional/datasources/nagios/test_nagios.py b/vitrage/tests/functional/datasources/nagios/test_nagios.py index e12c5c7c2..b14b442bc 100644 --- a/vitrage/tests/functional/datasources/nagios/test_nagios.py +++ b/vitrage/tests/functional/datasources/nagios/test_nagios.py @@ -17,6 +17,7 @@ from oslo_config import cfg from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.nagios import NAGIOS_DATASOURCE +from vitrage.datasources.nagios.properties import NagiosTestStatus from vitrage.datasources import NOVA_HOST_DATASOURCE from vitrage.datasources import NOVA_INSTANCE_DATASOURCE from vitrage.datasources import NOVA_ZONE_DATASOURCE @@ -63,7 +64,7 @@ class TestNagios(TestDataSourcesBase): nagios_event['resource_name'] = \ self._find_entity_id_by_type(processor.entity_graph, NOVA_HOST_DATASOURCE) - nagios_event['status'] = 'critical' + nagios_event['status'] = NagiosTestStatus.CRITICAL # Action processor.process_event(nagios_event) diff --git a/vitrage/tests/functional/evaluator/test_action_executor.py b/vitrage/tests/functional/evaluator/test_action_executor.py index 7302aeb40..f656abefc 100644 --- a/vitrage/tests/functional/evaluator/test_action_executor.py +++ b/vitrage/tests/functional/evaluator/test_action_executor.py @@ -208,7 +208,7 @@ class TestActionExecutor(TestFunctionalBase): targets = {TFields.TARGET: host} props = { TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE', - TFields.SEVERITY: 'CRITICAL', + TFields.SEVERITY: OperationalAlarmSeverity.CRITICAL, VProps.STATE: AlarmProps.ACTIVE_STATE, VProps.RESOURCE_ID: host[VProps.ID], VProps.VITRAGE_ID: 'DUMMY_ID' @@ -266,7 +266,7 @@ class TestActionExecutor(TestFunctionalBase): targets = {TFields.TARGET: host} props = { TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE', - TFields.SEVERITY: 'CRITICAL', + TFields.SEVERITY: OperationalAlarmSeverity.CRITICAL, VProps.STATE: AlarmProps.ACTIVE_STATE, VProps.RESOURCE_ID: host[VProps.ID] } diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index 74465c403..97289c2a4 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -32,6 +32,8 @@ from vitrage.datasources.neutron.port import NEUTRON_PORT_DATASOURCE from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE +from vitrage.entity_graph.mappings.operational_resource_state import \ + OperationalResourceState from vitrage.evaluator.actions.evaluator_event_transformer \ import VITRAGE_DATASOURCE from vitrage.evaluator.scenario_evaluator import ScenarioEvaluator @@ -45,7 +47,7 @@ from vitrage.utils.datetime import utcnow _TARGET_HOST = 'host-2' _TARGET_ZONE = 'zone-1' -_NAGIOS_TEST_INFO = {'resource_name': _TARGET_HOST, +_NAGIOS_TEST_INFO = {NagiosProperties.RESOURCE_NAME: _TARGET_HOST, 'resource_id': _TARGET_HOST, DSProps.DATASOURCE_ACTION: DatasourceAction.SNAPSHOT} @@ -88,18 +90,20 @@ class TestScenarioEvaluator(TestFunctionalBase): 'host should be AVAILABLE when starting') # generate nagios alarm to trigger template scenario - test_vals = {'status': 'WARNING', 'service': 'cause_suboptimal_state'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'cause_suboptimal_state'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) warning_test = mock_driver.generate_random_events_list(generator)[0] host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) - self.assertEqual('SUBOPTIMAL', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.SUBOPTIMAL, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be SUBOPTIMAL with warning alarm') # next disable the alarm - warning_test['status'] = 'OK' + warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) self.assertEqual('AVAILABLE', host_v[VProps.VITRAGE_AGGREGATED_STATE], @@ -117,36 +121,42 @@ class TestScenarioEvaluator(TestFunctionalBase): 'host should be AVAILABLE when starting') # generate nagios alarm to trigger - test_vals = {'status': 'WARNING', 'service': 'cause_suboptimal_state'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'cause_suboptimal_state'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) warning_test = mock_driver.generate_random_events_list(generator)[0] host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) - self.assertEqual('SUBOPTIMAL', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.SUBOPTIMAL, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be SUBOPTIMAL with warning alarm') # generate CRITICAL nagios alarm to trigger - test_vals = {'status': 'CRITICAL', 'service': 'cause_error_state'} + test_vals = \ + {NagiosProperties.STATUS: NagiosTestStatus.CRITICAL, + NagiosProperties.SERVICE: 'cause_error_state'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) critical_test = mock_driver.generate_random_events_list(generator)[0] host_v = self.get_host_after_event(event_queue, critical_test, processor, _TARGET_HOST) - self.assertEqual('ERROR', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.ERROR, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be ERROR with critical alarm') # next disable the critical alarm - critical_test['status'] = 'OK' + critical_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, critical_test, processor, _TARGET_HOST) - self.assertEqual('SUBOPTIMAL', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.SUBOPTIMAL, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be SUBOPTIMAL with only warning alarm') # next disable the alarm - warning_test['status'] = 'OK' + warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) self.assertEqual('AVAILABLE', host_v[VProps.VITRAGE_AGGREGATED_STATE], @@ -164,32 +174,38 @@ class TestScenarioEvaluator(TestFunctionalBase): 'host should be AVAILABLE when starting') # generate CRITICAL nagios alarm to trigger - test_vals = {'status': 'CRITICAL', 'service': 'cause_error_state'} + test_vals = \ + {NagiosProperties.STATUS: NagiosTestStatus.CRITICAL, + NagiosProperties.SERVICE: 'cause_error_state'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) critical_test = mock_driver.generate_random_events_list(generator)[0] host_v = self.get_host_after_event(event_queue, critical_test, processor, _TARGET_HOST) - self.assertEqual('ERROR', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.ERROR, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be ERROR with critical alarm') # generate WARNING nagios alarm to trigger - test_vals = {'status': 'WARNING', 'service': 'cause_suboptimal_state'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'cause_suboptimal_state'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) warning_test = mock_driver.generate_random_events_list(generator)[0] host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) - self.assertEqual('ERROR', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.ERROR, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be ERROR with critical alarm') # next disable the critical alarm - critical_test['status'] = 'OK' + critical_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, critical_test, processor, _TARGET_HOST) - self.assertEqual('SUBOPTIMAL', host_v[VProps.VITRAGE_AGGREGATED_STATE], + self.assertEqual(OperationalResourceState.SUBOPTIMAL, + host_v[VProps.VITRAGE_AGGREGATED_STATE], 'host should be SUBOPTIMAL with only warning alarm') def test_deduced_alarm(self): @@ -204,8 +220,8 @@ class TestScenarioEvaluator(TestFunctionalBase): 'host should be AVAILABLE when starting') # generate CRITICAL nagios alarm to trigger - test_vals = {'status': 'WARNING', - 'service': 'cause_warning_deduced_alarm'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'cause_warning_deduced_alarm'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) warning_test = mock_driver.generate_random_events_list(generator)[0] @@ -215,12 +231,13 @@ class TestScenarioEvaluator(TestFunctionalBase): alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('WARNING', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.WARNING, + alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) self.assertEqual(1, len(causes)) # next disable the alarm - warning_test['status'] = 'OK' + warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) alarms = \ @@ -228,19 +245,20 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(0, len(alarms)) # recreate the nagios alarm - warning_test['status'] = 'WARNING' + warning_test[NagiosProperties.STATUS] = NagiosTestStatus.WARNING warning_test[DSProps.SAMPLE_DATE] = str(utcnow()) host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('WARNING', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.WARNING, + alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) self.assertEqual(1, len(causes)) # next disable the alarm - warning_test['status'] = 'OK' + warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) alarms = \ @@ -252,7 +270,8 @@ class TestScenarioEvaluator(TestFunctionalBase): event_queue, processor, evaluator = self._init_system() # generate WARNING nagios alarm - vals = {'status': 'WARNING', 'service': 'cause_warning_deduced_alarm'} + vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'cause_warning_deduced_alarm'} vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, vals) warning_test = mock_driver.generate_random_events_list(generator)[0] @@ -262,13 +281,14 @@ class TestScenarioEvaluator(TestFunctionalBase): alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('WARNING', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.WARNING, + alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) self.assertEqual(1, len(causes)) # generate CRITICAL nagios alarm to trigger - vals = {'status': 'CRITICAL', - 'service': 'cause_critical_deduced_alarm'} + vals = {NagiosProperties.STATUS: NagiosTestStatus.CRITICAL, + NagiosProperties.SERVICE: 'cause_critical_deduced_alarm'} vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, vals) critical_test = mock_driver.generate_random_events_list(generator)[0] @@ -278,23 +298,24 @@ class TestScenarioEvaluator(TestFunctionalBase): alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('CRITICAL', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.CRITICAL, + alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) self.assertEqual(2, len(causes)) # remove WARNING nagios alarm, leaving only CRITICAL one - warning_test['status'] = 'OK' + warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, warning_test, processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('CRITICAL', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.CRITICAL, alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) self.assertEqual(1, len(causes)) # next disable the alarm - critical_test['status'] = 'OK' + critical_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, critical_test, processor, _TARGET_HOST) alarms = \ @@ -306,8 +327,9 @@ class TestScenarioEvaluator(TestFunctionalBase): event_queue, processor, evaluator = self._init_system() # generate CRITICAL nagios alarm to trigger - test_vals = {'status': 'CRITICAL', - 'service': 'cause_critical_deduced_alarm'} + test_vals = \ + {NagiosProperties.STATUS: NagiosTestStatus.CRITICAL, + NagiosProperties.SERVICE: 'cause_critical_deduced_alarm'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) critical_test = mock_driver.generate_random_events_list(generator)[0] @@ -317,11 +339,12 @@ class TestScenarioEvaluator(TestFunctionalBase): alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('CRITICAL', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.CRITICAL, + alarms[0][VProps.SEVERITY]) # generate WARNING nagios alarm to trigger - test_vals = {'status': 'WARNING', - 'service': 'cause_warning_deduced_alarm'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'cause_warning_deduced_alarm'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) warning_test = mock_driver.generate_random_events_list(generator)[0] @@ -331,16 +354,18 @@ class TestScenarioEvaluator(TestFunctionalBase): alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('CRITICAL', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.CRITICAL, + alarms[0][VProps.SEVERITY]) # remove CRITICAL nagios alarm, leaving only WARNING one - critical_test['status'] = 'OK' + critical_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, critical_test, processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(1, len(alarms)) - self.assertEqual('WARNING', alarms[0]['severity']) + self.assertEqual(NagiosTestStatus.WARNING, + alarms[0][VProps.SEVERITY]) def test_simple_not_operator_deduced_alarm(self): """Handles a simple not operator use case @@ -439,13 +464,14 @@ class TestScenarioEvaluator(TestFunctionalBase): 'simple_port_deduced_alarm') # Add PORT_PROBLEM alarm - test_vals = {'status': 'WARNING', + test_vals = {'status': NagiosTestStatus.WARNING, 'service': 'PORT_PROBLEM', 'name': 'PORT_PROBLEM', DSProps.DATASOURCE_ACTION: DatasourceAction.SNAPSHOT, VProps.RESOURCE_ID: port_vertex.get(VProps.ID), - 'resource_name': port_vertex.get(VProps.ID), - 'resource_type': NEUTRON_PORT_DATASOURCE} + NagiosProperties.RESOURCE_NAME: + port_vertex.get(VProps.ID), + NagiosProperties.RESOURCE_TYPE: NEUTRON_PORT_DATASOURCE} generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) nagios_event = mock_driver.generate_random_events_list(generator)[0] @@ -722,7 +748,7 @@ class TestScenarioEvaluator(TestFunctionalBase): # add edge between network and zone edge = create_edge(network_vertex.vertex_id, zone_vertex.vertex_id, - 'attached') + EdgeLabel.ATTACHED) entity_graph.add_edge(edge) while not event_queue.empty(): @@ -746,13 +772,14 @@ class TestScenarioEvaluator(TestFunctionalBase): # ################### STEP 2 ################### # Add NETWORK_PROBLEM alarm - test_vals = {'status': 'WARNING', + test_vals = {'status': NagiosTestStatus.WARNING, 'service': 'NETWORK_PROBLEM', 'name': 'NETWORK_PROBLEM', DSProps.DATASOURCE_ACTION: DatasourceAction.SNAPSHOT, VProps.RESOURCE_ID: network_vertex[VProps.ID], - 'resource_name': network_vertex[VProps.ID], - 'resource_type': NEUTRON_NETWORK_DATASOURCE} + NagiosProperties.RESOURCE_NAME: network_vertex[VProps.ID], + NagiosProperties.RESOURCE_TYPE: + NEUTRON_NETWORK_DATASOURCE} generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) nagios_event = mock_driver.generate_random_events_list(generator)[0] @@ -1179,8 +1206,8 @@ class TestScenarioEvaluator(TestFunctionalBase): 'host should be AVAILABLE when starting') # generate nagios alarm1 to trigger, raise alarm3 - test_vals = {'status': 'WARNING', - 'service': 'alarm1'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'alarm1'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm1_test = mock_driver.generate_random_events_list(generator)[0] @@ -1191,8 +1218,8 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(2, len(alarms)) # generate nagios alarm2 to trigger - test_vals = {'status': 'WARNING', - 'service': 'alarm2'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'alarm2'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm2_test = mock_driver.generate_random_events_list(generator)[0] @@ -1203,14 +1230,14 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(3, len(alarms)) # disable alarm1, alarm3 is not deleted - alarm1_test['status'] = 'OK' + alarm1_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, alarm1_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, processor.entity_graph) self.assertEqual(2, len(alarms)) # disable alarm2, alarm3 is deleted - alarm2_test['status'] = 'OK' + alarm2_test[NagiosProperties.STATUS] = NagiosTestStatus.OK alarm2_test[DSProps.SAMPLE_DATE] = str(utcnow()) host_v = self.get_host_after_event(event_queue, alarm2_test, processor, _TARGET_HOST) @@ -1246,8 +1273,8 @@ class TestScenarioEvaluator(TestFunctionalBase): 'host should be AVAILABLE when starting') # generate nagios alarm_a to trigger - test_vals = {'status': 'WARNING', - 'service': 'alarm_a'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'alarm_a'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm_a_test = mock_driver.generate_random_events_list(generator)[0] @@ -1260,8 +1287,8 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(num_orig_edges + 1, entity_graph.num_edges()) # generate nagios alarm_b to trigger - test_vals = {'status': 'WARNING', - 'service': 'alarm_b'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'alarm_b'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm_b_test = mock_driver.generate_random_events_list(generator)[0] @@ -1274,8 +1301,8 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(num_orig_edges + 2, entity_graph.num_edges()) # generate nagios alarm_c to trigger, alarm_d is raised - test_vals = {'status': 'WARNING', - 'service': 'alarm_c'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, + NagiosProperties.SERVICE: 'alarm_c'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm_c_test = mock_driver.generate_random_events_list(generator)[0] @@ -1288,8 +1315,8 @@ class TestScenarioEvaluator(TestFunctionalBase): self.assertEqual(num_orig_edges + 4, entity_graph.num_edges()) # remove nagios alarm_b, alarm_d should not be removed - test_vals = {'status': 'OK', - 'service': 'alarm_b'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.OK, + NagiosProperties.SERVICE: 'alarm_b'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm_b_ok = mock_driver.generate_random_events_list(generator)[0] @@ -1313,8 +1340,8 @@ class TestScenarioEvaluator(TestFunctionalBase): entity_graph.num_edges()) # remove nagios alarm_a, alarm_d should be removed - test_vals = {'status': 'OK', - 'service': 'alarm_a'} + test_vals = {NagiosProperties.STATUS: NagiosTestStatus.OK, + NagiosProperties.SERVICE: 'alarm_a'} test_vals.update(_NAGIOS_TEST_INFO) generator = mock_driver.simple_nagios_alarm_generators(1, 1, test_vals) alarm_a_ok = mock_driver.generate_random_events_list(generator)[0] diff --git a/vitrage/tests/mocks/mock_driver.py b/vitrage/tests/mocks/mock_driver.py index 41126a78d..c0cc36ec0 100644 --- a/vitrage/tests/mocks/mock_driver.py +++ b/vitrage/tests/mocks/mock_driver.py @@ -354,7 +354,8 @@ def simple_switch_generators(switch_num, host_num, ) if update_events: update_vals = {} if not update_vals else update_vals - update_vals['vitrage_datasource_action'] = 'update' + update_vals[DSProps.DATASOURCE_ACTION] = \ + DatasourceAction.UPDATE test_entity_spec_list.append( {tg.DYNAMIC_INFO_FKEY: tg.DRIVER_SWITCH_SNAPSHOT_D, tg.STATIC_INFO_FKEY: None, diff --git a/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py b/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py index cc94b5734..27665f898 100644 --- a/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py +++ b/vitrage/tests/unit/datasources/collectd/test_collectd_driver.py @@ -16,6 +16,7 @@ from datetime import datetime from oslo_config import cfg from vitrage.common.constants import DatasourceProperties as DSProps +from vitrage.datasources.collectd import COLLECTD_DATASOURCE from vitrage.datasources.collectd.driver import CollectdDriver from vitrage.datasources.collectd.properties \ import CollectdProperties as CProps @@ -36,7 +37,7 @@ class TestCollectdDriver(base.BaseTest): @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='collectd') + cls.conf.register_opts(cls.OPTS, group=COLLECTD_DATASOURCE) # noinspection PyAttributeOutsideInit def setUp(self): diff --git a/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py b/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py index 494d26d73..c7391a5cf 100644 --- a/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py +++ b/vitrage/tests/unit/datasources/doctor/test_doctor_driver.py @@ -17,6 +17,7 @@ from oslo_config import cfg from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import EventProperties as EventProps +from vitrage.datasources.doctor import DOCTOR_DATASOURCE from vitrage.datasources.doctor.driver import DoctorDriver from vitrage.datasources.doctor.properties import DoctorDetails from vitrage.datasources.doctor.properties import DoctorProperties \ @@ -34,7 +35,7 @@ class DoctorDriverTest(base.BaseTest): @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='doctor') + cls.conf.register_opts(cls.OPTS, group=DOCTOR_DATASOURCE) def test_enrich_event(self): # Test setup diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_config.py b/vitrage/tests/unit/datasources/nagios/test_nagios_config.py index d08292767..57d544034 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_config.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_config.py @@ -17,6 +17,7 @@ from oslo_config import cfg from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.datasources.nagios.config import NagiosConfig from vitrage.datasources.nagios.config import NagiosHostMapping +from vitrage.datasources.nagios import NAGIOS_DATASOURCE from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE from vitrage.tests import base @@ -81,7 +82,7 @@ class TestNagiosConfig(base.BaseTest): @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='nagios') + cls.conf.register_opts(cls.OPTS, group=NAGIOS_DATASOURCE) def test_nagios_configuration_loading(self): # Action diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py index 837a06073..f1d456464 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py @@ -17,8 +17,10 @@ from oslo_config import cfg from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import GraphAction +from vitrage.datasources.nagios import NAGIOS_DATASOURCE from vitrage.datasources.nagios.properties import NagiosProperties as \ NagiosProps +from vitrage.datasources.nagios.properties import NagiosTestStatus from vitrage.tests.mocks import utils from vitrage.tests.unit.datasources.nagios.mock_driver import MockNagiosDriver from vitrage.tests.unit.datasources.nagios.nagios_base_test import \ @@ -40,7 +42,7 @@ class NagiosDriverTest(NagiosBaseTest): @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='nagios') + cls.conf.register_opts(cls.OPTS, group=NAGIOS_DATASOURCE) def test_get_all(self): """Check get_all functionality. @@ -55,13 +57,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -77,13 +79,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -99,13 +101,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -122,13 +124,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -166,13 +168,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -188,13 +190,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -210,13 +212,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -233,13 +235,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -255,13 +257,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -291,13 +293,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -338,13 +340,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -379,13 +381,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} nagios_driver.set_service_datas([service_data1, service_data2, @@ -402,13 +404,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'CRITICAL'} + NagiosProps.STATUS: NagiosTestStatus.CRITICAL} nagios_driver.set_service_datas([service_data1, service_data2, @@ -448,13 +450,13 @@ class NagiosDriverTest(NagiosBaseTest): # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} service_data3 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'Uptime', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2, @@ -470,10 +472,10 @@ class NagiosDriverTest(NagiosBaseTest): # Action - delete a service that was OK service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2]) @@ -487,7 +489,7 @@ class NagiosDriverTest(NagiosBaseTest): # Action - delete a service that was not OK service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data2]) @@ -510,10 +512,10 @@ class NagiosDriverTest(NagiosBaseTest): # Action - "undelete" the service that was OK service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'WARNING'} + NagiosProps.STATUS: NagiosTestStatus.WARNING} service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data1, service_data2]) @@ -528,7 +530,7 @@ class NagiosDriverTest(NagiosBaseTest): # Action - delete a service that was not OK and call get_changes service_data2 = {NagiosProps.RESOURCE_NAME: 'compute-1', NagiosProps.SERVICE: 'CPU utilization', - NagiosProps.STATUS: 'OK'} + NagiosProps.STATUS: NagiosTestStatus.OK} nagios_driver.set_service_datas([service_data2]) diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_parser.py b/vitrage/tests/unit/datasources/nagios/test_nagios_parser.py index 6a961a77f..49ef6e5ef 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_parser.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_parser.py @@ -14,6 +14,7 @@ from vitrage.datasources.nagios.parser import NagiosParser from vitrage.datasources.nagios.properties import NagiosProperties +from vitrage.datasources.nagios.properties import NagiosTestStatus from vitrage.tests.mocks import utils from vitrage.tests.unit.datasources.nagios.nagios_base_test \ import NagiosBaseTest @@ -23,7 +24,7 @@ class NagiosParserTest(NagiosBaseTest): expected_service1 = {NagiosProperties.RESOURCE_NAME: 'compute-0-0.local', NagiosProperties.SERVICE: 'CPU load', - NagiosProperties.STATUS: 'WARNING', + NagiosProperties.STATUS: NagiosTestStatus.WARNING, NagiosProperties.LAST_CHECK: '2016-02-09 13:05:32', NagiosProperties.DURATION: ' 8d 2h 16m 33s', NagiosProperties.ATTEMPT: '1/1', @@ -32,7 +33,7 @@ class NagiosParserTest(NagiosBaseTest): expected_service2 = {NagiosProperties.RESOURCE_NAME: 'compute-0-1.local', NagiosProperties.SERVICE: 'check_load', - NagiosProperties.STATUS: 'CRITICAL', + NagiosProperties.STATUS: NagiosTestStatus.CRITICAL, NagiosProperties.LAST_CHECK: '2016-02-16 14:27:06', NagiosProperties.DURATION: ' 1d 0h 54m 59s', NagiosProperties.ATTEMPT: '1/1', @@ -41,7 +42,7 @@ class NagiosParserTest(NagiosBaseTest): expected_service3 = {NagiosProperties.RESOURCE_NAME: 'compute-0-0.local', NagiosProperties.SERVICE: 'Disk IO SUMMARY', - NagiosProperties.STATUS: 'OK', + NagiosProperties.STATUS: NagiosTestStatus.OK, NagiosProperties.LAST_CHECK: '2016-02-17 15:21:22', NagiosProperties.DURATION: '14d 1h 28m 34s', NagiosProperties.ATTEMPT: '1/1', diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py index 91a4cad1a..c7afd5baa 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py @@ -108,7 +108,7 @@ class NagiosTransformerTest(base.BaseTest): def _validate_action(self, alarm, wrapper): ds_action = alarm[DSProps.DATASOURCE_ACTION] if ds_action in (DatasourceAction.SNAPSHOT, DatasourceAction.UPDATE): - if alarm[NagiosProperties.STATUS] == 'OK': + if alarm[NagiosProperties.STATUS] == NagiosTestStatus.OK: self.assertEqual(GraphAction.DELETE_ENTITY, wrapper.action) else: self.assertEqual(GraphAction.UPDATE_ENTITY, wrapper.action) diff --git a/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py index 3934a758b..a5410b2ca 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py @@ -296,7 +296,7 @@ class NovaInstanceTransformerTest(base.BaseTest): }, DSProps.DATASOURCE_ACTION: 'SNAPSHOT', 'id': 'instance321', - 'vitrage_sample_date': time + DSProps.SAMPLE_DATE: time } # Test action diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py index 47a6a5994..a01e30321 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_configuration.py @@ -19,6 +19,7 @@ from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE from vitrage.datasources.zabbix.driver import ZabbixDriver from vitrage.datasources.zabbix.properties import ZabbixProperties \ as ZabbixProps +from vitrage.datasources.zabbix import ZABBIX_DATASOURCE from vitrage.tests import base from vitrage.tests.mocks import utils @@ -70,7 +71,7 @@ class TestZabbixConfig(base.BaseTest): @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='zabbix') + cls.conf.register_opts(cls.OPTS, group=ZABBIX_DATASOURCE) def test_zabbix_configuration_loading(self): # Action diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py index 30992c09e..97e23aa46 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py @@ -20,6 +20,7 @@ from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import GraphAction from vitrage.datasources.zabbix.properties import ZabbixProperties as ZProps +from vitrage.datasources.zabbix import ZABBIX_DATASOURCE from vitrage.tests.mocks import utils from vitrage.tests.unit.datasources.zabbix.mock_driver import MockZabbixDriver from vitrage.tests.unit.datasources.zabbix.zabbix_base_test import \ @@ -40,7 +41,7 @@ class ZabbixDriverTest(ZabbixBaseTest): @classmethod def setUpClass(cls): cls.conf = cfg.ConfigOpts() - cls.conf.register_opts(cls.OPTS, group='zabbix') + cls.conf.register_opts(cls.OPTS, group=ZABBIX_DATASOURCE) def test_get_all(self): # Test Setup diff --git a/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py b/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py index f964eb369..652181815 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py +++ b/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from vitrage.common.constants import EdgeLabel +from vitrage.common.constants import EntityCategory from vitrage.entity_graph.processor import processor_utils as PUtils from vitrage.graph.driver.networkx_graph import NXGraph from vitrage.tests.unit.entity_graph.processor import base @@ -27,8 +29,10 @@ class TestEntityGraphManager(base.TestBaseProcessor): entity_graph = NXGraph("Entity Graph") # create vertex properties - vertex = self._update_vertex_to_graph(entity_graph, 'RESOURCE', - 'INSTANCE', '12345', + vertex = self._update_vertex_to_graph(entity_graph, + EntityCategory.RESOURCE, + 'INSTANCE', + '12345', False, True, {}) # deal with placeholder vertex @@ -37,8 +41,10 @@ class TestEntityGraphManager(base.TestBaseProcessor): self.assertTrue(vertex is None) # create vertex properties - vertex = self._update_vertex_to_graph(entity_graph, 'RESOURCE', - 'INSTANCE', '12345', + vertex = self._update_vertex_to_graph(entity_graph, + EntityCategory.RESOURCE, + 'INSTANCE', + '12345', False, False, {}) # deal with non placeholder vertex @@ -50,8 +56,10 @@ class TestEntityGraphManager(base.TestBaseProcessor): entity_graph = NXGraph("Entity Graph") # create vertex properties - vertex = self._update_vertex_to_graph(entity_graph, 'RESOURCE', - 'INSTANCE', '12345', + vertex = self._update_vertex_to_graph(entity_graph, + EntityCategory.RESOURCE, + 'INSTANCE', + '12345', False, True, {}) # check vitrage deleted @@ -63,14 +71,20 @@ class TestEntityGraphManager(base.TestBaseProcessor): entity_graph = NXGraph("Entity Graph") # create vertex properties - vertex1 = self._update_vertex_to_graph(entity_graph, 'RESOURCE', - 'INSTANCE', '12345', + vertex1 = self._update_vertex_to_graph(entity_graph, + EntityCategory.RESOURCE, + 'INSTANCE', + '12345', False, True, {}) - vertex2 = self._update_vertex_to_graph(entity_graph, 'RESOURCE', - 'HOST', '54321', + vertex2 = self._update_vertex_to_graph(entity_graph, + EntityCategory.RESOURCE, + 'HOST', + '54321', False, True, {}) - edge = self._update_edge_to_graph(entity_graph, vertex1.vertex_id, - vertex2.vertex_id, 'contains') + edge = self._update_edge_to_graph(entity_graph, + vertex1.vertex_id, + vertex2.vertex_id, + EdgeLabel.CONTAINS) # check vitrage deleted self.assertFalse(PUtils.is_deleted(edge)) @@ -80,11 +94,12 @@ class TestEntityGraphManager(base.TestBaseProcessor): def test_find_neighbor_types(self): neighbors = [] entity_graph = NXGraph("Entity Graph") - entities_details = [('RESOURCE', 'HOST', '1', False, True), - ('RESOURCE', 'STORAGE', '2', False, True), - ('RESOURCE', 'APPLICATION', '3', False, True), - ('RESOURCE', 'STORAGE', '4', False, True), - ('ALARM', 'INSTANCE_AT_RISK', '5', False, True)] + entities_details = \ + [(EntityCategory.RESOURCE, 'HOST', '1', False, True), + (EntityCategory.RESOURCE, 'STORAGE', '2', False, True), + (EntityCategory.RESOURCE, 'APPLICATION', '3', False, True), + (EntityCategory.RESOURCE, 'STORAGE', '4', False, True), + (EntityCategory.ALARM, 'INSTANCE_AT_RISK', '5', False, True)] # add neighbors for details in entities_details: diff --git a/vitrage/tests/unit/entity_graph/processor/test_processor.py b/vitrage/tests/unit/entity_graph/processor/test_processor.py index 1d3c70f25..ae894fa9b 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_processor.py +++ b/vitrage/tests/unit/entity_graph/processor/test_processor.py @@ -330,32 +330,37 @@ class TestProcessor(TestEntityGraphUnitBase): # vitrage state doesn't exist and its updated instances[1][0][VProps.STATE] = None instances[1][1].entity_graph.update_vertex(instances[1][0]) - instances[1][0][VProps.VITRAGE_STATE] = 'SUBOPTIMAL' + instances[1][0][VProps.VITRAGE_STATE] = \ + OperationalResourceState.SUBOPTIMAL instances[1][1]._calculate_vitrage_aggregated_state( instances[1][0], GraphAction.UPDATE_ENTITY) # state exists and vitrage state changes - instances[2][0][VProps.VITRAGE_STATE] = 'SUBOPTIMAL' + instances[2][0][VProps.VITRAGE_STATE] = \ + OperationalResourceState.SUBOPTIMAL instances[2][1]._calculate_vitrage_aggregated_state( instances[2][0], GraphAction.UPDATE_ENTITY) # vitrage state exists and state changes instances[3][0][VProps.STATE] = None - instances[3][0][VProps.VITRAGE_STATE] = 'SUBOPTIMAL' + instances[3][0][VProps.VITRAGE_STATE] = \ + OperationalResourceState.SUBOPTIMAL instances[3][1].entity_graph.update_vertex(instances[3][0]) instances[3][0][VProps.STATE] = 'SUSPENDED' instances[3][1]._calculate_vitrage_aggregated_state( instances[3][0], GraphAction.UPDATE_ENTITY) # state and vitrage state exists and state changes - instances[4][0][VProps.VITRAGE_STATE] = 'SUBOPTIMAL' + instances[4][0][VProps.VITRAGE_STATE] = \ + OperationalResourceState.SUBOPTIMAL instances[4][1].entity_graph.update_vertex(instances[4][0]) instances[4][0][VProps.STATE] = 'SUSPENDED' instances[4][1]._calculate_vitrage_aggregated_state( instances[4][0], GraphAction.UPDATE_ENTITY) # state and vitrage state exists and vitrage state changes - instances[5][0][VProps.VITRAGE_STATE] = 'SUBOPTIMAL' + instances[5][0][VProps.VITRAGE_STATE] = \ + OperationalResourceState.SUBOPTIMAL instances[5][1].entity_graph.update_vertex(instances[5][0]) instances[5][1]._calculate_vitrage_aggregated_state( instances[5][0], GraphAction.UPDATE_ENTITY) @@ -365,11 +370,11 @@ class TestProcessor(TestEntityGraphUnitBase): instances[0][0][VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[0][0][VProps.VITRAGE_OPERATIONAL_STATE]) - self.assertEqual('SUBOPTIMAL', + self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[1][0][VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[1][0][VProps.VITRAGE_OPERATIONAL_STATE]) - self.assertEqual('SUBOPTIMAL', + self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[2][0][VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[2][0][VProps.VITRAGE_OPERATIONAL_STATE]) @@ -381,7 +386,7 @@ class TestProcessor(TestEntityGraphUnitBase): instances[4][0][VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[4][0][VProps.VITRAGE_OPERATIONAL_STATE]) - self.assertEqual('SUBOPTIMAL', + self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[5][0][VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, instances[5][0][VProps.VITRAGE_OPERATIONAL_STATE]) diff --git a/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py b/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py index d1aee0b8a..b0bfbc489 100644 --- a/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py +++ b/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py @@ -225,12 +225,12 @@ class TestDatasourceInfoMapper(base.BaseTest): vitrage_category=EntityCategory.RESOURCE, vitrage_type=NOVA_INSTANCE_DATASOURCE, entity_state='ACTIVE') - metadata2 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'} + metadata2 = {VProps.VITRAGE_STATE: OperationalResourceState.SUBOPTIMAL} new_vertex2 = create_vertex('23456', vitrage_category=EntityCategory.RESOURCE, vitrage_type=NOVA_INSTANCE_DATASOURCE, metadata=metadata2) - metadata3 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'} + metadata3 = {VProps.VITRAGE_STATE: OperationalResourceState.SUBOPTIMAL} new_vertex3 = create_vertex('34567', vitrage_category=EntityCategory.RESOURCE, vitrage_type=NOVA_INSTANCE_DATASOURCE, @@ -254,11 +254,11 @@ class TestDatasourceInfoMapper(base.BaseTest): new_vertex1[VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.OK, new_vertex1[VProps.VITRAGE_OPERATIONAL_STATE]) - self.assertEqual('SUBOPTIMAL', + self.assertEqual(OperationalResourceState.SUBOPTIMAL, new_vertex2[VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, new_vertex2[VProps.VITRAGE_OPERATIONAL_STATE]) - self.assertEqual('SUBOPTIMAL', + self.assertEqual(OperationalResourceState.SUBOPTIMAL, new_vertex3[VProps.VITRAGE_AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.SUBOPTIMAL, new_vertex3[VProps.VITRAGE_OPERATIONAL_STATE]) diff --git a/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py b/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py index 2ca4e0402..7a6fe268c 100644 --- a/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py +++ b/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py @@ -11,6 +11,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from vitrage.entity_graph.mappings.operational_resource_state import \ + OperationalResourceState from vitrage.common.constants import VertexProperties as VProps from vitrage.evaluator.actions.base import ActionType @@ -33,7 +35,7 @@ class SetStateRecipeTest(base.BaseTest): cls.target_vertex = Vertex('RESOURCE:nova.host:test1') targets = {TFields.TARGET: cls.target_vertex} - cls.props = {TFields.STATE: 'SUBOPTIMAL'} + cls.props = {TFields.STATE: OperationalResourceState.SUBOPTIMAL} cls.action_spec = ActionSpecs(ActionType.SET_STATE, targets, cls.props) diff --git a/vitrage/tests/unit/evaluator/test_template_content_validator.py b/vitrage/tests/unit/evaluator/test_template_content_validator.py index 4bf7698f2..f56d5eb23 100644 --- a/vitrage/tests/unit/evaluator/test_template_content_validator.py +++ b/vitrage/tests/unit/evaluator/test_template_content_validator.py @@ -14,6 +14,8 @@ import copy import logging +from vitrage.entity_graph.mappings.operational_resource_state import \ + OperationalResourceState from vitrage.common.constants import EntityCategory from vitrage.evaluator.actions.base import ActionType @@ -480,7 +482,7 @@ class TemplateContentValidatorTest(base.BaseTest): TemplateFields.TARGET: target } properties = { - TemplateFields.STATE: 'SUBOPTIMAL' + TemplateFields.STATE: OperationalResourceState.SUBOPTIMAL } action = { TemplateFields.ACTION_TYPE: ActionType.SET_STATE, diff --git a/vitrage/tests/unit/evaluator/test_template_data.py b/vitrage/tests/unit/evaluator/test_template_data.py index edef01ba8..dd42f09b6 100644 --- a/vitrage/tests/unit/evaluator/test_template_data.py +++ b/vitrage/tests/unit/evaluator/test_template_data.py @@ -12,10 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. +from vitrage.common.constants import EdgeLabel +from vitrage.common.constants import EdgeProperties from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.nagios import NAGIOS_DATASOURCE from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE +from vitrage.entity_graph.mappings.operational_resource_state import \ + OperationalResourceState +from vitrage.evaluator.scenario_evaluator import ActionType from vitrage.evaluator.template_data import ActionSpecs from vitrage.evaluator.template_data import ConditionVar from vitrage.evaluator.template_data import EdgeDescription @@ -77,8 +82,9 @@ class BasicTemplateTest(base.BaseTest): 'alarm_on_host': EdgeDescription( edge=Edge(source_id='alarm', target_id='resource', - label='on', - properties={'relationship_type': 'on'}), + label=EdgeLabel.ON, + properties={EdgeProperties.RELATIONSHIP_TYPE: + EdgeLabel.ON}), source=expected_entities['alarm'], target=expected_entities['resource'] ) @@ -91,9 +97,10 @@ class BasicTemplateTest(base.BaseTest): positive=True)]], actions=[ ActionSpecs( - type='set_state', + type=ActionType.SET_STATE, targets={'target': 'resource'}, - properties={'state': 'SUBOPTIMAL'})], + 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 @@ -202,7 +209,7 @@ class BasicTemplateTest(base.BaseTest): self.assertEqual(len(actions), 1) action = actions[0] - self.assertEqual(action.type, 'set_state') + self.assertEqual(action.type, ActionType.SET_STATE) targets = action.targets self.assertEqual(len(targets), 1) @@ -210,4 +217,5 @@ class BasicTemplateTest(base.BaseTest): properties = action.properties self.assertEqual(len(properties), 1) - self.assertEqual(properties['state'], 'SUBOPTIMAL') + self.assertEqual(properties['state'], + OperationalResourceState.SUBOPTIMAL) diff --git a/vitrage/tests/unit/notifier/snmp_notifier/common.py b/vitrage/tests/unit/notifier/snmp_notifier/common.py index 19c578bcf..fab3b587d 100644 --- a/vitrage/tests/unit/notifier/snmp_notifier/common.py +++ b/vitrage/tests/unit/notifier/snmp_notifier/common.py @@ -11,13 +11,15 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from vitrage.entity_graph.mappings.operational_alarm_severity import \ + OperationalAlarmSeverity from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps + false_ = 'False' name_ = 'VM network problem' -critical_ = 'CRITICAL' GENERAL_OID = '1.3.6.1.4.1' COMPANY_OID = '1.1.1' @@ -34,7 +36,8 @@ alarm_data = {VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.RESOURCE + '_' + VProps.VITRAGE_IS_DELETED: false_, VProps.RESOURCE + '_' + VProps.VITRAGE_IS_PLACEHOLDER: false_, VProps.VITRAGE_IS_DELETED: false_, - VProps.VITRAGE_OPERATIONAL_SEVERITY: critical_, + VProps.VITRAGE_OPERATIONAL_SEVERITY: + OperationalAlarmSeverity.CRITICAL, VProps.RESOURCE: {VProps.VITRAGE_IS_PLACEHOLDER: false_, VProps.VITRAGE_IS_DELETED: false_}} diff --git a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_notifier.py b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_notifier.py index dda0962f4..f4ec8a5ab 100644 --- a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_notifier.py +++ b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_notifier.py @@ -11,7 +11,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from vitrage.entity_graph.mappings.operational_alarm_severity import \ + OperationalAlarmSeverity from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -31,7 +32,8 @@ class SnmpNotifierTest(base.BaseTest): VProps.NAME: common.name_, VProps.RESOURCE: cls.resource_props, VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, - VProps.VITRAGE_OPERATIONAL_SEVERITY: common.critical_} + VProps.VITRAGE_OPERATIONAL_SEVERITY: + OperationalAlarmSeverity.CRITICAL} cls.alarm_vertex = Vertex('RESOURCE:nova.instance:test1', cls.props) def test_parse_alarm(self): @@ -45,7 +47,7 @@ class SnmpNotifierTest(base.BaseTest): self.assertEqual(alarm_data.get(VProps.VITRAGE_CATEGORY), EntityCategory.ALARM) self.assertEqual(alarm_data.get(VProps.VITRAGE_OPERATIONAL_SEVERITY), - common.critical_) + OperationalAlarmSeverity.CRITICAL) self.assertEqual(alarm_data.get(VProps.RESOURCE + '_' + VProps.VITRAGE_IS_DELETED), diff --git a/vitrage_tempest_tests/tests/api/base.py b/vitrage_tempest_tests/tests/api/base.py index c3e47933a..133c3c47c 100644 --- a/vitrage_tempest_tests/tests/api/base.py +++ b/vitrage_tempest_tests/tests/api/base.py @@ -17,6 +17,7 @@ import time from oslo_log import log as logging from oslotest import base +from vitrage.common.constants import EdgeProperties from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.aodh import AODH_DATASOURCE @@ -206,7 +207,7 @@ class BaseApiTest(base.BaseTestCase): for i in range(len(edges)): graph.add_edge(Edge(str(edges[i]['source']), str(edges[i]['target']), - edges[i]['relationship_type'])) + edges[i][EdgeProperties.RELATIONSHIP_TYPE])) return graph diff --git a/vitrage_tempest_tests/tests/api/rca/base.py b/vitrage_tempest_tests/tests/api/rca/base.py index 96c562854..0a6dcdf29 100644 --- a/vitrage_tempest_tests/tests/api/rca/base.py +++ b/vitrage_tempest_tests/tests/api/rca/base.py @@ -16,6 +16,8 @@ import json from oslo_log import log as logging +from vitrage.common.constants import EdgeLabel +from vitrage.common.constants import EdgeProperties from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.aodh import AODH_DATASOURCE from vitrage.datasources import NOVA_HOST_DATASOURCE @@ -118,8 +120,8 @@ class BaseRcaTest(BaseAlarmsTest): alarms[item['source']], VProps.NAME) target_alarm_name = self._get_value( alarms[item['target']], VProps.NAME) - if self._get_value(item, 'key') != 'causes' \ - or self._get_value(item, 'relationship_type') != 'causes' \ + if self._get_value(item, 'key') != EdgeLabel.CAUSES \ + or self._get_value(item, EdgeProperties.RELATIONSHIP_TYPE) != EdgeLabel.CAUSES \ or source_alarm_name != RCA_ALARM_NAME \ or target_alarm_name != VITRAGE_ALARM_NAME: flag = False diff --git a/vitrage_tempest_tests/tests/api/resources/test_resources.py b/vitrage_tempest_tests/tests/api/resources/test_resources.py index 52f89336b..8034c3981 100644 --- a/vitrage_tempest_tests/tests/api/resources/test_resources.py +++ b/vitrage_tempest_tests/tests/api/resources/test_resources.py @@ -143,9 +143,10 @@ class TestResource(BaseApiTest): self.assertNotEqual(len(resource_list), 0) for resource in resource_list: api_resource_show = \ - self.vitrage_client.resource.show(resource['vitrage_id']) + self.vitrage_client.resource.show(resource[VProps.VITRAGE_ID]) cli_resource_show = utils.run_vitrage_command( - 'vitrage resource show ' + resource['vitrage_id'], self.conf) + 'vitrage resource show ' + resource[VProps.VITRAGE_ID], + self.conf) self._compare_resource_show( api_resource_show, cli_resource_show) diff --git a/vitrage_tempest_tests/tests/base_mock.py b/vitrage_tempest_tests/tests/base_mock.py index 14a6a756a..270539b2f 100644 --- a/vitrage_tempest_tests/tests/base_mock.py +++ b/vitrage_tempest_tests/tests/base_mock.py @@ -17,6 +17,8 @@ import testtools from oslo_config import cfg +from vitrage.common.constants import DatasourceAction +from vitrage.common.constants import DatasourceProperties from vitrage.entity_graph.initialization_status import InitializationStatus from vitrage.entity_graph.processor import processor as proc from vitrage.tests.mocks import mock_driver as mock_sync @@ -46,11 +48,14 @@ class BaseMock(testtools.TestCase): def _create_mock_events(): gen_list = mock_sync.simple_zone_generators( 2, 4, snapshot_events=2, - snap_vals={'vitrage_datasource_action': 'init_snapshot'}) + snap_vals={DatasourceProperties.DATASOURCE_ACTION: + DatasourceAction.INIT_SNAPSHOT}) gen_list += mock_sync.simple_host_generators( 2, 4, 4, - snap_vals={'vitrage_datasource_action': 'init_snapshot'}) + snap_vals={DatasourceProperties.DATASOURCE_ACTION: + DatasourceAction.INIT_SNAPSHOT}) gen_list += mock_sync.simple_instance_generators( 4, 15, 15, - snap_vals={'vitrage_datasource_action': 'init_snapshot'}) + snap_vals={DatasourceProperties.DATASOURCE_ACTION: + DatasourceAction.INIT_SNAPSHOT}) return mock_sync.generate_sequential_events_list(gen_list)