Move NVMET driver exceptions to driver file

This patch migrates the NVMET driver specific exceptions from
the cinder/exception.py file to the respective driver.

Change-Id: Ie75babd057d71e31b442485d64eba8b2dc0b1809
This commit is contained in:
Walter A. Boring IV 2019-05-03 15:13:14 +00:00
parent 6fcb7c6639
commit 4dfca46ce8
3 changed files with 12 additions and 15 deletions

View File

@ -1385,12 +1385,3 @@ class ServiceUserTokenNoAuth(CinderException):
class UnsupportedNVMETProtocol(Invalid):
message = _("An invalid 'target_protocol' "
"value was provided: %(protocol)s")
# NVMET driver
class NVMETTargetAddError(CinderException):
message = "Failed to add subsystem: %(subsystem)s"
class NVMETTargetDeleteError(CinderException):
message = "Failed to delete subsystem: %(subsystem)s"

View File

@ -15,7 +15,6 @@ import mock
from oslo_utils import timeutils
from cinder import context
from cinder import exception
from cinder.tests.unit.targets import targets_fixture as tf
from cinder import utils
from cinder.volume.targets import nvmet
@ -141,7 +140,7 @@ class TestNVMETDriver(tf.TargetDriverFixture):
self.target.target_ip = self.target_ip
self.target.target_port = self.target_port
self.assertRaises(exception.NVMETTargetAddError,
self.assertRaises(nvmet.NVMETTargetAddError,
self.target.create_export,
ctxt,
mock_testvol,
@ -260,7 +259,7 @@ class TestNVMETDriver(tf.TargetDriverFixture):
"nqn.%s-%s" % (self.nvmet_subsystem_name,
mock_testvol['id']))
moc_delete_nvmf_subsystem.return_value = None
self.assertRaises(exception.NVMETTargetDeleteError,
self.assertRaises(nvmet.NVMETTargetDeleteError,
self.target.remove_export,
ctxt,
mock_testvol)

View File

@ -29,6 +29,14 @@ from cinder.volume.targets import nvmeof
LOG = logging.getLogger(__name__)
class NVMETTargetAddError(exception.CinderException):
message = "Failed to add subsystem: %(subsystem)s"
class NVMETTargetDeleteError(exception.CinderException):
message = "Failed to delete subsystem: %(subsystem)s"
class NVMET(nvmeof.NVMeOF):
@utils.synchronized('nvmetcli', external=True)
@ -58,7 +66,7 @@ class NVMET(nvmeof.NVMeOF):
ns_id, volume_id, volume_path)
if newly_added_subsystem is None:
LOG.error('Failed to add subsystem: %s', subsystem_name)
raise exception.NVMETTargetAddError(subsystem=subsystem_name)
raise NVMETTargetAddError(subsystem=subsystem_name)
LOG.info('Added subsystem: %s', newly_added_subsystem)
search_for_subsystem = newly_added_subsystem
else:
@ -142,8 +150,7 @@ class NVMET(nvmeof.NVMeOF):
if removed_subsystem is None:
LOG.error(
'Failed to delete subsystem: %s', subsystem_name)
raise exception.NVMETTargetDeleteError(
subsystem=subsystem_name)
raise NVMETTargetDeleteError(subsystem=subsystem_name)
elif removed_subsystem == subsystem_name:
LOG.info(
'Managed to delete subsystem: %s', subsystem_name)