]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixes create rbd volume from image v1 glance api
authorEdward Hope-Morley <edward.hope-morley@canonical.com>
Mon, 5 Aug 2013 21:57:09 +0000 (22:57 +0100)
committerEdward Hope-Morley <edward.hope-morley@canonical.com>
Tue, 6 Aug 2013 08:27:26 +0000 (09:27 +0100)
The RBD driver supports two methods of image cloning;
thin copy i.e. copy-on-write (requires v2 Glance API)
and full copy (default if v2 Glance API is not available).

clone_image() was failing in the Glance V1 API case because
it was not returning a tuple, as expected by the volume
manager. Glance V2 support works fine.

Fixes: bug #1208617
Change-Id: I2e8605eaacfe8b65bdf47cb6ea40ef62d6f6b895

cinder/tests/test_rbd.py
cinder/volume/drivers/rbd.py

index 32e44801d703a48c830e62b7e82ff7ff4294daf2..f9a6986b27e0917160789c065a9c3ae6c3becd7d 100644 (file)
@@ -515,24 +515,40 @@ class ManagedRBDTestCase(DriverTestCase):
             # cleanup
             db.volume_destroy(self.context, volume_id)
 
-    def test_clone_image_status_available(self):
+    def test_create_vol_from_image_status_available(self):
         """Verify that before cloning, an image is in the available state."""
         self._clone_volume_from_image('available', True)
 
-    def test_clone_image_status_error(self):
+    def test_create_vol_from_image_status_error(self):
         """Verify that before cloning, an image is in the available state."""
         self._clone_volume_from_image('error', False)
 
+    def test_clone_image(self):
+        # Test Failure Case(s)
+        expected = ({}, False)
+
+        self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: False)
+        self.assertEquals(expected,
+                          self.volume.driver.clone_image(object(), object()))
+
+        self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
+        self.assertEquals(expected,
+                          self.volume.driver.clone_image(object(), None))
+
+        # Test Success Case(s)
+        expected = ({'provider_location': None}, True)
+
+        self.stubs.Set(self.volume.driver, '_parse_location',
+                       lambda x: ('a', 'b', 'c', 'd'))
+
+        self.stubs.Set(self.volume.driver, '_clone', lambda *args: None)
+        self.stubs.Set(self.volume.driver, '_resize', lambda *args: None)
+
+        self.assertEquals(expected,
+                          self.volume.driver.clone_image(object(), object()))
+
     def test_clone_success(self):
         self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
         self.stubs.Set(self.volume.driver, 'clone_image', lambda a, b: True)
         image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
         self.assertTrue(self.volume.driver.clone_image({}, image_id))
-
-    def test_clone_bad_image_id(self):
-        self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
-        self.assertFalse(self.volume.driver.clone_image({}, None))
-
-    def test_clone_uncloneable(self):
-        self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: False)
-        self.assertFalse(self.volume.driver.clone_image({}, 'dne'))
index 75e804737807d70d430e64cfd45508683e5b5215..91c132f1fbfef32c02d3e473579c0941ebb1f7de 100644 (file)
@@ -521,8 +521,8 @@ class RBDDriver(driver.VolumeDriver):
 
     def clone_image(self, volume, image_location):
         if image_location is None or not self._is_cloneable(image_location):
-            return False
-        _, pool, image, snapshot = self._parse_location(image_location)
+            return ({}, False)
+        prefix, pool, image, snapshot = self._parse_location(image_location)
         self._clone(volume, pool, image, snapshot)
         self._resize(volume)
         return {'provider_location': None}, True