def test_extract_key(self): LOG.debug('Test get key from nova instance transformer') # Test setup spec_list = mock_sync.simple_instance_generators(host_num=1, vm_num=1, snapshot_events=1, update_events=0) instance_events = mock_sync.generate_random_events_list(spec_list) instance_transformer = InstanceTransformer(self.transformers) for event in instance_events: # Test action observed_key = instance_transformer._create_entity_key(event) # Test assertions observed_key_fields = observed_key.split( TransformerBase.KEY_SEPARATOR) self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) self.assertEqual(NOVA_INSTANCE_DATASOURCE, observed_key_fields[1]) instance_id = tbase.extract_field_value(event, 'id') self.assertEqual(instance_id, observed_key_fields[2]) key_values = instance_transformer._key_values( NOVA_INSTANCE_DATASOURCE, instance_id) expected_key = tbase.build_key(key_values) self.assertEqual(expected_key, observed_key)
def test_state_on_update(self): # setup processor = proc.Processor(self.conf, InitializationStatus()) event = self._create_event(spec_type='INSTANCE_SPEC', sync_mode=SyncMode.INIT_SNAPSHOT) # action processor.process_event(event) # test assertions instance_transformer = InstanceTransformer({}) vitrage_id = instance_transformer._create_entity_key(event) vertex = processor.entity_graph.get_vertex(vitrage_id) self.assertEqual(NormalizedResourceState.RUNNING, vertex[VProps.AGGREGATED_STATE])
def test_state_on_update(self): # setup processor = proc.Processor(self.conf, InitializationStatus()) event = self._create_event(spec_type='INSTANCE_SPEC', sync_mode=SyncMode.INIT_SNAPSHOT) # action processor.process_event(event) # test assertions instance_transformer = InstanceTransformer({}) vitrage_id = instance_transformer._create_entity_key(event) vertex = processor.entity_graph.get_vertex(vitrage_id) self.assertEqual('ACTIVE', vertex[VProps.AGGREGATED_STATE]) self.assertEqual(OperationalResourceState.OK, vertex[VProps.OPERATIONAL_STATE])
def _validate_host_neighbor(self, h_neighbor, event): it = InstanceTransformer(self.transformers) name = 'host' if tbase.is_update_event(event) \ else 'OS-EXT-SRV-ATTR:host' host_name = tbase.extract_field_value(event, name) time = event[DSProps.SAMPLE_DATE] ht = self.transformers[NOVA_HOST_DATASOURCE] properties = { VertexProperties.ID: host_name, VertexProperties.TYPE: NOVA_HOST_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: time } expected_neighbor = ht.create_placeholder_vertex(**properties) self.assertEqual(expected_neighbor, h_neighbor.vertex) # Validate neighbor edge edge = h_neighbor.edge self.assertEqual(edge.source_id, h_neighbor.vertex.vertex_id) self.assertEqual(edge.target_id, it._create_entity_key(event)) self.assertEqual(edge.label, EdgeLabel.CONTAINS)
def _validate_host_neighbor(self, h_neighbor, event): it = InstanceTransformer(self.transformers) name = 'host' if tbase.is_update_event(event) \ else 'OS-EXT-SRV-ATTR:host' host_name = tbase.extract_field_value(event, name) time = event[DSProps.SAMPLE_DATE] ht = self.transformers[NOVA_HOST_DATASOURCE] properties = { VertexProperties.ID: host_name, VertexProperties.TYPE: NOVA_HOST_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: time } expected_neighbor = ht.create_placeholder_vertex(**properties) self.assertEqual(expected_neighbor, h_neighbor.vertex) # Validate neighbor edge edge = h_neighbor.edge self.assertEqual(edge.source_id, h_neighbor.vertex.vertex_id) self.assertEqual(edge.target_id, it._create_entity_key(event)) self.assertEqual(edge.label, EdgeLabels.CONTAINS)
def test_extract_key(self): LOG.debug('Test get key from nova instance transformer') # Test setup spec_list = mock_sync.simple_instance_generators( host_num=1, vm_num=1, snapshot_events=1, update_events=0 ) instance_events = mock_sync.generate_random_events_list(spec_list) instance_transformer = InstanceTransformer(self.transformers) for event in instance_events: # Test action observed_key = instance_transformer._create_entity_key(event) # Test assertions observed_key_fields = observed_key.split( TransformerBase.KEY_SEPARATOR) self.assertEqual(EntityCategory.RESOURCE, observed_key_fields[0]) self.assertEqual( NOVA_INSTANCE_DATASOURCE, observed_key_fields[1] ) instance_id = tbase.extract_field_value(event, 'id') self.assertEqual(instance_id, observed_key_fields[2]) key_values = instance_transformer._key_values( NOVA_INSTANCE_DATASOURCE, instance_id) expected_key = tbase.build_key(key_values) self.assertEqual(expected_key, observed_key)