示例#1
0
 def _create_entity_key(self, entity_event):
     network_id = 'network_id' if tbase.is_update_event(entity_event) \
         else 'id'
     key_fields = self._key_values(NEUTRON_NETWORK_DATASOURCE,
                                   extract_field_value(entity_event,
                                                       network_id))
     return tbase.build_key(key_fields)
示例#2
0
    def _create_entity_key(self, event):

        instance_id = 'instance_id' if tbase.is_update_event(event) else 'id'
        key_fields = self._key_values(NOVA_INSTANCE_DATASOURCE,
                                      extract_field_value(event,
                                                          instance_id))
        return tbase.build_key(key_fields)
示例#3
0
    def _validate_volume_vertex_props(self, vertex, event):

        is_update_event = tbase.is_update_event(event)

        self.assertEqual(EntityCategory.RESOURCE,
                         vertex[VProps.VITRAGE_CATEGORY])
        self.assertEqual(event[DSProps.ENTITY_TYPE],
                         vertex[VProps.VITRAGE_TYPE])

        id_field_path = 'volume_id' if is_update_event else 'id'
        self.assertEqual(tbase.extract_field_value(event, id_field_path),
                         vertex[VProps.ID])

        self.assertEqual(event[DSProps.SAMPLE_DATE],
                         vertex[VProps.VITRAGE_SAMPLE_TIMESTAMP])

        name_field_path = 'display_name'
        self.assertEqual(tbase.extract_field_value(event, name_field_path),
                         vertex[VProps.NAME])

        state_field_path = 'status'
        self.assertEqual(tbase.extract_field_value(event, state_field_path),
                         vertex[VProps.STATE])

        size_field_path = 'size'
        self.assertEqual(tbase.extract_field_value(event, size_field_path),
                         vertex[CinderProps.SIZE])

        volume_type_field_path = 'volume_type'
        self.assertEqual(
            tbase.extract_field_value(event, volume_type_field_path),
            vertex[CinderProps.VOLUME_TYPE])

        self.assertFalse(vertex[VProps.VITRAGE_IS_PLACEHOLDER])
        self.assertFalse(vertex[VProps.VITRAGE_IS_DELETED])
示例#4
0
    def _create_entity_key(self, event):

        instance_id = 'instance_id' if tbase.is_update_event(event) else 'id'
        key_fields = self._key_values(NOVA_INSTANCE_DATASOURCE,
                                      extract_field_value(event,
                                                          instance_id))
        return tbase.build_key(key_fields)
    def _validate_volume_vertex_props(self, vertex, event):

        is_update_event = tbase.is_update_event(event)

        self.assertEqual(EntityCategory.RESOURCE, vertex[VProps.CATEGORY])
        self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])

        id_field_path = 'volume_id' if is_update_event else 'id'
        self.assertEqual(
            tbase.extract_field_value(event, id_field_path),
            vertex[VProps.ID])

        self.assertEqual(event[DSProps.SAMPLE_DATE],
                         vertex[VProps.SAMPLE_TIMESTAMP])

        name_field_path = 'display_name'
        self.assertEqual(
            tbase.extract_field_value(event, name_field_path),
            vertex[VProps.NAME])

        state_field_path = 'status'
        self.assertEqual(
            tbase.extract_field_value(event, state_field_path),
            vertex[VProps.STATE])

        self.assertFalse(vertex[VProps.IS_PLACEHOLDER])
        self.assertFalse(vertex[VProps.IS_DELETED])
示例#6
0
 def _create_entity_key(self, entity_event):
     network_id = 'network_id' if tbase.is_update_event(entity_event) \
         else 'id'
     key_fields = self._key_values(
         NEUTRON_NETWORK_DATASOURCE,
         extract_field_value(entity_event, network_id))
     return tbase.build_key(key_fields)
