def test_nagios_alarm_transform(self): LOG.debug('Nagios alarm transformer test: transform entity event') # Test setup spec_list = mock_sync.simple_nagios_alarm_generators(host_num=4, events_num=10) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) transformer = NagiosTransformer(self.transformers, self.conf) for alarm in nagios_alarms: cur_alarm_uuid = None if alarm.get(NagiosProperties.STATUS) == NagiosTestStatus.OK: alarm_key = transformer._create_entity_key(alarm) cur_alarm_uuid = \ TransformerBase.uuid_from_deprecated_vitrage_id( alarm_key) # Test action wrapper = transformer.transform(alarm) self._validate_vertex(wrapper.vertex, alarm) neighbors = wrapper.neighbors self.assertEqual(1, len(neighbors)) neighbor = neighbors[0] # Right now we are support only host as a resource if neighbor.vertex[VProps.VITRAGE_TYPE] == NOVA_HOST_DATASOURCE: self._validate_host_neighbor(neighbors[0], alarm, cur_alarm_uuid) self._validate_action(alarm, wrapper)
def _validate_host_neighbor(self, neighbor, event, cur_alarm_uuid=None): host_vertex = neighbor.vertex expected_key = tbase.build_key( (EntityCategory.RESOURCE, NOVA_HOST_DATASOURCE, event[NagiosProperties.RESOURCE_NAME])) expected_uuid = self.transformers[NOVA_HOST_DATASOURCE].\ uuid_from_deprecated_vitrage_id(expected_key) self.assertEqual(expected_uuid, host_vertex.vertex_id) self.assertEqual(expected_uuid, host_vertex.properties.get(VProps.VITRAGE_ID)) self.assertFalse(host_vertex[VProps.VITRAGE_IS_DELETED]) self.assertTrue(host_vertex[VProps.VITRAGE_IS_PLACEHOLDER]) self.assertEqual(EntityCategory.RESOURCE, host_vertex[VProps.VITRAGE_CATEGORY]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], host_vertex[VProps.ID]) self.assertEqual(NOVA_HOST_DATASOURCE, host_vertex[VProps.VITRAGE_TYPE]) edge = neighbor.edge self.assertEqual(EdgeLabel.ON, edge.label) alarm_key = NagiosTransformer(self.transformers, self.conf).\ _create_entity_key(event) alarm_uuid = cur_alarm_uuid if cur_alarm_uuid else\ TransformerBase.uuid_from_deprecated_vitrage_id(alarm_key) self.assertEqual(alarm_uuid, edge.source_id) self.assertEqual(host_vertex.vertex_id, edge.target_id)
def _validate_host_neighbor(self, neighbor, event): host_vertex = neighbor.vertex key_fields = host_vertex.vertex_id.split(TransformerBase.KEY_SEPARATOR) self.assertEqual(EntityCategory.RESOURCE, key_fields[0]) self.assertEqual(NOVA_HOST_DATASOURCE, key_fields[1]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], key_fields[2]) self.assertFalse(host_vertex[VProps.IS_DELETED]) self.assertTrue(host_vertex[VProps.IS_PLACEHOLDER]) self.assertEqual(EntityCategory.RESOURCE, host_vertex[VProps.CATEGORY]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], host_vertex[VProps.ID]) self.assertEqual(NOVA_HOST_DATASOURCE, host_vertex[VProps.TYPE]) edge = neighbor.edge self.assertEqual(EdgeLabel.ON, edge.label) alarm_key = NagiosTransformer(self.transformers, self.conf).\ _create_entity_key(event) self.assertEqual(alarm_key, edge.source_id) self.assertEqual(host_vertex.vertex_id, edge.target_id)
def test_extract_key(self): LOG.debug('Test get key from nova instance transformer') # Test setup spec_list = mock_sync.simple_nagios_alarm_generators(host_num=1, events_num=1) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) transformer = NagiosTransformer(self.transformers, self.conf) event = nagios_alarms[0] # Test action observed_key = transformer._create_entity_key(event) # Test assertions observed_key_fields = observed_key.split(TransformerBase.KEY_SEPARATOR) self.assertEqual(EntityCategory.ALARM, observed_key_fields[0]) self.assertEqual(event[DSProps.ENTITY_TYPE], observed_key_fields[1]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], observed_key_fields[2]) self.assertEqual(event[NagiosProperties.SERVICE], observed_key_fields[3])
def test_extract_key(self): LOG.debug('Test get key from nova instance transformer') # Test setup spec_list = mock_sync.simple_nagios_alarm_generators(host_num=1, events_num=1) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) transformer = NagiosTransformer(self.transformers) event = nagios_alarms[0] # Test action observed_key = transformer._create_entity_key(event) # Test assertions observed_key_fields = observed_key.split( TransformerBase.KEY_SEPARATOR) self.assertEqual(EntityCategory.ALARM, observed_key_fields[0]) self.assertEqual(event[DSProps.SYNC_TYPE], observed_key_fields[1]) self.assertEqual(event[NagiosProperties.RESOURCE_NAME], observed_key_fields[2]) self.assertEqual(event[NagiosProperties.SERVICE], observed_key_fields[3])
def test_nagios_alarm_transform(self): LOG.debug('Nagios alarm transformer test: transform entity event') # Test setup spec_list = mock_sync.simple_nagios_alarm_generators(host_num=4, events_num=10) nagios_alarms = mock_sync.generate_sequential_events_list(spec_list) for alarm in nagios_alarms: # Test action wrapper = NagiosTransformer(self.transformers).transform(alarm) self._validate_vertex(wrapper.vertex, alarm) neighbors = wrapper.neighbors self.assertEqual(1, len(neighbors)) neighbor = neighbors[0] # Right now we are support only host as a resource if neighbor.vertex[VProps.TYPE] == NOVA_HOST_DATASOURCE: self._validate_host_neighbor(neighbors[0], alarm) self._validate_action(alarm, wrapper)