From 77a596ab7c3f0015f71b4e8a359478141807d11e Mon Sep 17 00:00:00 2001 From: Jens Harbott Date: Sat, 2 Sep 2017 08:00:51 +0000 Subject: [PATCH] Fix port deletion when dns_integration is enabled The records found in ip_allocations contain objects of type IPAddress, but the external dns service expects them as string, so we need to insert a conversion. Change-Id: I622993fc273121bfd051d2fd9c7811e2ae49a1d8 Closes-Bug: 1714641 (cherry picked from commit 22d6a1540f6ab9029c85781d2a2cb8c7c39299c7) --- neutron/plugins/ml2/extensions/dns_integration.py | 2 +- neutron/services/externaldns/drivers/designate/driver.py | 2 +- .../unit/plugins/ml2/extensions/test_dns_integration.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/neutron/plugins/ml2/extensions/dns_integration.py b/neutron/plugins/ml2/extensions/dns_integration.py index c44d7b11685..79cba57b1d4 100644 --- a/neutron/plugins/ml2/extensions/dns_integration.py +++ b/neutron/plugins/ml2/extensions/dns_integration.py @@ -510,7 +510,7 @@ def _delete_port_in_external_dns_service(resource, event, trigger, **kwargs): if dns_data_db['current_dns_name']: ip_allocations = port_obj.IPAllocation.get_objects(context, port_id=port_id) - records = [alloc['ip_address'] for alloc in ip_allocations] + records = [str(alloc['ip_address']) for alloc in ip_allocations] _remove_data_from_external_dns_service( context, dns_driver, dns_data_db['current_dns_domain'], dns_data_db['current_dns_name'], records) diff --git a/neutron/services/externaldns/drivers/designate/driver.py b/neutron/services/externaldns/drivers/designate/driver.py index 4eda5b4df41..9ff2390e175 100644 --- a/neutron/services/externaldns/drivers/designate/driver.py +++ b/neutron/services/externaldns/drivers/designate/driver.py @@ -167,7 +167,7 @@ class Designate(driver.ExternalDNSService): except d_exc.NotFound: raise dns.DNSDomainNotFound(dns_domain=dns_domain) ids = [rec['id'] for rec in recordsets] - ips = [ip for rec in recordsets for ip in rec['records']] + ips = [str(ip) for rec in recordsets for ip in rec['records']] if set(ips) != set(records): raise dns.DuplicateRecordSet(dns_name=name) return ids diff --git a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py index 6837f977dc3..7a7a75dc711 100644 --- a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py +++ b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py @@ -123,10 +123,10 @@ class DNSIntegrationTestCase(test_plugin.Ml2PluginV2TestCase): def _update_port_for_test(self, port, new_dns_name=NEWDNSNAME, new_dns_domain=None, **kwargs): mock_client.reset_mock() - records_v4 = [ip['ip_address'] for ip in port['fixed_ips'] - if netaddr.IPAddress(ip['ip_address']).version == 4] - records_v6 = [ip['ip_address'] for ip in port['fixed_ips'] - if netaddr.IPAddress(ip['ip_address']).version == 6] + ip_addresses = [netaddr.IPAddress(ip['ip_address']) + for ip in port['fixed_ips']] + records_v4 = [ip for ip in ip_addresses if ip.version == 4] + records_v6 = [ip for ip in ip_addresses if ip.version == 6] recordsets = [] if records_v4: recordsets.append({'id': V4UUID, 'records': records_v4})