]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
CoraidDriver: Create_volume_from_snapshot of a different size
authorJean-Baptiste Ransy <jean-baptiste.ransy@alyseo.com>
Thu, 20 Jun 2013 15:39:45 +0000 (17:39 +0200)
committerJean-Baptiste Ransy <jean-baptiste.ransy@alyseo.com>
Tue, 2 Jul 2013 09:20:06 +0000 (11:20 +0200)
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
cinder/volume/drivers/coraid.py

index 3edd3f16c02bbcf0c88e2ce3009c548a453c5d05..793eeca18655fdcbdd3cf7042a5f2c095188a3de 100644 (file)
@@ -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')
index dd14f49e95482005be107e041183f4050c4a5a22..16df4c08c15770078025ca7318005f4c1abb3222 100644 (file)
@@ -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: