def _validate_host_neighbor(self, h_neighbor, event):

        it = InstanceTransformer(self.transformers)
        sync_mode = event['sync_mode']

        host_name = tbase.extract_field_value(event, it.HOST_NAME[sync_mode])
        time = tbase.extract_field_value(event, it.TIMESTAMP[sync_mode])

        ht = self.transformers['nova.host']
        expected_neighbor = ht.create_placeholder_vertex(host_name, time)
        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.extract_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.extract_key(event)

            # Test assertions
            observed_key_fields = observed_key.split(
                TransformerBase.KEY_SEPARATOR)

            self.assertEqual(EntityTypes.RESOURCE, observed_key_fields[0])
            self.assertEqual(
                InstanceTransformer.INSTANCE_TYPE,
                observed_key_fields[1]
            )

            instance_id = tbase.extract_field_value(
                event,
                instance_transformer.INSTANCE_ID[event['sync_mode']]
            )

            self.assertEqual(instance_id, observed_key_fields[2])

            key_values = instance_transformer._key_values([instance_id])
            expected_key = tbase.build_key(key_values)

            self.assertEqual(expected_key, observed_key)