Fix catching driver exceptions
octavia_lib driver exceptions were not cought by call_provider This patch add those exceptions, and also handles the native NotImplementedError which does nto have all the expected fields. Change-Id: I1a566353b7fb125184849b3a0f864d3ef6896d94
This commit is contained in:
parent
c5b2777537
commit
e2defa6dd2
@ -16,6 +16,7 @@ import copy
|
||||
|
||||
import six
|
||||
|
||||
from octavia_lib.api.drivers import exceptions as lib_exceptions
|
||||
from oslo_config import cfg
|
||||
from oslo_context import context as oslo_context
|
||||
from oslo_log import log as logging
|
||||
@ -48,17 +49,28 @@ def call_provider(provider, driver_method, *args, **kwargs):
|
||||
|
||||
try:
|
||||
return driver_method(*args, **kwargs)
|
||||
except driver_exceptions.DriverError as e:
|
||||
except (driver_exceptions.DriverError, lib_exceptions.DriverError) as e:
|
||||
LOG.exception("Provider '%s' raised a driver error: %s",
|
||||
provider, e.operator_fault_string)
|
||||
raise exceptions.ProviderDriverError(prov=provider,
|
||||
user_msg=e.user_fault_string)
|
||||
except (driver_exceptions.NotImplementedError, NotImplementedError) as e:
|
||||
except (driver_exceptions.NotImplementedError,
|
||||
lib_exceptions.NotImplementedError,
|
||||
NotImplementedError) as e:
|
||||
op_fault_string = (
|
||||
e.operator_fault_string
|
||||
if hasattr(e, "operator_fault_string")
|
||||
else _("This feature is not implemented by this provider."))
|
||||
usr_fault_string = (
|
||||
e.user_fault_string
|
||||
if hasattr(e, "user_fault_string")
|
||||
else _("This feature is not implemented by the provider."))
|
||||
LOG.info("Provider '%s' raised a not implemented error: %s",
|
||||
provider, e.operator_fault_string)
|
||||
provider, op_fault_string)
|
||||
raise exceptions.ProviderNotImplementedError(
|
||||
prov=provider, user_msg=e.user_fault_string)
|
||||
except driver_exceptions.UnsupportedOptionError as e:
|
||||
prov=provider, user_msg=usr_fault_string)
|
||||
except (driver_exceptions.UnsupportedOptionError,
|
||||
lib_exceptions.UnsupportedOptionError) as e:
|
||||
LOG.info("Provider '%s' raised an unsupported option error: "
|
||||
"%s", provider, e.operator_fault_string)
|
||||
raise exceptions.ProviderUnsupportedOptionError(
|
||||
|
@ -16,6 +16,8 @@ import copy
|
||||
|
||||
import mock
|
||||
|
||||
from octavia_lib.api.drivers import exceptions as lib_exceptions
|
||||
|
||||
from octavia.api.drivers import data_models as driver_dm
|
||||
from octavia.api.drivers import exceptions as driver_exceptions
|
||||
from octavia.api.drivers import utils
|
||||
@ -39,24 +41,41 @@ class TestUtils(base.TestCase):
|
||||
"arg1", foo="arg2")
|
||||
mock_driver_method.assert_called_with("arg1", foo="arg2")
|
||||
|
||||
# Test driver raising DriverError
|
||||
# Test driver raising different types of DriverError
|
||||
mock_driver_method.side_effect = driver_exceptions.DriverError
|
||||
self.assertRaises(exceptions.ProviderDriverError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
mock_driver_method.side_effect = lib_exceptions.DriverError
|
||||
self.assertRaises(exceptions.ProviderDriverError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
|
||||
# Test driver raising NotImplementedError
|
||||
# Test driver raising different types of NotImplementedError
|
||||
mock_driver_method.side_effect = driver_exceptions.NotImplementedError
|
||||
self.assertRaises(exceptions.ProviderNotImplementedError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
mock_driver_method.side_effect = NotImplementedError
|
||||
self.assertRaises(exceptions.ProviderNotImplementedError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
mock_driver_method.side_effect = lib_exceptions.NotImplementedError
|
||||
self.assertRaises(exceptions.ProviderNotImplementedError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
|
||||
# Test driver raising UnsupportedOptionError
|
||||
# Test driver raising different types of UnsupportedOptionError
|
||||
mock_driver_method.side_effect = (
|
||||
driver_exceptions.UnsupportedOptionError)
|
||||
self.assertRaises(exceptions.ProviderUnsupportedOptionError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
mock_driver_method.side_effect = (
|
||||
lib_exceptions.UnsupportedOptionError)
|
||||
self.assertRaises(exceptions.ProviderUnsupportedOptionError,
|
||||
utils.call_provider, "provider_name",
|
||||
mock_driver_method)
|
||||
|
||||
# Test driver raising DriverError
|
||||
mock_driver_method.side_effect = Exception
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed an issue where the driver errors were not caught.
|
Loading…
Reference in New Issue
Block a user