From 82a2fe4f7f35db7af094cc731ed3f621d37fe79e Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Mon, 10 Aug 2020 13:46:59 +0800 Subject: Follow up to I44336423194eed99f026c44b6390030a94ed0522 Allow using IPv6 address in the provisioning network. IP address based pxe config may not be used actually, in that case we can remove it and saving a few neutron interaction. Change-Id: Ideef57674550270a87513e039cd030f0bcc1c10e --- ironic/common/exception.py | 4 ++++ ironic/dhcp/neutron.py | 9 +++++---- ironic/tests/unit/dhcp/test_neutron.py | 26 +++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/ironic/common/exception.py b/ironic/common/exception.py index 1ade17253..912121a96 100644 --- a/ironic/common/exception.py +++ b/ironic/common/exception.py @@ -297,6 +297,10 @@ class InvalidIPv4Address(IronicException): _msg_fmt = _("Invalid IPv4 address %(ip_address)s.") +class InvalidIPAddress(IronicException): + _msg_fmt = _("Invalid IP address %(ip_address)s.") + + class FailedToUpdateMacOnPort(IronicException): _msg_fmt = _("Update MAC address on port: %(port_id)s failed.") diff --git a/ironic/dhcp/neutron.py b/ironic/dhcp/neutron.py index 372858742..bf42266c5 100644 --- a/ironic/dhcp/neutron.py +++ b/ironic/dhcp/neutron.py @@ -187,18 +187,19 @@ class NeutronDHCPApi(base.BaseDHCP): if ip_address: try: - if ipaddress.ip_address(ip_address).version == 4: + if (ipaddress.ip_address(ip_address).version == 4 + or ipaddress.ip_address(ip_address).version == 6): return ip_address else: - LOG.error("Neutron returned invalid IPv4 " + LOG.error("Neutron returned invalid IP " "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.InvalidIPAddress(ip_address=ip_address) except ValueError as exc: LOG.error("An Invalid IP address was supplied and failed " "basic validation: %s", exc) - raise exception.InvalidIPv4Address(ip_address=ip_address) + raise exception.InvalidIPAddress(ip_address=ip_address) else: LOG.error("No IP address assigned to Neutron port %s.", port_uuid) diff --git a/ironic/tests/unit/dhcp/test_neutron.py b/ironic/tests/unit/dhcp/test_neutron.py index e4091c58b..23a807da6 100644 --- a/ironic/tests/unit/dhcp/test_neutron.py +++ b/ironic/tests/unit/dhcp/test_neutron.py @@ -267,6 +267,30 @@ class TestNeutron(db_base.DbTestCase): self.assertEqual(expected, result) fake_client.show_port.assert_called_once_with(port_id) + def test__get_fixed_ip_address_ipv6(self): + port_id = 'fake-port-id' + expected = "2001:dead:beef::1234" + api = dhcp_factory.DHCPFactory().provider + port_data = { + "id": port_id, + "network_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "admin_state_up": True, + "status": "ACTIVE", + "mac_address": "fa:16:3e:4c:2c:30", + "fixed_ips": [ + { + "ip_address": "2001:dead:beef::1234", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "device_id": 'bece68a3-2f8b-4e66-9092-244493d6aba7', + } + fake_client = mock.Mock() + fake_client.show_port.return_value = {'port': port_data} + result = api._get_fixed_ip_address(port_id, fake_client) + self.assertEqual(expected, result) + fake_client.show_port.assert_called_once_with(port_id) + def test__get_fixed_ip_address_invalid_ip(self): port_id = 'fake-port-id' api = dhcp_factory.DHCPFactory().provider @@ -286,7 +310,7 @@ class TestNeutron(db_base.DbTestCase): } fake_client = mock.Mock() fake_client.show_port.return_value = {'port': port_data} - self.assertRaises(exception.InvalidIPv4Address, + self.assertRaises(exception.InvalidIPAddress, api._get_fixed_ip_address, port_id, fake_client) fake_client.show_port.assert_called_once_with(port_id) -- cgit v1.2.1