Merge "Vzstorage: synchronize volume connect" into stable/pike

This commit is contained in:
Zuul 2017-12-11 22:05:04 +00:00 committed by Gerrit Code Review
commit 2b558b7920
2 changed files with 16 additions and 8 deletions

View File

@ -67,7 +67,9 @@ class LibvirtVZStorageTestCase(test_volume.LibvirtVolumeBaseTestCase):
self.disk_info,
mock.sentinel.instance)
def test_libvirt_vzstorage_driver_connect(self):
@mock.patch.object(vzstorage.utils, 'synchronized',
return_value=lambda f: f)
def test_libvirt_vzstorage_driver_connect(self, mock_synchronized):
def brick_conn_vol(data):
return {'path': 'vstorage://testcluster'}
@ -86,6 +88,7 @@ class LibvirtVZStorageTestCase(test_volume.LibvirtVolumeBaseTestCase):
'-l /var/log/vstorage/testcluster/nova.log.gz '
'-C /tmp/ssd-cache/testcluster',
connection_info['data']['options'])
mock_synchronized.assert_called_once_with('vz_share-testcluster')
def test_libvirt_vzstorage_driver_disconnect(self):
drv = vzstorage.LibvirtVZStorageVolumeDriver(self.fake_host)

View File

@ -33,6 +33,7 @@ class LibvirtVZStorageVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
"""Class implements libvirt part of volume driver for VzStorage."""
SHARE_FORMAT_REGEX = r'(?:(\S+):/)?([a-zA-Z0-9_-]+)(?::(\S+))?$'
SHARE_LOCK_NAME = "vz_share-%s"
def __init__(self, connection):
super(LibvirtVZStorageVolumeDriver, self).__init__(connection)
@ -110,18 +111,22 @@ class LibvirtVZStorageVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
def connect_volume(self, connection_info, disk_info, instance):
"""Attach the volume to instance_name."""
LOG.debug("Calling os-brick to mount vzstorage")
vz_share = connection_info['data']['export']
connection_info['data']['options'] = self._get_mount_opts(vz_share)
device_info = self.connector.connect_volume(connection_info['data'])
LOG.debug("Attached vzstorage volume %s", device_info)
share_lock = self.SHARE_LOCK_NAME % vz_share
connection_info['data']['device_path'] = device_info['path']
@utils.synchronized(share_lock)
def _connect_volume(connection_info, disk_info, instance):
LOG.debug("Calling os-brick to mount vzstorage")
connection_info['data']['options'] = self._get_mount_opts(vz_share)
device_info = self.connector.connect_volume(
connection_info['data'])
LOG.debug("Attached vzstorage volume %s", device_info)
connection_info['data']['device_path'] = device_info['path']
return _connect_volume(connection_info, disk_info, instance)
def disconnect_volume(self, connection_info, disk_dev, instance):
"""Detach the volume from instance_name."""
LOG.debug("calling os-brick to detach Vzstorage Volume")
self.connector.disconnect_volume(connection_info['data'], None)
LOG.debug("Disconnected Vzstorage Volume %s", disk_dev)