move vzstorage exceptions

This patch moves the vzstorage driver specific exceptions to the driver.

Change-Id: Ia007916c46a7912f3ecb7791cc7c9fcc22d6d9d5
This commit is contained in:
Walter A. Boring IV 2019-05-09 18:43:40 +00:00
parent fc60334cd7
commit b97670549b
3 changed files with 28 additions and 30 deletions

View File

@ -1002,20 +1002,6 @@ class NfsNoSuitableShareFound(RemoteFSNoSuitableShareFound):
message = _("There is no share which can host %(volume_size)sG")
# Virtuozzo Storage Driver
class VzStorageException(RemoteFSException):
message = _("Unknown Virtuozzo Storage exception")
class VzStorageNoSharesMounted(RemoteFSNoSharesMounted):
message = _("No mounted Virtuozzo Storage shares found")
class VzStorageNoSuitableShareFound(RemoteFSNoSuitableShareFound):
message = _("There is no share which can host %(volume_size)sG")
# Fibre Channel Zone Manager
class ZoneManagerException(CinderException):
message = _("Fibre Channel connection control failure: %(reason)s")

View File

@ -103,7 +103,7 @@ class VZStorageTestCase(test.TestCase):
@mock.patch('os.path.exists')
def test_setup_missing_shares_conf(self, mock_exists):
mock_exists.side_effect = self._path_dont_exists
self.assertRaises(exception.VzStorageException,
self.assertRaises(vzstorage.VzStorageException,
self._vz_driver.do_setup,
mock.sentinel.context)
@ -111,7 +111,7 @@ class VZStorageTestCase(test.TestCase):
def test_setup_invalid_usage_ratio(self, mock_exists):
mock_exists.side_effect = self._path_exists
self._vz_driver.configuration.vzstorage_used_ratio = 1.2
self.assertRaises(exception.VzStorageException,
self.assertRaises(vzstorage.VzStorageException,
self._vz_driver.do_setup,
mock.sentinel.context)
@ -119,7 +119,7 @@ class VZStorageTestCase(test.TestCase):
def test_setup_invalid_usage_ratio2(self, mock_exists):
mock_exists.side_effect = self._path_exists
self._vz_driver.configuration.vzstorage_used_ratio = 0
self.assertRaises(exception.VzStorageException,
self.assertRaises(vzstorage.VzStorageException,
self._vz_driver.do_setup,
mock.sentinel.context)
@ -128,7 +128,7 @@ class VZStorageTestCase(test.TestCase):
mock_exists.side_effect = self._path_exists
self._cfg.vzstorage_mount_point_base = './tmp'
vz_driver = vzstorage.VZStorageDriver(configuration=self._cfg)
self.assertRaises(exception.VzStorageException,
self.assertRaises(vzstorage.VzStorageException,
vz_driver.do_setup,
mock.sentinel.context)
@ -138,7 +138,7 @@ class VZStorageTestCase(test.TestCase):
exc = OSError()
exc.errno = errno.ENOENT
self._vz_driver._execute.side_effect = exc
self.assertRaises(exception.VzStorageException,
self.assertRaises(vzstorage.VzStorageException,
self._vz_driver.do_setup,
mock.sentinel.context)
@ -164,7 +164,7 @@ class VZStorageTestCase(test.TestCase):
self.assertEqual(expected, ret)
def test_ensure_share_mounted_invalid_share(self):
self.assertRaises(exception.VzStorageException,
self.assertRaises(vzstorage.VzStorageException,
self._vz_driver._ensure_share_mounted, ':')
@mock.patch.object(remotefs.RemoteFsClient, 'mount')
@ -197,14 +197,14 @@ class VZStorageTestCase(test.TestCase):
def test_find_share_no_shares_mounted(self):
drv = self._vz_driver
with mock.patch.object(drv, '_is_share_eligible', return_value=True):
self.assertRaises(exception.VzStorageNoSharesMounted,
self.assertRaises(vzstorage.VzStorageNoSharesMounted,
drv._find_share, self.vol)
def test_find_share_no_shares_suitable(self):
drv = self._vz_driver
drv._mounted_shares = [self._FAKE_SHARE]
with mock.patch.object(drv, '_is_share_eligible', return_value=False):
self.assertRaises(exception.VzStorageNoSuitableShareFound,
self.assertRaises(vzstorage.VzStorageNoSuitableShareFound,
drv._find_share, self.vol)
def test_is_share_eligible_false(self):

View File

@ -73,6 +73,18 @@ DISK_FORMAT_QCOW2 = 'qcow2'
DISK_FORMAT_PLOOP = 'ploop'
class VzStorageException(exception.RemoteFSException):
message = _("Unknown Virtuozzo Storage exception")
class VzStorageNoSharesMounted(exception.RemoteFSNoSharesMounted):
message = _("No mounted Virtuozzo Storage shares found")
class VzStorageNoSuitableShareFound(exception.RemoteFSNoSuitableShareFound):
message = _("There is no share which can host %(volume_size)sG")
class PloopDevice(object):
"""Setup a ploop device for ploop image
@ -239,19 +251,19 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
msg = (_("VzStorage config file at %(config)s doesn't exist.") %
{'config': config})
LOG.error(msg)
raise exception.VzStorageException(msg)
raise VzStorageException(msg)
if not os.path.isabs(self.base):
msg = _("Invalid mount point base: %s.") % self.base
LOG.error(msg)
raise exception.VzStorageException(msg)
raise VzStorageException(msg)
used_ratio = self.configuration.vzstorage_used_ratio
if not ((used_ratio > 0) and (used_ratio <= 1)):
msg = _("VzStorage config 'vzstorage_used_ratio' invalid. "
"Must be > 0 and <= 1.0: %s.") % used_ratio
LOG.error(msg)
raise exception.VzStorageException(msg)
raise VzStorageException(msg)
self.shares = {}
@ -265,7 +277,7 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
except OSError as exc:
if exc.errno == errno.ENOENT:
msg = _('%s is not installed.') % package
raise exception.VzStorageException(msg)
raise VzStorageException(msg)
else:
raise
@ -278,7 +290,7 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
msg = (_("Invalid Virtuozzo Storage share specification: %r. "
"Must be: [MDS1[,MDS2],...:/]<CLUSTER NAME>[:PASSWORD].")
% share)
raise exception.VzStorageException(msg)
raise VzStorageException(msg)
cluster_name = m.group(2)
if share in self.shares:
@ -306,13 +318,13 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
"""
if not self._mounted_shares:
raise exception.VzStorageNoSharesMounted()
raise VzStorageNoSharesMounted()
for share in self._mounted_shares:
if self._is_share_eligible(share, volume.size):
break
else:
raise exception.VzStorageNoSuitableShareFound(
raise VzStorageNoSuitableShareFound(
volume_size=volume.size)
LOG.debug('Selected %s as target VzStorage share.', share)
@ -619,7 +631,7 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
elif active_file != snap_file:
msg = (_("Expected higher file exists for snapshot %s") %
snapshot.id)
raise exception.VzStorageException(msg)
raise VzStorageException(msg)
img_info = self._qemu_img_info(snap_file, snapshot.volume.name)
base_file = os.path.join(self._local_volume_dir(snapshot.volume),