From c58e87cfe19adbd432b23cfea00ce72e8636403b Mon Sep 17 00:00:00 2001 From: Ben Swartzlander Date: Wed, 29 Aug 2012 20:35:33 -0400 Subject: [PATCH] Move newly created NFS exceptions to standard location in exception.py Addresses bug 1037619 bug 1037619 Change-Id: I20b1c612c03ef90eeb074814b979a9bc7492109c --- cinder/exception.py | 12 ++++++++++++ cinder/tests/test_nfs.py | 9 +++++---- cinder/volume/nfs.py | 23 +++++------------------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cinder/exception.py b/cinder/exception.py index d574f3748..045c8a6c2 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -478,3 +478,15 @@ class InstanceNotFound(NotFound): class VolumeBackendAPIException(CinderException): message = _("Bad or unexpected response from the storage volume " "backend API: %(data)s") + + +class NfsException(CinderException): + message = _("Unknown NFS exception") + + +class NfsNoSharesMounted(NotFound): + message = _("No mounted NFS shares found") + + +class NfsNoSuitableShareFound(NotFound): + message = _("There is no share which can host %(volume_size)sG") diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index 6bf6a0fce..458700fe8 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -26,6 +26,7 @@ from mox import IgnoreArg from mox import stubout from cinder import context +from cinder import exception from cinder import test from cinder.exception import ProcessExecutionError @@ -374,7 +375,7 @@ class NfsDriverTestCase(test.TestCase): nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE - self.assertRaises(nfs.NfsException, + self.assertRaises(exception.NfsException, drv.do_setup, IsA(context.RequestContext)) def test_setup_should_throw_exception_if_nfs_client_is_not_installed(self): @@ -392,7 +393,7 @@ class NfsDriverTestCase(test.TestCase): mox.ReplayAll() - self.assertRaises(nfs.NfsException, + self.assertRaises(exception.NfsException, drv.do_setup, IsA(context.RequestContext)) mox.VerifyAll() @@ -403,7 +404,7 @@ class NfsDriverTestCase(test.TestCase): drv._mounted_shares = [] - self.assertRaises(nfs.NfsException, drv._find_share, + self.assertRaises(exception.NotFound, drv._find_share, self.TEST_SIZE_IN_GB) def test_find_share(self): @@ -441,7 +442,7 @@ class NfsDriverTestCase(test.TestCase): mox.ReplayAll() - self.assertRaises(nfs.NfsNoSuitableShareFound, drv._find_share, + self.assertRaises(exception.NfsNoSuitableShareFound, drv._find_share, self.TEST_SIZE_IN_GB) mox.VerifyAll() diff --git a/cinder/volume/nfs.py b/cinder/volume/nfs.py index ed894efdc..02fb3a08f 100644 --- a/cinder/volume/nfs.py +++ b/cinder/volume/nfs.py @@ -48,18 +48,6 @@ FLAGS = flags.FLAGS FLAGS.register_opts(volume_opts) -class NfsException(exception.CinderException): - pass - - -class NfsNoSharesMounted(NfsException): - pass - - -class NfsNoSuitableShareFound(NfsException): - pass - - class NfsDriver(driver.VolumeDriver): """NFS based cinder driver. Creates file on NFS share for using it as block device on hypervisor.""" @@ -74,13 +62,13 @@ class NfsDriver(driver.VolumeDriver): if not config or not os.path.exists(config): msg = _("NFS config file doesn't exist") LOG.warn(msg) - raise NfsException(msg) + raise exception.NfsException(msg) try: self._execute('mount.nfs', check_exit_code=False) except OSError as exc: if exc.errno == errno.ENOENT: - raise NfsException('mount.nfs is not installed') + raise exception.NfsException('mount.nfs is not installed') else: raise @@ -229,8 +217,7 @@ class NfsDriver(driver.VolumeDriver): """ if not self._mounted_shares: - raise NfsNoSharesMounted( - _("There is no any mounted NFS share found")) + raise exception.NfsNoSharesMounted() greatest_size = 0 greatest_share = None @@ -242,8 +229,8 @@ class NfsDriver(driver.VolumeDriver): greatest_size = capacity if volume_size_for * 1024 * 1024 * 1024 > greatest_size: - raise NfsNoSuitableShareFound( - _('There is no share which can host %sG') % volume_size_for) + raise exception.NfsNoSuitableShareFound( + volume_size=volume_size_for) return greatest_share def _get_mount_point_for_share(self, nfs_share): -- 2.45.2