]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Upgrade Scality driver to match minimum features
authorJean-Marc Saffroy <jean.marc.saffroy@scality.com>
Thu, 8 Aug 2013 18:49:28 +0000 (20:49 +0200)
committerJean-Marc Saffroy <jean.marc.saffroy@scality.com>
Fri, 9 Aug 2013 18:20:15 +0000 (20:20 +0200)
The Scality driver needs an upgrade to match minimum features:
- Havana: Clone Volume
- Icehouse: Extend Volume

Also, some features (Copy Image to Volume, Copy Volume to Image) already work but need automated tests.

Change-Id: Iac5ac2c58fd5ce62823f829a0a014decb4ad4958
Fixes: bug 1210240
cinder/tests/test_scality.py
cinder/volume/drivers/scality.py

index 77b1c4946f661822fb8b448678c9c09550cff807..97966c5ba00c7f5b86b56ecb246ffa92cde221e3 100644 (file)
@@ -23,7 +23,9 @@ import tempfile
 
 import mox as mox_lib
 
+from cinder import context
 from cinder import exception
+from cinder.image import image_utils
 from cinder import test
 from cinder import utils
 from cinder.volume.drivers import scality
@@ -56,6 +58,18 @@ class ScalityDriverTestCase(test.TestCase):
                                  TEST_VOLDIR,
                                  TEST_SNAPNAME)
 
+    TEST_CLONENAME = 'clone_name'
+    TEST_CLONE = {
+        'name': TEST_CLONENAME,
+        'size': TEST_VOLSIZE
+    }
+
+    TEST_NEWSIZE = '2'
+
+    TEST_IMAGE_SERVICE = 'image_service'
+    TEST_IMAGE_ID = 'image_id'
+    TEST_IMAGE_META = 'image_meta'
+
     def _makedirs(self, path):
         try:
             os.makedirs(path)
@@ -111,6 +125,9 @@ class ScalityDriverTestCase(test.TestCase):
         self.TEST_SNAPPATH = os.path.join(self.TEST_MOUNT,
                                           self.TEST_VOLDIR,
                                           self.TEST_SNAPNAME)
+        self.TEST_CLONEPATH = os.path.join(self.TEST_MOUNT,
+                                           self.TEST_VOLDIR,
+                                           self.TEST_CLONENAME)
 
         self._driver = scality.ScalityDriver()
         self._driver.set_execute(self._execute_wrapper)
@@ -211,3 +228,59 @@ class ScalityDriverTestCase(test.TestCase):
         self.assertEqual(ret['data']['sofs_path'],
                          os.path.join(self.TEST_VOLDIR,
                                       self.TEST_VOLNAME))
+
+    def test_copy_image_to_volume(self):
+        """Expected behaviour for copy_image_to_volume."""
+        self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')
+
+        image_utils.fetch_to_raw(context,
+                                 self.TEST_IMAGE_SERVICE,
+                                 self.TEST_IMAGE_ID,
+                                 self.TEST_VOLPATH)
+
+        self.mox.ReplayAll()
+
+        self._driver.copy_image_to_volume(context,
+                                          self.TEST_VOLUME,
+                                          self.TEST_IMAGE_SERVICE,
+                                          self.TEST_IMAGE_ID)
+
+    def test_copy_volume_to_image(self):
+        """Expected behaviour for copy_volume_to_image."""
+        self.mox.StubOutWithMock(image_utils, 'upload_volume')
+
+        image_utils.upload_volume(context,
+                                  self.TEST_IMAGE_SERVICE,
+                                  self.TEST_IMAGE_META,
+                                  self.TEST_VOLPATH)
+
+        self.mox.ReplayAll()
+
+        self._driver.copy_volume_to_image(context,
+                                          self.TEST_VOLUME,
+                                          self.TEST_IMAGE_SERVICE,
+                                          self.TEST_IMAGE_META)
+
+    def test_create_cloned_volume(self):
+        """Expected behaviour for create_cloned_volume."""
+        self.mox.StubOutWithMock(self._driver, '_create_file')
+        self.mox.StubOutWithMock(self._driver, '_copy_file')
+
+        vol_size = self._driver._size_bytes(self.TEST_VOLSIZE)
+        self._driver._create_file(self.TEST_CLONEPATH, vol_size)
+        self._driver._copy_file(self.TEST_VOLPATH, self.TEST_CLONEPATH)
+
+        self.mox.ReplayAll()
+
+        self._driver.create_cloned_volume(self.TEST_CLONE, self.TEST_VOLUME)
+
+    def test_extend_volume(self):
+        """Expected behaviour for extend_volume."""
+        self.mox.StubOutWithMock(self._driver, '_create_file')
+
+        new_size = self._driver._size_bytes(self.TEST_NEWSIZE)
+        self._driver._create_file(self.TEST_VOLPATH, new_size)
+
+        self.mox.ReplayAll()
+
+        self._driver.extend_volume(self.TEST_VOLUME, self.TEST_NEWSIZE)
index abf2fcda54344ec1ac78feaaf685018384221a68..34f2138f8c67126fcfad5393f6a5e5a2de8d2573 100644 (file)
@@ -257,3 +257,12 @@ class ScalityDriver(driver.VolumeDriver):
         boolean indicating whether cloning occurred
         """
         return None, False
+
+    def create_cloned_volume(self, volume, src_vref):
+        """Creates a clone of the specified volume."""
+        self.create_volume_from_snapshot(volume, src_vref)
+
+    def extend_volume(self, volume, new_size):
+        """Extend an existing volume."""
+        self._create_file(self.local_path(volume),
+                          self._size_bytes(new_size))