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_build_instance_key(self): LOG.debug('Test build instance key') # Test setup instance_id = '456' expected_key = 'RESOURCE:nova.instance:%s' % instance_id instance_transformer = InstanceTransformer(self.transformers) # Test action key_fields = instance_transformer._key_values(NOVA_INSTANCE_DATASOURCE, instance_id) # Test assertions observed_key = tbase.build_key(key_fields) self.assertEqual(expected_key, observed_key)
def test_build_instance_key(self): LOG.debug('Test build instance key') # Test setup instance_id = '456' expected_key = 'RESOURCE:nova.instance:%s' % instance_id instance_transformer = InstanceTransformer(self.transformers) # Test action key_fields = instance_transformer._key_values( NOVA_INSTANCE_DATASOURCE, instance_id) # Test assertions observed_key = tbase.build_key(key_fields) self.assertEqual(expected_key, observed_key)
def test_create_placeholder_vertex(self): LOG.debug('Test create placeholder vertex') # Tests setup instance_id = 'Instance123' timestamp = datetime.datetime.utcnow() properties = { VertexProperties.ID: instance_id, VertexProperties.TYPE: NOVA_INSTANCE_DATASOURCE, VertexProperties.SAMPLE_TIMESTAMP: timestamp } transformer = InstanceTransformer(self.transformers) # Test action placeholder = transformer.create_placeholder_vertex(**properties) # Test assertions observed_id_values = placeholder.vertex_id.split( TransformerBase.KEY_SEPARATOR) expected_id_values = transformer._key_values(NOVA_INSTANCE_DATASOURCE, instance_id) self.assertEqual(tuple(observed_id_values), expected_id_values) observed_time = placeholder.get(VertexProperties.SAMPLE_TIMESTAMP) self.assertEqual(observed_time, timestamp) observed_type = placeholder.get(VertexProperties.TYPE) self.assertEqual(observed_type, NOVA_INSTANCE_DATASOURCE) observed_entity_id = placeholder.get(VertexProperties.ID) self.assertEqual(observed_entity_id, instance_id) observed_category = placeholder.get(VertexProperties.CATEGORY) self.assertEqual(observed_category, EntityCategory.RESOURCE) is_placeholder = placeholder.get(VertexProperties.IS_PLACEHOLDER) self.assertEqual(is_placeholder, True)
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)