From af9d5460e41d3e274f4a5c8e087251dd4251cba6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Saffroy Date: Thu, 8 Aug 2013 20:49:28 +0200 Subject: [PATCH] Upgrade Scality driver to match minimum features 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 | 73 ++++++++++++++++++++++++++++++++ cinder/volume/drivers/scality.py | 9 ++++ 2 files changed, 82 insertions(+) diff --git a/cinder/tests/test_scality.py b/cinder/tests/test_scality.py index 77b1c4946..97966c5ba 100644 --- a/cinder/tests/test_scality.py +++ b/cinder/tests/test_scality.py @@ -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) diff --git a/cinder/volume/drivers/scality.py b/cinder/volume/drivers/scality.py index abf2fcda5..34f2138f8 100644 --- a/cinder/volume/drivers/scality.py +++ b/cinder/volume/drivers/scality.py @@ -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)) -- 2.45.2