Browse Source

Remove deprecated exception classes

These classes were deprecated in Stein and marked for removal in Ussuri.
By removing these classes, we fix pep8 issues (catching-non-exception)
we started seeing at the gate with the release of astroid 2.4.0.

Change-Id: I66b2d0687f4edfbcbff99c29c9c5d539e4e7ea7f
changes/04/723604/2
Carlos Goncalves 2 years ago
parent
commit
0056b5175f
  1. 41
      octavia/api/drivers/exceptions.py
  2. 10
      octavia/api/drivers/utils.py
  3. 6
      octavia/api/v2/controllers/provider.py
  4. 8
      octavia/tests/functional/api/v2/test_load_balancer.py
  5. 6
      octavia/tests/functional/api/v2/test_provider.py
  6. 20
      octavia/tests/unit/api/drivers/test_utils.py

41
octavia/api/drivers/exceptions.py

@ -1,41 +0,0 @@
# Copyright 2018 Rackspace, US Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import warnings
from debtcollector import moves
from octavia_lib.api.drivers import exceptions as lib_exceptions
warnings.simplefilter('default', DeprecationWarning)
DriverError = moves.moved_class(lib_exceptions.DriverError, 'DriverError',
__name__, version='Stein', removal_version='U')
NotImplementedError = moves.moved_class(
lib_exceptions.NotImplementedError, 'NotImplementedError', __name__,
version='Stein', removal_version='U')
UnsupportedOptionError = moves.moved_class(
lib_exceptions.UnsupportedOptionError, 'UnsupportedOptionError', __name__,
version='Stein', removal_version='U')
UpdateStatusError = moves.moved_class(
lib_exceptions.UpdateStatusError, 'UpdateStatusError', __name__,
version='Stein', removal_version='U')
UpdateStatisticsError = moves.moved_class(
lib_exceptions.UpdateStatisticsError, 'UpdateStatisticsError', __name__,
version='Stein', removal_version='U')

10
octavia/api/drivers/utils.py

