Skip to content

Commit

Permalink
Move newly created NFS exceptions to standard location in exception.py
Browse files Browse the repository at this point in the history
Addresses bug 1037619

bug 1037619

Change-Id: I20b1c612c03ef90eeb074814b979a9bc7492109c
  • Loading branch information
Ben Swartzlander committed Sep 1, 2012
1 parent 99e8882 commit c58e87c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
12 changes: 12 additions & 0 deletions cinder/exception.py
Expand Up @@ -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")
9 changes: 5 additions & 4 deletions cinder/tests/test_nfs.py
Expand Up @@ -26,6 +26,7 @@
from mox import stubout

from cinder import context
from cinder import exception
from cinder import test
from cinder.exception import ProcessExecutionError

Expand Down Expand Up @@ -374,7 +375,7 @@ def test_setup_should_throw_error_if_shares_config_not_configured(self):

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):
Expand All @@ -392,7 +393,7 @@ def test_setup_should_throw_exception_if_nfs_client_is_not_installed(self):

mox.ReplayAll()

self.assertRaises(nfs.NfsException,
self.assertRaises(exception.NfsException,
drv.do_setup, IsA(context.RequestContext))

mox.VerifyAll()
Expand All @@ -403,7 +404,7 @@ def test_find_share_should_throw_error_if_there_is_no_mounted_shares(self):

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):
Expand Down Expand Up @@ -441,7 +442,7 @@ def test_find_share_should_throw_error_if_there_is_no_enough_place(self):

mox.ReplayAll()

self.assertRaises(nfs.NfsNoSuitableShareFound, drv._find_share,
self.assertRaises(exception.NfsNoSuitableShareFound, drv._find_share,
self.TEST_SIZE_IN_GB)

mox.VerifyAll()
Expand Down
23 changes: 5 additions & 18 deletions cinder/volume/nfs.py
Expand Up @@ -48,18 +48,6 @@
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."""
Expand All @@ -74,13 +62,13 @@ def do_setup(self, context):
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

Expand Down Expand Up @@ -229,8 +217,7 @@ def _find_share(self, volume_size_for):
"""

if not self._mounted_shares:
raise NfsNoSharesMounted(
_("There is no any mounted NFS share found"))
raise exception.NfsNoSharesMounted()

greatest_size = 0
greatest_share = None
Expand All @@ -242,8 +229,8 @@ def _find_share(self, volume_size_for):
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):
Expand Down

0 comments on commit c58e87c

Please sign in to comment.