From c4d86761a22e2bf8b19975c5b22626488a69e031 Mon Sep 17 00:00:00 2001 From: yogeshprasad Date: Mon, 9 Mar 2015 17:15:17 +0530 Subject: [PATCH] Added provider_id to volume and snapshot object This feature helps cinder drivers to access provider information without resorting to DB access in their driver code. Closes-Bug: #1430145 Change-Id: I72bcbdafd1c2ec24fa4c52978c88b8518db2a1ec --- cinder/objects/snapshot.py | 1 + cinder/objects/volume.py | 1 + cinder/tests/objects/test_snapshot.py | 7 +++++++ cinder/tests/test_volume.py | 10 ++++++++++ 4 files changed, 19 insertions(+) diff --git a/cinder/objects/snapshot.py b/cinder/objects/snapshot.py index 06accd758..36dd2e8a7 100644 --- a/cinder/objects/snapshot.py +++ b/cinder/objects/snapshot.py @@ -56,6 +56,7 @@ class Snapshot(base.CinderPersistentObject, base.CinderObject, 'volume_type_id': fields.UUIDField(nullable=True), 'provider_location': fields.StringField(nullable=True), + 'provider_id': fields.UUIDField(nullable=True), 'metadata': fields.DictOfStringsField(), 'volume': fields.ObjectField('Volume', nullable=True), diff --git a/cinder/objects/volume.py b/cinder/objects/volume.py index 6ba556b3a..7971106ac 100644 --- a/cinder/objects/volume.py +++ b/cinder/objects/volume.py @@ -56,6 +56,7 @@ class Volume(base.CinderPersistentObject, base.CinderObject, 'display_name': fields.StringField(nullable=True), 'display_description': fields.StringField(nullable=True), + 'provider_id': fields.UUIDField(nullable=True), 'provider_location': fields.StringField(nullable=True), 'provider_auth': fields.StringField(nullable=True), 'provider_geometry': fields.StringField(nullable=True), diff --git a/cinder/tests/objects/test_snapshot.py b/cinder/tests/objects/test_snapshot.py index f5bf7f7c9..5e6fd2fbb 100644 --- a/cinder/tests/objects/test_snapshot.py +++ b/cinder/tests/objects/test_snapshot.py @@ -55,6 +55,13 @@ class TestSnapshot(test_objects._LocalTest): self.assertEqual(fake_snapshot['id'], snapshot.id) self.assertEqual(fake_snapshot['volume_id'], snapshot.volume_id) + @mock.patch('cinder.db.snapshot_create', + return_value=dict(provider_id='1111-aaaa', **fake_snapshot)) + def test_create_with_provider_id(self, snapshot_create): + snapshot = snapshot_obj.Snapshot(context=self.context) + snapshot.create() + self.assertEqual('1111-aaaa', snapshot.provider_id) + @mock.patch('cinder.db.snapshot_update') def test_save(self, snapshot_update): snapshot = snapshot_obj.Snapshot._from_db_object( diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 18d5968a6..989b1ae85 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -602,6 +602,16 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual(volume['volume_type_id'], db_vol_type.get('id')) self.assertIsNotNone(volume['encryption_key_id']) + def test_create_volume_with_provider_id(self): + volume_params_with_provider_id = dict(provider_id='1111-aaaa', + **self.volume_params) + + volume = tests_utils.create_volume(self.context, + **volume_params_with_provider_id) + + self.volume.create_volume(self.context, volume['id']) + self.assertEqual('1111-aaaa', volume['provider_id']) + def test_create_delete_volume_with_encrypted_volume_type(self): self.stubs.Set(keymgr, "API", fake_keymgr.fake_api) -- 2.45.2