Merge "tests: confirm that _output_hosts_file does not log too often" into stable/juno
This commit is contained in:
commit
266e428c74
|
@ -518,13 +518,13 @@ class Dnsmasq(DhcpLocalProcess):
|
||||||
filename = self.get_conf_file_name('host')
|
filename = self.get_conf_file_name('host')
|
||||||
|
|
||||||
LOG.debug(_('Building host file: %s'), filename)
|
LOG.debug(_('Building host file: %s'), filename)
|
||||||
|
# NOTE(ihrachyshka): the loop should not log anything inside it, to
|
||||||
|
# avoid potential performance drop when lots of hosts are dumped
|
||||||
for (port, alloc, hostname, name) in self._iter_hosts():
|
for (port, alloc, hostname, name) in self._iter_hosts():
|
||||||
if not alloc:
|
if not alloc:
|
||||||
if getattr(port, 'extra_dhcp_opts', False):
|
if getattr(port, 'extra_dhcp_opts', False):
|
||||||
buf.write('%s,%s%s\n' %
|
buf.write('%s,%s%s\n' %
|
||||||
(port.mac_address, 'set:', port.id))
|
(port.mac_address, 'set:', port.id))
|
||||||
LOG.debug('Adding %(mac)s : set:%(tag)s',
|
|
||||||
{"mac": port.mac_address, "tag": port.id})
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# (dzyu) Check if it is legal ipv6 address, if so, need wrap
|
# (dzyu) Check if it is legal ipv6 address, if so, need wrap
|
||||||
|
@ -538,16 +538,9 @@ class Dnsmasq(DhcpLocalProcess):
|
||||||
buf.write('%s,%s,%s,%s%s\n' %
|
buf.write('%s,%s,%s,%s%s\n' %
|
||||||
(port.mac_address, name, ip_address,
|
(port.mac_address, name, ip_address,
|
||||||
'set:', port.id))
|
'set:', port.id))
|
||||||
LOG.debug('Adding %(mac)s : %(name)s : %(ip)s : '
|
|
||||||
'set:%(tag)s',
|
|
||||||
{"mac": port.mac_address, "name": name,
|
|
||||||
"ip": ip_address, "tag": port.id})
|
|
||||||
else:
|
else:
|
||||||
buf.write('%s,%s,%s\n' %
|
buf.write('%s,%s,%s\n' %
|
||||||
(port.mac_address, name, ip_address))
|
(port.mac_address, name, ip_address))
|
||||||
LOG.debug('Adding %(mac)s : %(name)s : %(ip)s',
|
|
||||||
{"mac": port.mac_address, "name": name,
|
|
||||||
"ip": ip_address})
|
|
||||||
|
|
||||||
utils.replace_file(filename, buf.getvalue())
|
utils.replace_file(filename, buf.getvalue())
|
||||||
LOG.debug('Done building host file %s with contents:\n%s', filename,
|
LOG.debug('Done building host file %s with contents:\n%s', filename,
|
||||||
|
|
|
@ -1427,6 +1427,17 @@ tag:tag0,option:router""".lstrip()
|
||||||
float(2.66))
|
float(2.66))
|
||||||
self.assertTrue(warning.called)
|
self.assertTrue(warning.called)
|
||||||
|
|
||||||
|
def test__output_hosts_file_log_only_twice(self):
|
||||||
|
dm = dhcp.Dnsmasq(self.conf, FakeDualStackNetworkSingleDHCP(),
|
||||||
|
version=dhcp.Dnsmasq.MINIMUM_VERSION)
|
||||||
|
with mock.patch.object(dhcp.LOG, 'process') as process:
|
||||||
|
process.return_value = ('fake_message', {})
|
||||||
|
dm._output_hosts_file()
|
||||||
|
# The method logs twice, at the start of and the end. There should be
|
||||||
|
# no other logs, no matter how many hosts there are to dump in the
|
||||||
|
# file.
|
||||||
|
self.assertEqual(2, process.call_count)
|
||||||
|
|
||||||
def test_only_populates_dhcp_enabled_subnets(self):
|
def test_only_populates_dhcp_enabled_subnets(self):
|
||||||
exp_host_name = '/dhcp/eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee/host'
|
exp_host_name = '/dhcp/eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee/host'
|
||||||
exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2.openstacklocal,'
|
exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2.openstacklocal,'
|
||||||
|
|
Loading…
Reference in New Issue