commit 8654eb2d183cf13699e50b8b967a6c52412602ac Author: Dan Radez Date: Wed Sep 30 11:00:07 2020 -0400 Default dnsmasq --conf-file to /dev/null Passing --conf-file= with no value has no effect on the dnsmasq process. Intended effect here is for the default system dnsmasq.conf file not to be read and included in configuring the process. For that to happen some value has to be passed to --conf-file. Passing /dev/null will invoke the desired outcome to skip the system default conf file. Closes-Bug: #1896945 Change-Id: I22570a44f84d14a792633747c04d7426ab231009 (cherry picked from commit 704576e54e041340ed9c2964b110815e074239a6) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index a7d2d5f..2e8f513 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -424,7 +424,8 @@ class Dnsmasq(DhcpLocalProcess): cmd.append('--dhcp-option-force=option:T2,%ds' % self.conf.dhcp_rebinding_time) - cmd.append('--conf-file=%s' % self.conf.dnsmasq_config_file) + cmd.append('--conf-file=%s' % + (self.conf.dnsmasq_config_file.strip() or '/dev/null')) for server in self.conf.dnsmasq_dns_servers: cmd.append('--server=%s' % server) diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index eb4485e..73e803c 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1286,6 +1286,21 @@ class TestDnsmasq(TestBase): def mock_get_conf_file_name(kind): return '/dhcp/%s/%s' % (network.id, kind) + # Empty string passed to --conf-file in dnsmasq is invalid + # we must force '' to '/dev/null' because the dhcp agent + # does the same. Therefore we allow empty string to + # be passed to neutron but not to dnsmasq. + def check_conf_file_empty(cmd_list): + for i in cmd_list: + conf_file = '' + value = '' + if i.startswith('--conf-file='): + conf_file = i + value = i[12:].strip() + if not value: + idx = cmd_list.index(conf_file) + cmd_list[idx] = '--conf-file=/dev/null' + # if you need to change this path here, think twice, # that means pid files will move around, breaking upgrades # or backwards-compatibility @@ -1347,7 +1362,9 @@ class TestDnsmasq(TestBase): expected.append('--dhcp-option-force=option:T1,%ds' % dhcp_t1) if dhcp_t2: expected.append('--dhcp-option-force=option:T2,%ds' % dhcp_t2) + expected.extend(extra_options) + check_conf_file_empty(expected) self.execute.return_value = ('', '')