Remove reliance on NeutronException message field

The 'message' class member in Exception was deprecated in PY2.6 and
removed in PY3.0 [1]. Should Neutron code abandon its use of this
field, it will break current Octavia code.
This patch shields Octavia of such change, replacing exc.message
calls with exc.__str__().

[1] - https://www.python.org/dev/peps/pep-0352/

Change-Id: Ia7836f0d68e20d9964334bc41f7789efd1007939
This commit is contained in:
Bar RH 2017-12-14 04:33:10 +02:00
parent 51f6f7258b
commit 32206f77f6
4 changed files with 29 additions and 29 deletions

View File

@ -35,6 +35,7 @@ import octavia.common.validate as validate
from octavia.db import api as db_api
from octavia.db import prepare as db_prepare
from octavia.i18n import _
from octavia.network import base as network_base
CONF = cfg.CONF
@ -211,16 +212,15 @@ class LoadBalancersController(base.BaseController):
"""Create vip port."""
network_driver = utils.get_network_driver()
try:
vip = network_driver.allocate_vip(load_balancer_db)
except Exception as e:
return network_driver.allocate_vip(load_balancer_db)
except network_base.AllocateVIPException as e:
# Convert neutron style exception to octavia style
# if the error was API ready
if e.orig_code is not None:
if getattr(e, 'orig_code', None) is not None:
e.code = e.orig_code
e.message = e.orig_msg
e.msg = e.orig_msg
raise e
return vip
@wsme_pecan.wsexpose(lb_types.LoadBalancerFullRootResponse,
body=lb_types.LoadBalancerRootPOST, status_code=201)

View File

@ -110,7 +110,7 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
try:
self._add_allowed_address_pair_to_port(port_id, vip_address)
except neutron_client_exceptions.PortNotFoundClient as e:
raise base.PortNotFound(e.message)
raise base.PortNotFound(str(e))
except Exception:
message = _('Error adding allowed address pair {ip} '
'to port {port_id}.').format(ip=vip_address,
@ -378,7 +378,8 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
raise base.AllocateVIPException(
message,
orig_msg=getattr(e, 'message', None),
orig_code=getattr(e, 'status_code', None))
orig_code=getattr(e, 'status_code', None),
)
new_port = utils.convert_port_dict_to_model(new_port)
return self._port_to_vip(new_port, load_balancer)
@ -438,12 +439,12 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
server=compute_id, net_id=network_id, fixed_ip=ip_address,
port_id=None)
except nova_client_exceptions.NotFound as e:
if 'Instance' in e.message:
raise base.AmphoraNotFound(e.message)
elif 'Network' in e.message:
raise base.NetworkNotFound(e.message)
if 'Instance' in str(e):
raise base.AmphoraNotFound(str(e))
elif 'Network' in str(e):
raise base.NetworkNotFound(str(e))
else:
raise base.PlugNetworkException(e.message)
raise base.PlugNetworkException(str(e))
except Exception:
message = _('Error plugging amphora (compute_id: {compute_id}) '
'into network {network_id}.').format(
@ -512,12 +513,12 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
plugged_interface = self._nova_interface_to_octavia_interface(
amphora.compute_id, interface)
except nova_client_exceptions.NotFound as e:
if 'Instance' in e.message:
raise base.AmphoraNotFound(e.message)
elif 'Network' in e.message:
raise base.NetworkNotFound(e.message)
if 'Instance' in str(e):
raise base.AmphoraNotFound(str(e))
elif 'Network' in str(e):
raise base.NetworkNotFound(str(e))
else:
raise base.PlugNetworkException(e.message)
raise base.PlugNetworkException(str(e))
except nova_client_exceptions.Conflict:
LOG.info('Port %(portid)s is already plugged, '
'skipping', {'portid': port.id})

View File

@ -111,7 +111,7 @@ class BaseNeutronDriver(base.AbstractNetworkDriver):
try:
self.neutron_client.update_port(port_id, port_update)
except neutron_client_exceptions.PortNotFoundClient as e:
raise base.PortNotFound(e.message)
raise base.PortNotFound(str(e))
except Exception as e:
raise base.NetworkException(str(e))
@ -143,7 +143,7 @@ class BaseNeutronDriver(base.AbstractNetworkDriver):
try:
self.neutron_client.update_port(port_id, body)
except neutron_client_exceptions.PortNotFoundClient as e:
raise base.PortNotFound(e.message)
raise base.PortNotFound(str(e))
except Exception as e:
raise base.NetworkException(str(e))

View File

@ -434,6 +434,16 @@ class TestLoadBalancer(base.BaseAPITest):
self.assertEqual(port.id, api_lb.get('vip_port_id'))
def test_create_neutron_failure(self):
class TestNeutronException(network_base.AllocateVIPException):
def __init__(self, message, orig_msg, orig_code):
super(TestNeutronException, self).__init__(
message, orig_msg=orig_msg, orig_code=orig_code,
)
def __str__(self):
return repr(self.message)
subnet = network_models.Subnet(id=uuidutils.generate_uuid())
network = network_models.Network(id=uuidutils.generate_uuid(),
subnets=[subnet])
@ -2796,14 +2806,3 @@ class TestLoadBalancerGraph(base.BaseAPITest):
self.conf.config(group='api_settings', auth_strategy=auth_strategy)
self.assertEqual(self.NOT_AUTHORIZED_BODY, res.json)
class TestNeutronException(Exception):
def __init__(self, message, orig_msg, orig_code):
self.message = message
self.orig_msg = orig_msg
self.orig_code = orig_code
def __str__(self):
return repr(self.message)