@ -22,7 +22,6 @@ from oslo_log import log as logging
from oslo_utils import excutils
from stevedore import driver as stevedore_driver
from octavia.api.drivers import exceptions as driver_exceptions
from octavia.common import data_models
from octavia.common import exceptions
from octavia.common.tls_utils import cert_parser
@ -50,14 +49,12 @@ def call_provider(provider, driver_method, *args, **kwargs):
try:
return driver_method(*args, **kwargs)
except (driver_exceptions.DriverError, lib_exceptions.DriverError) as e:
except 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,
lib_exceptions.NotImplementedError,
NotImplementedError) as e:
except (lib_exceptions.NotImplementedError, NotImplementedError) as e:
op_fault_string = (
e.operator_fault_string
if hasattr(e, "operator_fault_string")
@ -70,8 +67,7 @@ def call_provider(provider, driver_method, *args, **kwargs):
provider, op_fault_string)
raise exceptions.ProviderNotImplementedError(
prov=provider, user_msg=usr_fault_string)
except (driver_exceptions.UnsupportedOptionError,
lib_exceptions.UnsupportedOptionError) as e:
except lib_exceptions.UnsupportedOptionError as e:
LOG.info("Provider '%s' raised an unsupported option error: "
"%s", provider, e.operator_fault_string)
raise exceptions.ProviderUnsupportedOptionError(

6
octavia/api/v2/controllers/provider.py

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from octavia_lib.api.drivers import exceptions as lib_exceptions
from oslo_config import cfg
from oslo_log import log as logging
from pecan import expose as pecan_expose
@ -20,7 +21,6 @@ from wsme import types as wtypes
from wsmeext import pecan as wsme_pecan
from octavia.api.drivers import driver_factory
from octavia.api.drivers import exceptions as driver_except
from octavia.api.v2.controllers import base
from octavia.api.v2.types import provider as provider_types
from octavia.common import constants
@ -89,7 +89,7 @@ class FlavorCapabilitiesController(base.BaseController):
self.driver = driver_factory.get_driver(self.provider)
try:
metadata_dict = self.driver.get_supported_flavor_metadata()
except driver_except.NotImplementedError as e:
except lib_exceptions.NotImplementedError as e:
LOG.warning('Provider %s get_supported_flavor_metadata() '
'reported: %s', self.provider, e.operator_fault_string)
raise exceptions.ProviderNotImplementedError(
@ -140,7 +140,7 @@ class AvailabilityZoneCapabilitiesController(base.BaseController):
try:
metadata_dict = (
self.driver.get_supported_availability_zone_metadata())
except driver_except.NotImplementedError as e:
except lib_exceptions.NotImplementedError as e:
LOG.warning(
'Provider %s get_supported_availability_zone_metadata() '
'reported: %s', self.provider, e.operator_fault_string)

8
octavia/tests/functional/api/v2/test_load_balancer.py

@ -16,12 +16,12 @@ import copy
import random
from unittest import mock
from octavia_lib.api.drivers import exceptions as lib_exceptions
from oslo_config import cfg
from oslo_config import fixture as oslo_fixture
from oslo_utils import uuidutils
from sqlalchemy.orm import exc as sa_exception
from octavia.api.drivers import exceptions as provider_exceptions
from octavia.common import constants
import octavia.common.context
from octavia.common import data_models
@ -459,8 +459,7 @@ class TestLoadBalancer(base.BaseAPITest):
"create_vip_port") as mock_provider:
mock_get_network.return_value = network
mock_get_port.return_value = port
mock_provider.side_effect = (provider_exceptions.
NotImplementedError())
mock_provider.side_effect = lib_exceptions.NotImplementedError()
response = self.post(self.LBS_PATH, body)
api_lb = response.json.get(self.root_tag)
self._assert_request_matches_response(lb_json, api_lb)
@ -621,8 +620,7 @@ class TestLoadBalancer(base.BaseAPITest):
mock_get_port.return_value = port
mock_allocate_vip.side_effect = TestNeutronException(
"octavia_msg", "neutron_msg", 409)
mock_provider.side_effect = (provider_exceptions.
NotImplementedError())
mock_provider.side_effect = lib_exceptions.NotImplementedError()
response = self.post(self.LBS_PATH, body, status=409)
# Make sure the faultstring contains the neutron error and not
# the octavia error message

6
octavia/tests/functional/api/v2/test_provider.py

@ -15,11 +15,11 @@
from unittest import mock
from octavia_lib.api.drivers import exceptions as lib_exceptions
from oslo_config import cfg
from oslo_config import fixture as oslo_fixture
from oslo_utils import uuidutils
from octavia.api.drivers import exceptions
from octavia.common import constants
import octavia.common.context
from octavia.tests.functional.api.v2 import base
@ -90,7 +90,7 @@ class TestFlavorCapabilities(base.BaseAPITest):
@mock.patch('octavia.api.drivers.noop_driver.driver.NoopProviderDriver.'
'get_supported_flavor_metadata')
def test_not_implemented(self, mock_get_metadata):
mock_get_metadata.side_effect = exceptions.NotImplementedError()
mock_get_metadata.side_effect = lib_exceptions.NotImplementedError()
self.get(self.FLAVOR_CAPABILITIES_PATH.format(provider='noop_driver'),
status=501)
@ -214,7 +214,7 @@ class TestAvailabilityZoneCapabilities(base.BaseAPITest):
@mock.patch('octavia.api.drivers.noop_driver.driver.NoopProviderDriver.'
'get_supported_availability_zone_metadata')
def test_not_implemented(self, mock_get_metadata):
mock_get_metadata.side_effect = exceptions.NotImplementedError()
mock_get_metadata.side_effect = lib_exceptions.NotImplementedError()
self.get(self.AVAILABILITY_ZONE_CAPABILITIES_PATH.format(
provider='noop_driver'), status=501)

20
octavia/tests/unit/api/drivers/test_utils.py

@ -18,7 +18,6 @@ from octavia_lib.api.drivers import data_models as driver_dm
from octavia_lib.api.drivers import exceptions as lib_exceptions
from octavia_lib.common import constants as lib_constants
from octavia.api.drivers import exceptions as driver_exceptions
from octavia.api.drivers import utils
from octavia.common import constants
from octavia.common import data_models
@ -40,21 +39,13 @@ class TestUtils(base.TestCase):
"arg1", foo="arg2")
mock_driver_method.assert_called_with("arg1", foo="arg2")
# 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)
# Test driver raising DriverError
mock_driver_method.side_effect = lib_exceptions.DriverError
self.assertRaises(exceptions.ProviderDriverError,
utils.call_provider, "provider_name",
mock_driver_method)
# 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",
@ -64,19 +55,14 @@ class TestUtils(base.TestCase):
utils.call_provider, "provider_name",
mock_driver_method)
# 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)
# Test driver raising UnsupportedOptionError
mock_driver_method.side_effect = (
lib_exceptions.UnsupportedOptionError)
self.assertRaises(exceptions.ProviderUnsupportedOptionError,
utils.call_provider, "provider_name",
mock_driver_method)
# Test driver raising DriverError
# Test driver raising ProviderDriverError
mock_driver_method.side_effect = Exception
self.assertRaises(exceptions.ProviderDriverError,
utils.call_provider, "provider_name",

Loading…
Cancel
Save