Browse Source

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
changes/75/738075/2
Carlos Goncalves 1 year ago
parent
commit
684e0b9f55
  1. 27
      octavia_lib/api/drivers/exceptions.py
  2. 1
      octavia_lib/api/drivers/provider_base.py
  3. 11
      octavia_lib/tests/unit/api/drivers/test_exceptions.py
  4. 5
      releasenotes/notes/add-not-found-exception-7f9d188cd22f69e1.yaml

27
octavia_lib/api/drivers/exceptions.py

@ -184,3 +184,30 @@ class DriverAgentTimeout(Exception):
self.fault_string = kwargs.pop('fault_string', self.fault_string)
super(DriverAgentTimeout, self).__init__(self.fault_string,
*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)

1
octavia_lib/api/drivers/provider_base.py

@ -487,6 +487,7 @@ class ProviderDriver():
:raises NotImplementedError: The driver does not support flavors.
:raises UnsupportedOptionError: if driver does not
support one of the configuration options.
:raises NotFound: if the driver cannot find a resource.
"""
raise exceptions.NotImplementedError(
user_fault_string='This provider does not support validating '

11
octavia_lib/tests/unit/api/drivers/test_exceptions.py

@ -86,3 +86,14 @@ class TestProviderExceptions(base.TestCase):
self.assertEqual(self.fault_object_id,
update_stats_error.stats_object_id)
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)

5
releasenotes/notes/add-not-found-exception-7f9d188cd22f69e1.yaml

@ -0,0 +1,5 @@
---
features:
- |
Added a ``NotFound`` exception class that provider drivers can raise when
a resource cannot be found.
Loading…
Cancel
Save