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_create_host_neighbor(self): LOG.debug('Test create host neighbor') # Test setup vertex_id = 'RESOURCE:nova.instance:456' host_name = 'host123' time = datetime.datetime.utcnow() # Test action instance_transformer = InstanceTransformer(self.transformers) neighbor = instance_transformer._create_host_neighbor( vertex_id, host_name, time, self.transformers[NOVA_HOST_DATASOURCE] ) # Test assertions host_vertex_id = 'RESOURCE:nova.host:host123' self.assertEqual(host_vertex_id, neighbor.vertex.vertex_id) self.assertEqual( time, neighbor.vertex.get(VertexProperties.SAMPLE_TIMESTAMP) ) # test relation edge self.assertEqual(host_vertex_id, neighbor.edge.source_id) self.assertEqual(vertex_id, neighbor.edge.target_id) self.assertEqual(EdgeLabels.CONTAINS, neighbor.edge.label)
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_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_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 setUpClass(cls): super(KubernetesTransformerTest, cls).setUpClass() cls.transformers = {} cls.transformers[KUBERNETES_DATASOURCE] = KubernetesTransformer( cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers)
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 setUpClass(cls): cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=NOVA_INSTANCE_DATASOURCE) cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( cls.transformers, cls.conf) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers, cls.conf)
def setUpClass(cls): cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=CINDER_VOLUME_DATASOURCE) cls.transformers[CINDER_VOLUME_DATASOURCE] = \ CinderVolumeTransformer(cls.transformers, cls.conf) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers, cls.conf)
def setUpClass(cls): super(KubernetesTransformerTest, cls).setUpClass() cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=KUBERNETES_DATASOURCE) cls.transformers[KUBERNETES_DATASOURCE] = KubernetesTransformer( cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers)
def setUp(self): super(PrometheusTransformerTest, self).setUp() self.transformers = {} self.conf_reregister_opts(self.OPTS, group=PROMETHEUS_DATASOURCE) self.transformers[NOVA_HOST_DATASOURCE] = \ HostTransformer(self.transformers) self.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(self.transformers) self.transformers[PROMETHEUS_DATASOURCE] = \ PrometheusTransformer(self.transformers)
def setUpClass(cls): super(BaseNovaInstanceTransformerTest, cls).setUpClass() cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=NOVA_INSTANCE_DATASOURCE) cls.conf.register_opts(cls._get_default_group_opts()) cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers)
def setUpClass(cls): super(TestKapacitorTransformer, cls).setUpClass() cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=KAPACITOR_DATASOURCE) cls.transformers[KAPACITOR_DATASOURCE] = \ KapacitorTransformer(cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers) cls.transformers[NOVA_HOST_DATASOURCE] = \ HostTransformer(cls.transformers)
def setUpClass(cls): super(TestHeatStackTransformer, cls).setUpClass() cls.transformers = {} cls.conf = cfg.ConfigOpts() cls.conf.register_opts(cls.OPTS, group=HEAT_STACK_DATASOURCE) cls.transformers[HEAT_STACK_DATASOURCE] = \ HeatStackTransformer(cls.transformers) cls.transformers[CINDER_VOLUME_DATASOURCE] = \ CinderVolumeTransformer(cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers)
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_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)
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_create_host_neighbor(self): LOG.debug('Test create host neighbor') # Test setup vertex_id = 'RESOURCE:nova.instance:456' host_name = 'host123' time = datetime.datetime.utcnow() # Test action instance_transformer = InstanceTransformer(self.transformers) neighbor = instance_transformer._create_host_neighbor( vertex_id, host_name, time, self.transformers[NOVA_HOST_DATASOURCE]) # Test assertions host_vertex_id = 'RESOURCE:nova.host:host123' self.assertEqual(host_vertex_id, neighbor.vertex.vertex_id) self.assertEqual( time, neighbor.vertex.get(VertexProperties.SAMPLE_TIMESTAMP)) # test relation edge self.assertEqual(host_vertex_id, neighbor.edge.source_id) self.assertEqual(vertex_id, neighbor.edge.target_id) self.assertEqual(EdgeLabel.CONTAINS, neighbor.edge.label)
def setUpClass(cls): cls.transformers = {} cls.transformers[NOVA_HOST_DATASOURCE] = HostTransformer( cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers)
def setUpClass(cls): cls.transformers = {} cls.transformers[CINDER_VOLUME_DATASOURCE] = \ CinderVolumeTransformer(cls.transformers) cls.transformers[NOVA_INSTANCE_DATASOURCE] = \ InstanceTransformer(cls.transformers)