From b256cae8e204fbbf6f3d40f5f4d47013be018a6d Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 27 Apr 2016 09:47:59 -0400 Subject: [PATCH] Only reset dns_name when unbinding port if DNS is integrated We only set the dns_name on the port if the "DNS Integration" extension is enabled, so we should only reset it on the port when unbinding if the extension is enabled, otherwise some Neutron stadium plugins will fail since they don't expect the 'dns_name' attribute to be on the port. Change-Id: I7451fbfad53236e9e147a0387dac45ae97f3e75b Closes-Bug: #1574565 --- nova/network/neutronv2/api.py | 5 +++-- nova/tests/unit/network/test_neutronv2.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index 4163abcf26..1cbf1d412c 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -315,11 +315,12 @@ class API(base_api.NetworkAPI): # in case the caller forgot to filter the list. if port_id is None: continue - port_req_body = {'port': {'device_id': '', 'device_owner': '', - 'dns_name': ''}} + port_req_body = {'port': {'device_id': '', 'device_owner': ''}} if port_binding: port_req_body['port']['binding:host_id'] = None port_req_body['port']['binding:profile'] = {} + if constants.DNS_INTEGRATION in self.extensions: + port_req_body['port']['dns_name'] = '' try: port_client.update_port(port_id, port_req_body) except Exception: diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py index 5a53f82e32..e36d62c25a 100644 --- a/nova/tests/unit/network/test_neutronv2.py +++ b/nova/tests/unit/network/test_neutronv2.py @@ -3548,7 +3548,7 @@ class TestNeutronv2WithMock(test.TestCase): api = neutronapi.API() api._unbind_ports(mock_ctx, ports, mock_client) - body = {'port': {'device_id': '', 'device_owner': '', 'dns_name': ''}} + body = {'port': {'device_id': '', 'device_owner': ''}} if has_ext: body['port']['binding:host_id'] = None body['port']['binding:profile'] = {} @@ -3828,6 +3828,20 @@ class TestNeutronv2WithMock(test.TestCase): self.api.get_floating_ips_by_project, self.context) + def test_unbind_ports_reset_dns_name(self): + neutron = mock.Mock() + port_client = mock.Mock() + with mock.patch.object(self.api, '_has_port_binding_extension', + return_value=False): + self.api.extensions = [constants.DNS_INTEGRATION] + ports = [uuids.port_id] + self.api._unbind_ports(self.context, ports, neutron, port_client) + port_req_body = {'port': {'device_id': '', + 'device_owner': '', + 'dns_name': ''}} + port_client.update_port.assert_called_once_with( + uuids.port_id, port_req_body) + class TestNeutronv2ModuleMethods(test.NoDBTestCase):