diff --git a/cinder/tests/test_rbd.py b/cinder/tests/test_rbd.py index 32e44801d70..f9a6986b27e 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 75e80473780..91c132f1fbf 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