Remove shadow BaseException class
The BaseException class defined in exceptions.py is shadowing the built-in BaseException class of the Python exception hierarchy, which could potentially cause confusion. This removes the BaseException definition and replaces it with the existing WatcherException object. Instantiations of the IllegalArgumentException are also changed to use the message kwarg. Change-Id: I20abf135805c7a354924de8a5194b59fc040460a Closes-Bug: #1535504
This commit is contained in:
@@ -63,7 +63,7 @@ class ChangeNovaServiceState(base.BasePrimitive):
|
|||||||
def nova_manage_service(self, state):
|
def nova_manage_service(self, state):
|
||||||
if state is None:
|
if state is None:
|
||||||
raise exception.IllegalArgumentException(
|
raise exception.IllegalArgumentException(
|
||||||
_("The target state is not defined"))
|
message=_("The target state is not defined"))
|
||||||
|
|
||||||
keystone = kclient.KeystoneClient()
|
keystone = kclient.KeystoneClient()
|
||||||
wrapper = nclient.NovaClient(keystone.get_credentials(),
|
wrapper = nclient.NovaClient(keystone.get_credentials(),
|
||||||
|
|||||||
@@ -220,51 +220,16 @@ class PatchError(Invalid):
|
|||||||
# decision engine
|
# decision engine
|
||||||
|
|
||||||
|
|
||||||
class BaseException(Exception):
|
class IllegalArgumentException(WatcherException):
|
||||||
|
msg_fmt = _('Illegal argument')
|
||||||
def __init__(self, desc=""):
|
|
||||||
if (not isinstance(desc, six.string_types)):
|
|
||||||
raise ValueError(_("Description must be an instance of str"))
|
|
||||||
|
|
||||||
desc = desc.strip()
|
|
||||||
|
|
||||||
self._desc = desc
|
|
||||||
|
|
||||||
def get_description(self):
|
|
||||||
return self._desc
|
|
||||||
|
|
||||||
def get_message(self):
|
|
||||||
return _("An exception occurred without a description")
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.get_message()
|
|
||||||
|
|
||||||
|
|
||||||
class IllegalArgumentException(BaseException):
|
class NoSuchMetric(WatcherException):
|
||||||
def __init__(self, desc):
|
msg_fmt = _('No such metric')
|
||||||
desc = desc or _("Description cannot be empty")
|
|
||||||
super(IllegalArgumentException, self).__init__(desc)
|
|
||||||
|
|
||||||
def get_message(self):
|
|
||||||
return self._desc
|
|
||||||
|
|
||||||
|
|
||||||
class NoSuchMetric(BaseException):
|
class NoDataFound(WatcherException):
|
||||||
def __init__(self, desc):
|
msg_fmt = _('No rows were returned')
|
||||||
desc = desc or _("No such metric")
|
|
||||||
super(NoSuchMetric, self).__init__(desc)
|
|
||||||
|
|
||||||
def get_message(self):
|
|
||||||
return self._desc
|
|
||||||
|
|
||||||
|
|
||||||
class NoDataFound(BaseException):
|
|
||||||
def __init__(self, desc):
|
|
||||||
desc = desc or _("No rows were returned")
|
|
||||||
super(NoDataFound, self).__init__(desc)
|
|
||||||
|
|
||||||
def get_message(self):
|
|
||||||
return self._desc
|
|
||||||
|
|
||||||
|
|
||||||
class KeystoneFailure(WatcherException):
|
class KeystoneFailure(WatcherException):
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ class ModelRoot(object):
|
|||||||
def assert_hypervisor(self, obj):
|
def assert_hypervisor(self, obj):
|
||||||
if not isinstance(obj, hypervisor.Hypervisor):
|
if not isinstance(obj, hypervisor.Hypervisor):
|
||||||
raise exception.IllegalArgumentException(
|
raise exception.IllegalArgumentException(
|
||||||
_("'obj' argument type is not valid"))
|
message=_("'obj' argument type is not valid"))
|
||||||
|
|
||||||
def assert_vm(self, obj):
|
def assert_vm(self, obj):
|
||||||
if not isinstance(obj, vm.VM):
|
if not isinstance(obj, vm.VM):
|
||||||
raise exception.IllegalArgumentException(
|
raise exception.IllegalArgumentException(
|
||||||
_("'obj' argument type is not valid"))
|
message=_("'obj' argument type is not valid"))
|
||||||
|
|
||||||
def add_hypervisor(self, hypervisor):
|
def add_hypervisor(self, hypervisor):
|
||||||
self.assert_hypervisor(hypervisor)
|
self.assert_hypervisor(hypervisor)
|
||||||
|
|||||||
Reference in New Issue
Block a user