]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Added provider_id to volume and snapshot object
authoryogeshprasad <yogesh.prasad@cloudbyte.com>
Mon, 9 Mar 2015 11:45:17 +0000 (17:15 +0530)
committeryogeshprasad <yogesh.prasad@cloudbyte.com>
Fri, 13 Mar 2015 15:54:29 +0000 (21:24 +0530)
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
cinder/objects/volume.py
cinder/tests/objects/test_snapshot.py
cinder/tests/test_volume.py

index 06accd75817e9889f2de0d57b9a26c9d39d940d0..36dd2e8a76c36b6a6422bb5faa4b21e744473e74 100644 (file)
@@ -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),
index 6ba556b3a2f5f87c87c2bbaccd9fbbf8c5004a50..7971106ac5369ba26f3983992b02c9828113f3f0 100644 (file)
@@ -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),
index f5bf7f7c92fb498473be1e13a731422be9d986d4..5e6fd2fbb8d7f0504c5f478152ef75f78ff39df2 100644 (file)
@@ -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(
index 18d5968a6f66c629940aac7bdba775ffa72e8c96..989b1ae85abc8d2ac11a49f31d7ca184ab2cbc40 100644 (file)
@@ -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)