]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add necessary fields to volume creation
authorlisali <xiaoyan.li@intel.com>
Thu, 25 Feb 2016 08:59:42 +0000 (08:59 +0000)
committerMichał Dulko <michal.dulko@intel.com>
Mon, 29 Feb 2016 14:14:23 +0000 (15:14 +0100)
This patch is to add the two fields in driver.py when creating
volumes.

Without the fix, it leads query related to the volume failed
with exception.

Change-Id: I0055b5bf402b0aa7b4ee78b0fb40bedea850af94
Closes-Bug: #1549673
Related-Bug: #1549669

cinder/tests/unit/test_volume.py
cinder/volume/driver.py

index 6cf65569bc5a2c18564cf5110579af8ab0e271e5..d11f28c66fde07e8221affece0f7619fbe401831 100644 (file)
@@ -6516,6 +6516,23 @@ class GenericVolumeDriverTestCase(DriverTestCase):
             backup_obj = objects.Backup.get_by_id(self.context, backup.id)
             self.assertEqual(temp_vol.id, backup_obj.temp_volume_id)
 
+    def test__create_temp_volume_from_snapshot(self):
+        volume_dict = {'id': 'fake',
+                       'host': 'fakehost',
+                       'availability_zone': 'fakezone',
+                       'size': 1}
+        vol = fake_volume.fake_volume_obj(self.context, **volume_dict)
+        snapshot = fake_snapshot.fake_snapshot_obj(self.context)
+
+        with mock.patch.object(
+                self.volume.driver,
+                'create_volume_from_snapshot'):
+            temp_vol = self.volume.driver._create_temp_volume_from_snapshot(
+                self.context,
+                vol, snapshot)
+            self.assertEqual('detached', temp_vol['attach_status'])
+            self.assertEqual('fakezone', temp_vol['availability_zone'])
+
     @mock.patch.object(utils, 'brick_get_connector_properties')
     @mock.patch.object(cinder.volume.driver.VolumeDriver, '_attach_volume')
     @mock.patch.object(cinder.volume.driver.VolumeDriver, '_detach_volume')
index 610663a72c97c888fd54f361249531b800faedc6..4a001c50a55e90b9ebb07e6940f1f20fdc3ffc1b 100644 (file)
@@ -1423,6 +1423,8 @@ class BaseVD(object):
             'user_id': context.user_id,
             'project_id': context.project_id,
             'status': 'creating',
+            'attach_status': 'detached',
+            'availability_zone': volume.availability_zone,
         }
         temp_vol_ref = self.db.volume_create(context, temp_volume)
         try: