Skip to content

Commit

Permalink
Fixes create rbd volume from image v1 glance api
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dosaboy committed Aug 6, 2013
1 parent 18e4ea2 commit 0f11f01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 26 additions & 10 deletions cinder/tests/test_rbd.py
Expand Up @@ -515,24 +515,40 @@ def fake_clone_error(volume, image_location):
# 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'))
4 changes: 2 additions & 2 deletions cinder/volume/drivers/rbd.py
Expand Up @@ -521,8 +521,8 @@ def _is_cloneable(self, image_location):

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
Expand Down

0 comments on commit 0f11f01

Please sign in to comment.