From e2e9b763a829ca9c7bb3df8622b3e22d3829b39b Mon Sep 17 00:00:00 2001 From: Dongcan Ye Date: Mon, 15 Jan 2018 12:58:45 +0000 Subject: [PATCH] Add meaningful exception in Neutron port show We had already defined an exception FailedToGetIPAddressOnPort if not get fixed_ips, for the neutron port show we can add some meaningful exception. Change-Id: I242da01fdf703f7c52e51aa5236209edea37c856 --- ironic/dhcp/neutron.py | 16 +++++++++------- ironic/tests/unit/dhcp/test_neutron.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ironic/dhcp/neutron.py b/ironic/dhcp/neutron.py index 27c4366d0e..0ac34877f3 100644 --- a/ironic/dhcp/neutron.py +++ b/ironic/dhcp/neutron.py @@ -135,16 +135,16 @@ class NeutronDHCPApi(base.BaseDHCP): :param port_uuid: Neutron port id. :param client: Neutron client instance. :returns: Neutron port ip address. - :raises: FailedToGetIPAddressOnPort + :raises: NetworkError :raises: InvalidIPv4Address + :raises: FailedToGetIPAddressOnPort """ ip_address = None try: neutron_port = client.show_port(port_uuid).get('port') except neutron_client_exc.NeutronClientException: - LOG.exception("Failed to Get IP address on Neutron port %s.", - port_uuid) - raise exception.FailedToGetIPAddressOnPort(port_id=port_uuid) + raise exception.NetworkError( + _('Could not retrieve neutron port: %s') % port_uuid) fixed_ips = neutron_port.get('fixed_ips') @@ -158,8 +158,9 @@ class NeutronDHCPApi(base.BaseDHCP): if netutils.is_valid_ipv4(ip_address): return ip_address else: - LOG.error("Neutron returned invalid IPv4 address %s.", - ip_address) + LOG.error("Neutron returned invalid IPv4 " + "address %(ip_address)s on port %(port_uuid)s.", + {'ip_address': ip_address, 'port_uuid': port_uuid}) raise exception.InvalidIPv4Address(ip_address=ip_address) else: LOG.error("No IP address assigned to Neutron port %s.", @@ -209,7 +210,8 @@ class NeutronDHCPApi(base.BaseDHCP): client) ip_addresses.append(vif_ip_address) except (exception.FailedToGetIPAddressOnPort, - exception.InvalidIPv4Address): + exception.InvalidIPv4Address, + exception.NetworkError): failures.append(obj.uuid) if failures: diff --git a/ironic/tests/unit/dhcp/test_neutron.py b/ironic/tests/unit/dhcp/test_neutron.py index ac7fee7f0a..641544f1c1 100644 --- a/ironic/tests/unit/dhcp/test_neutron.py +++ b/ironic/tests/unit/dhcp/test_neutron.py @@ -238,7 +238,7 @@ class TestNeutron(db_base.DbTestCase): fake_client = mock.Mock() fake_client.show_port.side_effect = ( neutron_client_exc.NeutronClientException()) - self.assertRaises(exception.FailedToGetIPAddressOnPort, + self.assertRaises(exception.NetworkError, api._get_fixed_ip_address, port_id, fake_client) fake_client.show_port.assert_called_once_with(port_id)