From 1410af4214379da13b10baec3ddb37cbce7e5eb6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Ransy Date: Thu, 20 Jun 2013 17:39:45 +0200 Subject: [PATCH] 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 --- cinder/tests/test_coraid.py | 42 ++++++++++++++++++++++++++++----- cinder/volume/drivers/coraid.py | 26 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/cinder/tests/test_coraid.py b/cinder/tests/test_coraid.py index 3edd3f16c..793eeca18 100644 --- a/cinder/tests/test_coraid.py +++ b/cinder/tests/test_coraid.py @@ -64,7 +64,8 @@ fake_snapshot_name = "snapshot-12345678-8888-8888-1234-1234567890ab" 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 @@ class TestCoraidDriver(test.TestCase): 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 @@ class TestCoraidRESTClient(test.TestCase): 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') diff --git a/cinder/volume/drivers/coraid.py b/cinder/volume/drivers/coraid.py index dd14f49e9..16df4c08c 100644 --- a/cinder/volume/drivers/coraid.py +++ b/cinder/volume/drivers/coraid.py @@ -265,6 +265,19 @@ class CoraidRESTClient(object): 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 @@ class CoraidDriver(driver.VolumeDriver): 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: -- 2.45.2