示例#7
0
    def _validate_host_neighbor(self, h_neighbor, event):

        it = self.transformers[NOVA_INSTANCE_DATASOURCE]

        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 = {
            VProps.ID: host_name,
            VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE,
            VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE,
            VProps.VITRAGE_SAMPLE_TIMESTAMP: time
        }
        expected_neighbor = \
            ht.create_neighbor_placeholder_vertex(**properties)
        self.assertEqual(expected_neighbor, h_neighbor.vertex)

        # Validate neighbor edge
        edge = h_neighbor.edge
        entity_key = it._create_entity_key(event)
        entity_uuid = \
            TransformerBase.uuid_from_deprecated_vitrage_id(entity_key)
        self.assertEqual(edge.source_id, h_neighbor.vertex.vertex_id)
        self.assertEqual(edge.target_id, entity_uuid)
        self.assertEqual(edge.label, EdgeLabel.CONTAINS)
示例#8
0
    def _create_entity_key(self, entity_event):

        is_update_event = tbase.is_update_event(entity_event)
        id_field_path = 'volume_id' if is_update_event else 'id'
        volume_id = extract_field_value(entity_event, id_field_path)

        key_fields = self._key_values(CINDER_VOLUME_DATASOURCE, volume_id)
        return build_key(key_fields)
示例#9
0
    def _create_entity_key(self, entity_event):

        is_update_event = tbase.is_update_event(entity_event)
        id_field_path = 'volume_id' if is_update_event else 'id'
        volume_id = extract_field_value(entity_event, id_field_path)

        key_fields = self._key_values(CINDER_VOLUME_DATASOURCE, volume_id)
        return build_key(key_fields)
示例#10
0
    def _create_entity_key(self, entity_event):

        is_update_event = tbase.is_update_event(entity_event)
        id_field_path = 'stack_identity' if is_update_event else 'id'
        volume_id = extract_field_value(entity_event, id_field_path)

        key_fields = self._key_values(HEAT_STACK_DATASOURCE, volume_id)
        return build_key(key_fields)
示例#11
0
    def _create_entity_key(self, entity_event):

        is_update_event = tbase.is_update_event(entity_event)
        id_field_path = 'stack_identity' if is_update_event else 'id'
        volume_id = extract_field_value(entity_event, id_field_path)

        key_fields = self._key_values(HEAT_STACK_DATASOURCE, volume_id)
        return build_key(key_fields)
示例#12
0
 def _get_field_extractor(self, event):
     """Return an object that extracts the field values from the event"""
     if tbase.is_update_event(event):
         return self.versioned_notifications_extractor if \
             CONF.use_nova_versioned_notifications is True else \
             self.legacy_notifications_extractor
     else:
         return self.snapshot_extractor
示例#13
0
    def _create_entity_key(self, entity_event):

        is_update_event = tbase.is_update_event(entity_event)
        id_field_path = StackProps.STACK_IDENTITY\
            if is_update_event else StackProps.ID
        volume_id = extract_field_value(entity_event, id_field_path)

        key_fields = self._key_values(HEAT_STACK_DATASOURCE, volume_id)
        return build_key(key_fields)
示例#14
0
    def _create_neighbors(self, entity_event):
        if tbase.is_update_event(entity_event):
            attachments_property = 'volume_attachment'
            instance_id_property = 'instance_uuid'
        else:
            attachments_property = 'attachments'
            instance_id_property = 'server_id'

        return self._create_instance_neighbors(entity_event,
                                               attachments_property,
                                               instance_id_property)
示例#15
0
    def _create_neighbors(self, entity_event):
        if tbase.is_update_event(entity_event):
            attachments_property = 'volume_attachment'
            instance_id_property = 'instance_uuid'
        else:
            attachments_property = 'attachments'
            instance_id_property = 'server_id'

        return self._create_instance_neighbors(entity_event,
                                               attachments_property,
                                               instance_id_property)
