Merge "Add meaningful exception in Neutron port show"
This commit is contained in:
commit
9128cd6da8
@ -135,16 +135,16 @@ class NeutronDHCPApi(base.BaseDHCP):
|
|||||||
:param port_uuid: Neutron port id.
|
:param port_uuid: Neutron port id.
|
||||||
:param client: Neutron client instance.
|
:param client: Neutron client instance.
|
||||||
:returns: Neutron port ip address.
|
:returns: Neutron port ip address.
|
||||||
:raises: FailedToGetIPAddressOnPort
|
:raises: NetworkError
|
||||||
:raises: InvalidIPv4Address
|
:raises: InvalidIPv4Address
|
||||||
|
:raises: FailedToGetIPAddressOnPort
|
||||||
"""
|
"""
|
||||||
ip_address = None
|
ip_address = None
|
||||||
try:
|
try:
|
||||||
neutron_port = client.show_port(port_uuid).get('port')
|
neutron_port = client.show_port(port_uuid).get('port')
|
||||||
except neutron_client_exc.NeutronClientException:
|
except neutron_client_exc.NeutronClientException:
|
||||||
LOG.exception("Failed to Get IP address on Neutron port %s.",
|
raise exception.NetworkError(
|
||||||
port_uuid)
|
_('Could not retrieve neutron port: %s') % port_uuid)
|
||||||
raise exception.FailedToGetIPAddressOnPort(port_id=port_uuid)
|
|
||||||
|
|
||||||
fixed_ips = neutron_port.get('fixed_ips')
|
fixed_ips = neutron_port.get('fixed_ips')
|
||||||
|
|
||||||
@ -158,8 +158,9 @@ class NeutronDHCPApi(base.BaseDHCP):
|
|||||||
if netutils.is_valid_ipv4(ip_address):
|
if netutils.is_valid_ipv4(ip_address):
|
||||||
return ip_address
|
return ip_address
|
||||||
else:
|
else:
|
||||||
LOG.error("Neutron returned invalid IPv4 address %s.",
|
LOG.error("Neutron returned invalid IPv4 "
|
||||||
ip_address)
|
"address %(ip_address)s on port %(port_uuid)s.",
|
||||||
|
{'ip_address': ip_address, 'port_uuid': port_uuid})
|
||||||
raise exception.InvalidIPv4Address(ip_address=ip_address)
|
raise exception.InvalidIPv4Address(ip_address=ip_address)
|
||||||
else:
|
else:
|
||||||
LOG.error("No IP address assigned to Neutron port %s.",
|
LOG.error("No IP address assigned to Neutron port %s.",
|
||||||
@ -209,7 +210,8 @@ class NeutronDHCPApi(base.BaseDHCP):
|
|||||||
client)
|
client)
|
||||||
ip_addresses.append(vif_ip_address)
|
ip_addresses.append(vif_ip_address)
|
||||||
except (exception.FailedToGetIPAddressOnPort,
|
except (exception.FailedToGetIPAddressOnPort,
|
||||||
exception.InvalidIPv4Address):
|
exception.InvalidIPv4Address,
|
||||||
|
exception.NetworkError):
|
||||||
failures.append(obj.uuid)
|
failures.append(obj.uuid)
|
||||||
|
|
||||||
if failures:
|
if failures:
|
||||||
|
@ -238,7 +238,7 @@ class TestNeutron(db_base.DbTestCase):
|
|||||||
fake_client = mock.Mock()
|
fake_client = mock.Mock()
|
||||||
fake_client.show_port.side_effect = (
|
fake_client.show_port.side_effect = (
|
||||||
neutron_client_exc.NeutronClientException())
|
neutron_client_exc.NeutronClientException())
|
||||||
self.assertRaises(exception.FailedToGetIPAddressOnPort,
|
self.assertRaises(exception.NetworkError,
|
||||||
api._get_fixed_ip_address, port_id, fake_client)
|
api._get_fixed_ip_address, port_id, fake_client)
|
||||||
fake_client.show_port.assert_called_once_with(port_id)
|
fake_client.show_port.assert_called_once_with(port_id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user