vstorage: added vz:volume_format vendor property

VStorage backend is able to deal with multiple volume
formats. Now desired volume format may be chosen by
setting vz:volume_format property in volume type
extra spec.

Change-Id: Ib610e6f9c82259f9dd2db37178b24d964a38e20d
Signed-off-by: Pavel Glushchak <pglushchak@virtuozzo.com>
This commit is contained in:
Pavel Glushchak 2017-05-16 18:10:54 +03:00
parent b2aa2bd40f
commit 1f69f7507e
3 changed files with 75 additions and 14 deletions

View File

@ -366,3 +366,33 @@ class VZStorageTestCase(test.TestCase):
'ploop', 'resize', '-s', '100G',
'%s/DiskDescriptor.xml' % self._FAKE_VOLUME_PATH,
run_as_root=True)
@mock.patch.object(os.path, 'exists', return_value=False)
def test_do_create_volume_with_volume_type(self, mock_exists):
drv = self._vz_driver
drv.local_path = mock.Mock(
return_value=self._FAKE_VOLUME_PATH)
drv._write_info_file = mock.Mock()
drv._qemu_img_info = mock.Mock()
drv._create_qcow2_file = mock.Mock()
drv._create_ploop = mock.Mock()
volume_type = fake_volume.fake_volume_type_obj(self.context)
volume_type.extra_specs = {
'vz:volume_format': 'qcow2'
}
volume1 = fake_volume.fake_volume_obj(self.context)
volume1.size = 1024
volume1.volume_type = volume_type
volume2 = copy.deepcopy(volume1)
volume2.metadata = {
'volume_format': 'ploop'
}
drv._do_create_volume(volume1)
drv._create_qcow2_file.assert_called_once_with(
self._FAKE_VOLUME_PATH, 1024)
drv._do_create_volume(volume2)
drv._create_ploop.assert_called_once_with(
self._FAKE_VOLUME_PATH, 1024)

View File

@ -33,8 +33,6 @@ from cinder import interface
from cinder import utils
from cinder.volume.drivers import remotefs as remotefs_drv
VERSION = '1.0'
LOG = logging.getLogger(__name__)
vzstorage_opts = [
@ -153,17 +151,17 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
Version history:
1.0 - Initial driver.
1.1 - Supports vz:volume_format in vendor properties.
"""
driver_volume_type = 'vzstorage'
driver_prefix = 'vzstorage'
volume_backend_name = 'Virtuozzo_Storage'
VERSION = VERSION
# ThirdPartySystems wiki page
VERSION = '1.1'
CI_WIKI_NAME = "Virtuozzo_Storage_CI"
SHARE_FORMAT_REGEX = r'(?:(\S+):\/)?([a-zA-Z0-9_-]+)(?::(\S+))?'
def __init__(self, execute=putils.execute, *args, **kwargs):
self.driver_volume_type = 'vzstorage'
self.driver_prefix = 'vzstorage'
self.volume_backend_name = 'Virtuozzo_Storage'
self._remotefsclient = None
super(VZStorageDriver, self).__init__(*args, **kwargs)
self.configuration.append_config_values(vzstorage_opts)
@ -182,6 +180,25 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
vzstorage_mount_point_base=self.base,
vzstorage_mount_options=opts)
def _update_volume_stats(self):
super(VZStorageDriver, self)._update_volume_stats()
self._stats['vendor_name'] = 'Virtuozzo'
def _init_vendor_properties(self):
namespace = 'vz'
properties = {}
self._set_property(
properties,
"%s:volume_format" % namespace,
"Volume format",
_("Specifies volume format."),
"string",
enum=["qcow2", "ploop", "raw"],
default=self.configuration.vzstorage_default_volume_format)
return properties, namespace
def _qemu_img_info(self, path, volume_name):
qemu_img_cache = path + ".qemu_img_info"
is_cache_outdated = True
@ -338,15 +355,23 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
return True
def choose_volume_format(self, volume):
vol_type = volume.volume_type
if vol_type:
extra_specs = vol_type.extra_specs or {}
else:
extra_specs = {}
volume_format = None
volume_type = volume.volume_type
extra_specs.update(volume.metadata or {})
# Retrieve volume format from volume metadata
if 'volume_format' in volume.metadata:
volume_format = volume.metadata['volume_format']
return (extra_specs.get('volume_format') or
# If volume format wasn't found in metadata, use
# volume type extra specs
if not volume_format and volume_type:
extra_specs = volume_type.extra_specs or {}
if 'vz:volume_format' in extra_specs:
volume_format = extra_specs['vz:volume_format']
# If volume format is still undefined, return default
# volume format from backend configuration
return (volume_format or
self.configuration.vzstorage_default_volume_format)
def get_volume_format(self, volume):

View File

@ -0,0 +1,6 @@
---
features:
- |
VzStorage volume driver now supports choosing desired volume format by setting
vendor property 'vz:volume_format' in volume type metadata.
Allowed values are 'ploop', 'qcow2' and 'raw'.