From 0f11f016c56db89188051661ad9dce8f0ef920f7 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 5 Aug 2013 22:57:09 +0100 Subject: [PATCH] Fixes create rbd volume from image v1 glance api 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 | 36 ++++++++++++++++++++++++++---------- cinder/volume/drivers/rbd.py | 4 ++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cinder/tests/test_rbd.py b/cinder/tests/test_rbd.py index 32e44801d..f9a6986b2 100644 --- a/cinder/tests/test_rbd.py +++ b/cinder/tests/test_rbd.py @@ -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')) diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index 75e804737..91c132f1f 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -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 -- 2.45.2