From b49414adef235fb2de16a6727573b22ba96450d1 Mon Sep 17 00:00:00 2001 From: Dan Offek Date: Wed, 31 Aug 2016 15:48:18 +0000 Subject: [PATCH] Additional Volume info Change-Id: I796232982957c19774a54d3417f1475640a66960 --- .../datasources/cinder/volume/properties.py | 19 ++++++++++ .../datasources/cinder/volume/transformer.py | 35 +++++++++++++++++-- vitrage/entity_graph/processor/processor.py | 4 +++ .../driver_volume_snapshot_dynamic.json | 4 ++- .../driver/driver_volume_update_dynamic.json | 4 ++- .../cinder/test_cinder_volume_transformer.py | 12 +++++++ 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 vitrage/datasources/cinder/volume/properties.py diff --git a/vitrage/datasources/cinder/volume/properties.py b/vitrage/datasources/cinder/volume/properties.py new file mode 100644 index 000000000..56e66d802 --- /dev/null +++ b/vitrage/datasources/cinder/volume/properties.py @@ -0,0 +1,19 @@ +# Copyright 2016 - Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class CinderProperties(object): + SIZE = 'size' + VOLUME_TYPE = 'volume_type' + ATTACHMENTS = 'attachments' diff --git a/vitrage/datasources/cinder/volume/transformer.py b/vitrage/datasources/cinder/volume/transformer.py index ef29535d0..7e2eeb13f 100644 --- a/vitrage/datasources/cinder/volume/transformer.py +++ b/vitrage/datasources/cinder/volume/transformer.py @@ -20,6 +20,8 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import EventAction from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE +from vitrage.datasources.cinder.volume.properties import \ + CinderProperties as CinderProps from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE from vitrage.datasources.resource_transformer_base import \ ResourceTransformerBase @@ -52,13 +54,20 @@ class CinderVolumeTransformer(ResourceTransformerBase): volume_state = extract_field_value(entity_event, 'status') project_id = entity_event.get('os-vol-tenant-attr:tenant_id', None) timestamp = extract_field_value(entity_event, 'created_at') + size = extract_field_value(entity_event, 'size') + volume_type = extract_field_value(entity_event, 'volume_type') + attachments = extract_field_value(entity_event, 'attachments') return self._create_vertex(entity_event, volume_name, volume_id, volume_state, project_id, - timestamp) + timestamp, + size, + volume_type, + attachments, + 'server_id') def _create_update_entity_vertex(self, entity_event): @@ -67,13 +76,20 @@ class CinderVolumeTransformer(ResourceTransformerBase): volume_state = extract_field_value(entity_event, 'status') project_id = entity_event.get('tenant_id', None) timestamp = entity_event.get('updated_at', None) + size = extract_field_value(entity_event, 'size') + volume_type = extract_field_value(entity_event, 'volume_type') + attachments = extract_field_value(entity_event, 'volume_attachment') return self._create_vertex(entity_event, volume_name, volume_id, volume_state, project_id, - timestamp) + timestamp, + size, + volume_type, + attachments, + 'instance_uuid') def _create_vertex(self, entity_event, @@ -81,10 +97,23 @@ class CinderVolumeTransformer(ResourceTransformerBase): volume_id, volume_state, project_id, - update_timestamp): + update_timestamp, + volume_size, + volume_type, + attachments, + server_id_key): + + server_ids = [] + + for attachment in attachments: + server_ids.append((attachment[server_id_key])) + metadata = { VProps.NAME: volume_name, VProps.PROJECT_ID: project_id, + CinderProps.SIZE: volume_size, + CinderProps.VOLUME_TYPE: volume_type, + CinderProps.ATTACHMENTS: tuple(server_ids) } entity_key = self._create_entity_key(entity_event) diff --git a/vitrage/entity_graph/processor/processor.py b/vitrage/entity_graph/processor/processor.py index b8689dc1a..ac3daf36c 100644 --- a/vitrage/entity_graph/processor/processor.py +++ b/vitrage/entity_graph/processor/processor.py @@ -142,6 +142,8 @@ class Processor(processor.ProcessorBase): for neighbor in neighbors: # TODO(Alexey): maybe to check if the vertices exists + if entity_vertex is not None: + self.entity_graph.update_vertex(entity_vertex) self.entity_graph.update_edge(neighbor.edge) def delete_relationship(self, updated_vertex, neighbors): @@ -151,6 +153,8 @@ class Processor(processor.ProcessorBase): graph_edge = self.entity_graph.get_edge(neighbor.edge.source_id, neighbor.edge.target_id, neighbor.edge.label) + if updated_vertex is not None: + self.entity_graph.update_vertex(updated_vertex) if graph_edge: self.entity_graph.remove_edge(graph_edge) diff --git a/vitrage/tests/resources/mock_configurations/driver/driver_volume_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/driver/driver_volume_snapshot_dynamic.json index c06ca011d..a284ce572 100644 --- a/vitrage/tests/resources/mock_configurations/driver/driver_volume_snapshot_dynamic.json +++ b/vitrage/tests/resources/mock_configurations/driver/driver_volume_snapshot_dynamic.json @@ -6,5 +6,7 @@ "id": "12345", "sync_type": "cinder\\.volume", "sync_mode": "snapshot", - "sample_date": "2015-12-01T12:46:41Z" + "sample_date": "2015-12-01T12:46:41Z", + "volume_type": "lvmdriver-1", + "size": "1559" } diff --git a/vitrage/tests/resources/mock_configurations/driver/driver_volume_update_dynamic.json b/vitrage/tests/resources/mock_configurations/driver/driver_volume_update_dynamic.json index 88739bfa7..6f9138325 100644 --- a/vitrage/tests/resources/mock_configurations/driver/driver_volume_update_dynamic.json +++ b/vitrage/tests/resources/mock_configurations/driver/driver_volume_update_dynamic.json @@ -7,5 +7,7 @@ "sync_type": "cinder\\.volume", "sync_mode": "update", "event_type": "volume.create.start", - "sample_date": "2015-12-01T12:46:41Z" + "sample_date": "2015-12-01T12:46:41Z", + "volume_type": "SCSIID", + "size": "1559" } diff --git a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py index 1aa497004..2023f7c38 100644 --- a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py +++ b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py @@ -23,6 +23,8 @@ from vitrage.common.constants import EntityCategory from vitrage.common.constants import UpdateMethod from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE +from vitrage.datasources.cinder.volume.properties \ + import CinderProperties as CinderProps from vitrage.datasources.cinder.volume.transformer \ import CinderVolumeTransformer from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE @@ -180,6 +182,16 @@ class TestCinderVolumeTransformer(base.BaseTest): 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.IS_PLACEHOLDER]) self.assertFalse(vertex[VProps.IS_DELETED])