示例#16
0
    def _create_neighbors(self, entity_event):
        if tbase.is_update_event(entity_event):
            device_owner_property = 'device_owner'
            device_id_property = 'server_uuid'
            net_id_property = 'network_id'
        else:
            device_owner_property = 'device_owner'
            device_id_property = 'device_id'
            net_id_property = 'network_id'

        return self._create_port_neighbors(entity_event, device_owner_property,
                                           device_id_property, net_id_property)
示例#17
0
    def _validate_neighbors(self, neighbors, volume_vertex_id, event):
        instance_counter = 0

        for neighbor in neighbors:
            is_update_event = tbase.is_update_event(event)
            instance_id = event['volume_attachment'][0]['instance_uuid'] if \
                is_update_event else event['attachments'][0]['server_id']
            self._validate_instance_neighbor(neighbor, instance_id,
                                             volume_vertex_id)
            instance_counter += 1

        self.assertEqual(1, instance_counter,
                         'Volume can be belonged to only one instance')
示例#18
0
    def _create_neighbors(self, entity_event):
        if tbase.is_update_event(entity_event):
            device_owner_property = 'device_owner'
            device_id_property = 'server_uuid'
            net_id_property = 'network_id'
        else:
            device_owner_property = 'device_owner'
            device_id_property = 'device_id'
            net_id_property = 'network_id'

        return self._create_port_neighbors(entity_event,
                                           device_owner_property,
                                           device_id_property,
                                           net_id_property)
    def _validate_neighbors(self, neighbors, volume_vertex_id, event):
        instance_counter = 0

        for neighbor in neighbors:
            is_update_event = tbase.is_update_event(event)
            instance_id = event['volume_attachment'][0]['instance_uuid'] if \
                is_update_event else event['attachments'][0]['server_id']
            self._validate_instance_neighbor(neighbor,
                                             instance_id,
                                             volume_vertex_id)
            instance_counter += 1

        self.assertEqual(1,
                         instance_counter,
                         'Volume can be belonged to only one instance')
示例#20
0
    def _create_nova_instance_neighbors(self, entity_event):
        neighbors = []
        host_transformer = self.transformers[NOVA_HOST_DATASOURCE]

        host_name = 'host' if tbase.is_update_event(entity_event) \
            else 'OS-EXT-SRV-ATTR:host'

        if host_transformer:
            host_neighbor = self._create_host_neighbor(
                self._create_entity_key(entity_event),
                extract_field_value(entity_event, host_name),
                entity_event[DSProps.SAMPLE_DATE], host_transformer)
            neighbors.append(host_neighbor)
        else:
            LOG.warning('Cannot find host transformer')

        return neighbors
示例#21
0
    def _create_nova_instance_neighbors(self, entity_event):
        neighbors = []
        host_transformer = self.transformers[NOVA_HOST_DATASOURCE]

        host_name = 'host' if tbase.is_update_event(entity_event) \
            else 'OS-EXT-SRV-ATTR:host'

        if host_transformer:
            host_neighbor = self._create_host_neighbor(
                self._create_entity_key(entity_event),
                extract_field_value(entity_event, host_name),
                entity_event[DSProps.SAMPLE_DATE],
                host_transformer)
            neighbors.append(host_neighbor)
        else:
            LOG.warning('Cannot find host transformer')

        return neighbors
