Add NotFound exception class
This class can be used by provider drivers to raise an exception when a resource cannot be found. Change-Id: If3d095f033f342ebb637d74bd834d373e31fee0f
This commit is contained in:
parent
bf1824a8b2
commit
684e0b9f55
|
@ -184,3 +184,30 @@ class DriverAgentTimeout(Exception):
|
||||||
self.fault_string = kwargs.pop('fault_string', self.fault_string)
|
self.fault_string = kwargs.pop('fault_string', self.fault_string)
|
||||||
super(DriverAgentTimeout, self).__init__(self.fault_string,
|
super(DriverAgentTimeout, self).__init__(self.fault_string,
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class NotFound(Exception):
|
||||||
|
"""Exception raised when the driver cannot find a resource.
|
||||||
|
|
||||||
|
This exception includes two strings: The user fault string and the
|
||||||
|
optional operator fault string. The user fault string,
|
||||||
|
"user_fault_string", will be provided to the API requester. The operator
|
||||||
|
fault string, "operator_fault_string", will be logged in the Octavia API
|
||||||
|
log file for the operator to use when debugging.
|
||||||
|
|
||||||
|
:param user_fault_string: String provided to the API requester.
|
||||||
|
:type user_fault_string: string
|
||||||
|
:param operator_fault_string: Optional string logged by the Octavia API
|
||||||
|
for the operator to use when debugging.
|
||||||
|
:type operator_fault_string: string
|
||||||
|
"""
|
||||||
|
user_fault_string = _("The provider driver could not find a resource.")
|
||||||
|
operator_fault_string = _("The provider driver could not find a resource.")
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.user_fault_string = kwargs.pop('user_fault_string',
|
||||||
|
self.user_fault_string)
|
||||||
|
self.operator_fault_string = kwargs.pop('operator_fault_string',
|
||||||
|
self.operator_fault_string)
|
||||||
|
super(NotFound, self).__init__(self.user_fault_string,
|
||||||
|
*args, **kwargs)
|
||||||
|
|
|
@ -487,6 +487,7 @@ class ProviderDriver():
|
||||||
:raises NotImplementedError: The driver does not support flavors.
|
:raises NotImplementedError: The driver does not support flavors.
|
||||||
:raises UnsupportedOptionError: if driver does not
|
:raises UnsupportedOptionError: if driver does not
|
||||||
support one of the configuration options.
|
support one of the configuration options.
|
||||||
|
:raises NotFound: if the driver cannot find a resource.
|
||||||
"""
|
"""
|
||||||
raise exceptions.NotImplementedError(
|
raise exceptions.NotImplementedError(
|
||||||
user_fault_string='This provider does not support validating '
|
user_fault_string='This provider does not support validating '
|
||||||
|
|
|
@ -86,3 +86,14 @@ class TestProviderExceptions(base.TestCase):
|
||||||
self.assertEqual(self.fault_object_id,
|
self.assertEqual(self.fault_object_id,
|
||||||
update_stats_error.stats_object_id)
|
update_stats_error.stats_object_id)
|
||||||
self.assertEqual(self.fault_record, update_stats_error.stats_record)
|
self.assertEqual(self.fault_record, update_stats_error.stats_record)
|
||||||
|
|
||||||
|
def test_NotFound(self):
|
||||||
|
not_found_error = exceptions.NotFound(
|
||||||
|
user_fault_string=self.user_fault_string,
|
||||||
|
operator_fault_string=self.operator_fault_string)
|
||||||
|
|
||||||
|
self.assertEqual(self.user_fault_string,
|
||||||
|
not_found_error.user_fault_string)
|
||||||
|
self.assertEqual(self.operator_fault_string,
|
||||||
|
not_found_error.operator_fault_string)
|
||||||
|
self.assertIsInstance(not_found_error, Exception)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Added a ``NotFound`` exception class that provider drivers can raise when
|
||||||
|
a resource cannot be found.
|
Loading…
Reference in New Issue