diff options
author | Kaifeng Wang <kaifeng.w@gmail.com> | 2020-08-10 13:46:59 +0800 |
---|---|---|
committer | Kaifeng Wang <kaifeng.w@gmail.com> | 2020-08-10 13:46:59 +0800 |
commit | 82a2fe4f7f35db7af094cc731ed3f621d37fe79e (patch) | |
tree | ee086b1c80c9ba83ea46d3af22b6d299acf8d020 | |
parent | 06094e16585357f0efde9344f40f14665f755c57 (diff) | |
download | ironic-82a2fe4f7f35db7af094cc731ed3f621d37fe79e.tar.gz |
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
-rw-r--r-- | ironic/common/exception.py | 4 | ||||
-rw-r--r-- | ironic/dhcp/neutron.py | 9 | ||||
-rw-r--r-- | 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) |