Skip to content
Permalink
Browse files

CoraidDriver: Create_volume_from_snapshot of a different size

When you create a Volume from a Snapshot, the 'size' argument for the
new volume isn't used at all.
So, the new volume created will be created (successfully but) with the
same size as the snapshot size.

Cinder think the volume has been created with the right size.

We just need to call Coraid ESM LV Resize with the REST API after
the volume has been created.

Fixes bug 1158959

Change-Id: I760fe1ba4052bb2d5b1a1a5c55c9a976522af107
  • Loading branch information...
jbransy committed Jun 20, 2013
1 parent e3abee8 commit 1410af4214379da13b10baec3ddb37cbce7e5eb6
Showing with 62 additions and 6 deletions.
  1. +36 −6 cinder/tests/test_coraid.py
  2. +26 −0 cinder/volume/drivers/coraid.py
@@ -64,7 +64,8 @@
fake_snapshot_id = "12345678-8888-8888-1234-1234567890ab"
fake_volume_id = "12345678-1234-1234-1234-1234567890ab"
fake_snapshot = {"id": fake_snapshot_id,
"volume_id": fake_volume_id}
"volume_id": fake_volume_id,
"volume_size": 10}

fake_configure_data = [{"addr": "cms", "data": "FAKE"}]

@@ -153,11 +154,30 @@ def test_delete_snapshot(self):
self.drv.delete_snapshot(fake_snapshot)

def test_create_volume_from_snapshot(self):
setattr(self.esm_mock, 'create_volume_from_snapshot',
lambda *_: True)
self.stubs.Set(CoraidDriver, '_get_repository',
lambda *_: fake_repository_name)
self.drv.create_volume_from_snapshot(fake_volume, fake_snapshot)
self.esm_mock.create_volume_from_snapshot(
fake_volume,
fake_snapshot).AndReturn(True)
mox.Replay(self.esm_mock)
self.esm_mock.create_volume_from_snapshot(fake_volume, fake_snapshot)
mox.Verify(self.esm_mock)

def test_create_volume_from_snapshot_bigger(self):
self.esm_mock.create_volume_from_snapshot(
fake_volume,
fake_snapshot).AndReturn(True)
self.esm_mock.resize_volume(fake_volume_name,
'20').AndReturn(True)
mox.Replay(self.esm_mock)
self.esm_mock.create_volume_from_snapshot(fake_volume, fake_snapshot)
self.esm_mock.resize_volume(fake_volume_name, '20')
mox.Verify(self.esm_mock)

def test_extend_volume(self):
self.esm_mock.resize_volume(fake_volume_name,
'20').AndReturn(True)
mox.Replay(self.esm_mock)
self.esm_mock.resize_volume(fake_volume_name, '20')
mox.Verify(self.esm_mock)


class TestCoraidRESTClient(test.TestCase):
@@ -268,3 +288,13 @@ def test_create_volume_from_snapshot(self):
self.drv.create_volume_from_snapshot(fake_volume_name,
fake_volume_name,
fake_repository_name)

def test_resize_volume(self):
setattr(self.rest_mock, 'resize_volume',
lambda *_: True)
self.stubs.Set(CoraidRESTClient, '_get_volume_info',
lambda *_: fake_volume_info)
self.stubs.Set(CoraidRESTClient, '_configure',
lambda *_: fake_esm_success)
self.drv.resize_volume(fake_volume_name,
'20')
@@ -265,6 +265,19 @@ def create_volume_from_snapshot(self, snapshot_name,
volume_name, repository)
return self._configure(data)

def resize_volume(self, volume_name, volume_size):
volume_info = self._get_volume_info(volume_name)
repository = volume_info['repo']
data = '[{"addr":"cms","data":"{' \
'\\"lvName\\":\\"%s\\",' \
'\\"newLvSize\\":\\"%s\\"}",' \
'\\"repoName\\":\\"%s\\"}",' \
'"op":"orchStrLunMods",' \
'"args":"resizeVolume"}]' % (volume_name,
volume_size,
repository)
return self._configure(data)


class CoraidDriver(driver.VolumeDriver):
"""This is the Class to set in cinder.conf (volume_driver)."""
@@ -355,12 +368,25 @@ def create_volume_from_snapshot(self, volume, snapshot):
self.esm.create_volume_from_snapshot(snapshot_name,
volume['name'],
repository)
resize = volume['size'] > snapshot['volume_size']
if resize:
self.esm.resize_volume(volume['name'], volume['size'])
except Exception:
msg = _('Failed to Create Volume from Snapshot %(snapname)s')
LOG.debug(msg % dict(snapname=snapshot_name))
raise
return

def extend_volume(self, volume, new_size):
"""Extend an Existing Volume."""
try:
self.esm.resize_volume(volume['name'], new_size)
except Exception:
msg = _('Failed to Extend Volume %(volname)s')
LOG.debug(msg % dict(volname=volume['name']))
raise
return

def initialize_connection(self, volume, connector):
"""Return connection information."""
try:

0 comments on commit 1410af4

Please sign in to comment.
You can’t perform that action at this time.