]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Move newly created NFS exceptions to standard location in exception.py
authorBen Swartzlander <bswartz@netapp.com>
Thu, 30 Aug 2012 00:35:33 +0000 (20:35 -0400)
committerBen Swartzlander <bswartz@netapp.com>
Sat, 1 Sep 2012 02:44:15 +0000 (22:44 -0400)
Addresses bug 1037619

bug 1037619

Change-Id: I20b1c612c03ef90eeb074814b979a9bc7492109c

cinder/exception.py
cinder/tests/test_nfs.py
cinder/volume/nfs.py

index d574f374830e1502d785c206268d3dd57d8f5eac..045c8a6c2ff98cdd59da59a9d75219e8eddc21e7 100644 (file)
@@ -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")
index 6bf6a0fcec413d9c98c1b2b4e6cd3ec92d020cf1..458700fe83f13433b8b0c1b7f1c7c874862eef23 100644 (file)
@@ -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()
index ed894efdc422f40284b61b639704d211e520dd56..02fb3a08fe936d383c61214ec1891e1d3d20d437 100644 (file)
@@ -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):