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):