From: ustcdylan <liujunwei@chinamobile.com>
Date: Sat, 6 Dec 2014 14:23:21 +0000 (+0800)
Subject: Fix bug in sheepdog driver: the wrong volume size
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=337342d0894df0661810b8f9b08d26611ad43962;p=openstack-build%2Fcinder-build.git

Fix bug in sheepdog driver: the wrong volume size

We give a volume size when create a volume from an snapshot,
but the sheepdog driver ignores the size.

Change-Id: I4310e7ef07e98c002ad3494e623ea243e3aad468
Closes-Bug: #1399598
---

diff --git a/cinder/tests/test_sheepdog.py b/cinder/tests/test_sheepdog.py
index ccedc27b2..97fb76804 100644
--- a/cinder/tests/test_sheepdog.py
+++ b/cinder/tests/test_sheepdog.py
@@ -17,6 +17,7 @@
 
 import contextlib
 
+import mock
 from oslo.utils import units
 from oslo_concurrency import processutils
 
@@ -139,3 +140,25 @@ class SheepdogTestCase(test.TestCase):
         self.driver.extend_volume(fake_vol, fake_size)
 
         self.mox.VerifyAll()
+
+    def test_create_volume_from_snapshot(self):
+        fake_name = u'volume-00000001'
+        fake_size = '10'
+        fake_vol = {'project_id': 'testprjid', 'name': fake_name,
+                    'size': fake_size,
+                    'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'}
+
+        ss_uuid = '00000000-0000-0000-0000-c3aa7ee01536'
+        fake_snapshot = {'volume_name': fake_name,
+                         'name': 'volume-%s' % ss_uuid,
+                         'id': ss_uuid,
+                         'size': fake_size}
+
+        with mock.patch.object(SheepdogDriver, '_try_execute') as mock_exe:
+            self.driver.create_volume_from_snapshot(fake_vol, fake_snapshot)
+            args = ['qemu-img', 'create', '-b',
+                    "sheepdog:%s:%s" % (fake_snapshot['volume_name'],
+                                        fake_snapshot['name']),
+                    "sheepdog:%s" % fake_vol['name'],
+                    "%sG" % fake_vol['size']]
+            mock_exe.assert_called_once_with(*args)
diff --git a/cinder/volume/drivers/sheepdog.py b/cinder/volume/drivers/sheepdog.py
index 026ee7f9e..3bafdbd3b 100644
--- a/cinder/volume/drivers/sheepdog.py
+++ b/cinder/volume/drivers/sheepdog.py
@@ -77,7 +77,8 @@ class SheepdogDriver(driver.VolumeDriver):
         self._try_execute('qemu-img', 'create', '-b',
                           "sheepdog:%s:%s" % (snapshot['volume_name'],
                                               snapshot['name']),
-                          "sheepdog:%s" % volume['name'])
+                          "sheepdog:%s" % volume['name'],
+                          '%sG' % volume['size'])
 
     def delete_volume(self, volume):
         """Delete a logical volume."""