Skip to content

Commit

Permalink
Upgrade Scality driver to match minimum features
Browse files Browse the repository at this point in the history
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
  • Loading branch information
saffroy committed Aug 9, 2013
1 parent 957685e commit af9d546
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
73 changes: 73 additions & 0 deletions cinder/tests/test_scality.py
Expand Up @@ -23,7 +23,9 @@

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -111,6 +125,9 @@ def setUp(self):
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)
Expand Down Expand Up @@ -211,3 +228,59 @@ def test_initialize_connection(self):
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)
9 changes: 9 additions & 0 deletions cinder/volume/drivers/scality.py
Expand Up @@ -257,3 +257,12 @@ def clone_image(self, volume, image_location):
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))

0 comments on commit af9d546

Please sign in to comment.