示例#22
0
    def _validate_vertex_props(self, vertex, event):

        self.assertEqual(13, len(vertex.properties))

        is_update_event = tbase.is_update_event(event)

        extract_value = tbase.extract_field_value

        instance_id = 'instance_id' if is_update_event else 'id'
        expected_id = extract_value(event, instance_id)
        observed_id = vertex[VProps.ID]
        self.assertEqual(expected_id, observed_id)

        self.assertEqual(
            EntityCategory.RESOURCE,
            vertex[VProps.VITRAGE_CATEGORY]
        )
        self.assertEqual(NOVA_INSTANCE_DATASOURCE,
                         vertex[VProps.VITRAGE_TYPE])

        expected_project = extract_value(event, 'tenant_id')
        observed_project = vertex[VProps.PROJECT_ID]
        self.assertEqual(expected_project, observed_project)

        state = 'state' if is_update_event else 'status'
        expected_state = extract_value(event, state)
        observed_state = vertex[VProps.STATE]
        self.assertEqual(expected_state, observed_state)

        expected_timestamp = event[DSProps.SAMPLE_DATE]
        observed_timestamp = vertex[VProps.VITRAGE_SAMPLE_TIMESTAMP]
        self.assertEqual(expected_timestamp, observed_timestamp)

        name = 'hostname' if is_update_event else 'name'
        expected_name = extract_value(event, name)
        observed_name = vertex[VProps.NAME]
        self.assertEqual(expected_name, observed_name)

        vitrage_is_placeholder = vertex[VProps.VITRAGE_IS_PLACEHOLDER]
        self.assertFalse(vitrage_is_placeholder)

        vitrage_is_deleted = vertex[VProps.VITRAGE_IS_DELETED]
        self.assertFalse(vitrage_is_deleted)
    def _validate_vertex_props(self, vertex, event):

        self.assertEqual(11, len(vertex.properties))

        is_update_event = tbase.is_update_event(event)

        extract_value = tbase.extract_field_value

        instance_id = 'instance_id' if is_update_event else 'id'
        expected_id = extract_value(event, instance_id)
        observed_id = vertex[VertexProperties.ID]
        self.assertEqual(expected_id, observed_id)

        self.assertEqual(
            EntityCategory.RESOURCE,
            vertex[VertexProperties.CATEGORY]
        )
        self.assertEqual(NOVA_INSTANCE_DATASOURCE,
                         vertex[VertexProperties.TYPE])

        expected_project = extract_value(event, 'tenant_id')
        observed_project = vertex[VertexProperties.PROJECT_ID]
        self.assertEqual(expected_project, observed_project)

        state = 'state' if is_update_event else 'status'
        expected_state = extract_value(event, state)
        observed_state = vertex[VertexProperties.STATE]
        self.assertEqual(expected_state, observed_state)

        expected_timestamp = event[DSProps.SAMPLE_DATE]
        observed_timestamp = vertex[VertexProperties.SAMPLE_TIMESTAMP]
        self.assertEqual(expected_timestamp, observed_timestamp)

        name = 'hostname' if is_update_event else 'name'
        expected_name = extract_value(event, name)
        observed_name = vertex[VertexProperties.NAME]
        self.assertEqual(expected_name, observed_name)

        is_placeholder = vertex[VertexProperties.IS_PLACEHOLDER]
        self.assertFalse(is_placeholder)

        is_deleted = vertex[VertexProperties.IS_DELETED]
        self.assertFalse(is_deleted)
示例#24
0
    def _validate_host_neighbor(self, h_neighbor, event):

        it = self.transformers[NOVA_INSTANCE_DATASOURCE]

        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 = self.transformers[NOVA_INSTANCE_DATASOURCE]

        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)
示例#26
0
    def _validate_stack_vertex_props(self, vertex, event):

        is_update_event = tbase.is_update_event(event)

        self.assertEqual(EntityCategory.RESOURCE, vertex[VProps.CATEGORY])
        self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])

        id_field_path = 'stack_identity' if is_update_event else 'id'
        self.assertEqual(tbase.extract_field_value(event, id_field_path),
                         vertex[VProps.ID])

        self.assertEqual(event[DSProps.SAMPLE_DATE],
                         vertex[VProps.SAMPLE_TIMESTAMP])

        name_field_path = 'stack_name'
        self.assertEqual(tbase.extract_field_value(event, name_field_path),
                         vertex[VProps.NAME])

        state_field_path = 'state' if is_update_event else 'stack_status'
        self.assertEqual(tbase.extract_field_value(event, state_field_path),
                         vertex[VProps.STATE])

        self.assertFalse(vertex[VProps.IS_PLACEHOLDER])
        self.assertFalse(vertex[VProps.IS_DELETED])