From 7e038bc2e94ce65aa3a004632dcc867b4aee59ae Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Thu, 9 May 2019 18:53:44 +0000 Subject: [PATCH] move smbfs exceptions This patch moves the smbfs driver exceptions to the driver. Change-Id: Id03022b2871cbb13a9c80521dff21f52b06d5b69 --- cinder/exception.py | 13 ------------- cinder/tests/unit/windows/test_smbfs.py | 8 ++++---- cinder/volume/drivers/windows/smbfs.py | 26 ++++++++++++++++++------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/cinder/exception.py b/cinder/exception.py index b87fe381267..cdfe95b8bda 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -1038,19 +1038,6 @@ class NfsNoSuitableShareFound(RemoteFSNoSuitableShareFound): message = _("There is no share which can host %(volume_size)sG") -# Smbfs driver -class SmbfsException(RemoteFSException): - message = _("Unknown SMBFS exception.") - - -class SmbfsNoSharesMounted(RemoteFSNoSharesMounted): - message = _("No mounted SMBFS shares found.") - - -class SmbfsNoSuitableShareFound(RemoteFSNoSuitableShareFound): - message = _("There is no share which can host %(volume_size)sG.") - - # Virtuozzo Storage Driver class VzStorageException(RemoteFSException): diff --git a/cinder/tests/unit/windows/test_smbfs.py b/cinder/tests/unit/windows/test_smbfs.py index 9f6cbb71a5f..302f81f58fa 100644 --- a/cinder/tests/unit/windows/test_smbfs.py +++ b/cinder/tests/unit/windows/test_smbfs.py @@ -113,7 +113,7 @@ class WindowsSmbFsTestCase(test.TestCase): self._smbfs_driver.configuration = config if not (config.smbfs_shares_config and share_config_exists): - self.assertRaises(exception.SmbfsException, + self.assertRaises(smbfs.SmbfsException, self._smbfs_driver.do_setup, mock.sentinel.context) else: @@ -153,7 +153,7 @@ class WindowsSmbFsTestCase(test.TestCase): 'share0': 'pool0', 'share1': 'pool0' } - self.assertRaises(exception.SmbfsException, + self.assertRaises(smbfs.SmbfsException, self._smbfs_driver._setup_pool_mappings) def test_initialize_connection(self): @@ -322,7 +322,7 @@ class WindowsSmbFsTestCase(test.TestCase): supported_fmts = self._smbfs_driver._SUPPORTED_IMAGE_FORMATS if volume_format.lower() not in supported_fmts: - self.assertRaises(exception.SmbfsException, + self.assertRaises(smbfs.SmbfsException, self._smbfs_driver.get_volume_format, self.volume, qemu_format) @@ -862,7 +862,7 @@ class WindowsSmbFsTestCase(test.TestCase): def test_get_pool_name_from_share_exception(self): self._smbfs_driver._pool_mappings = {} - self.assertRaises(exception.SmbfsException, + self.assertRaises(smbfs.SmbfsException, self._smbfs_driver._get_share_from_pool_name, mock.sentinel.pool) diff --git a/cinder/volume/drivers/windows/smbfs.py b/cinder/volume/drivers/windows/smbfs.py index 623f9515c20..009b46c359e 100644 --- a/cinder/volume/drivers/windows/smbfs.py +++ b/cinder/volume/drivers/windows/smbfs.py @@ -64,6 +64,18 @@ CONF = cfg.CONF CONF.register_opts(volume_opts, group=configuration.SHARED_CONF_GROUP) +class SmbfsException(exception.RemoteFSException): + message = _("Unknown SMBFS exception.") + + +class SmbfsNoSharesMounted(exception.RemoteFSNoSharesMounted): + message = _("No mounted SMBFS shares found.") + + +class SmbfsNoSuitableShareFound(exception.RemoteFSNoSuitableShareFound): + message = _("There is no share which can host %(volume_size)sG.") + + @interface.volumedriver class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, remotefs_drv.RemoteFSPoolMixin, @@ -139,16 +151,16 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, if not config: msg = (_("SMBFS config file not set (smbfs_shares_config).")) LOG.error(msg) - raise exception.SmbfsException(msg) + raise SmbfsException(msg) if not os.path.exists(config): msg = (_("SMBFS config file at %(config)s doesn't exist.") % {'config': config}) LOG.error(msg) - raise exception.SmbfsException(msg) + raise SmbfsException(msg) if not os.path.isabs(self.base): msg = _("Invalid mount point base: %s") % self.base LOG.error(msg) - raise exception.SmbfsException(msg) + raise SmbfsException(msg) self.shares = {} # address : options self._ensure_shares_mounted() @@ -163,7 +175,7 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, if duplicate_pools: msg = _("Found multiple mappings for pools %(pools)s. " "Requested pool mappings: %(pool_mappings)s") - raise exception.SmbfsException( + raise SmbfsException( msg % dict(pools=duplicate_pools, pool_mappings=self._pool_mappings)) @@ -221,7 +233,7 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, if sys.platform != 'win32': _msg = _("This system platform (%s) is not supported. This " "driver supports only Win32 platforms.") % sys.platform - raise exception.SmbfsException(_msg) + raise SmbfsException(_msg) def _get_total_allocated(self, smbfs_share): pool_name = self._get_pool_name_from_share(smbfs_share) @@ -276,7 +288,7 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, volume_format = ext else: # Hyper-V relies on file extensions so we're enforcing them. - raise exception.SmbfsException( + raise SmbfsException( _("Invalid image file extension: %s") % ext) else: volume_format = ( @@ -635,7 +647,7 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, if not share: msg = _("Could not find any share for pool %(pool_name)s. " "Pool mappings: %(pool_mappings)s.") - raise exception.SmbfsException( + raise SmbfsException( msg % dict(pool_name=pool_name, pool_mappings=self._pool_mappings)) return share