Cleanup dead code for dnsmasq

In fix of bug 1202392, there was dead code left [1]. This patch
cleans them up.

[1] https://review.openstack.org/#/c/37580/

Change-Id: I02edb9ce6ac639e84089afea5a900462e61b934a
This commit is contained in:
Han Zhou 2015-02-03 13:36:23 +08:00 committed by Carl Baldwin
parent a812664fd0
commit aede59641c
3 changed files with 15 additions and 59 deletions

View File

@ -9,7 +9,7 @@
[Filters] [Filters]
# dhcp-agent # dhcp-agent
dnsmasq: EnvFilter, dnsmasq, root, NEUTRON_NETWORK_ID= dnsmasq: CommandFilter, dnsmasq, root
# dhcp-agent uses kill as well, that's handled by the generic KillFilter # dhcp-agent uses kill as well, that's handled by the generic KillFilter
# it looks like these are the only signals needed, per # it looks like these are the only signals needed, per
# neutron/agent/linux/dhcp.py # neutron/agent/linux/dhcp.py

View File

@ -18,11 +18,8 @@ import collections
import os import os
import re import re
import shutil import shutil
import socket
import sys
import netaddr import netaddr
from oslo_serialization import jsonutils
from oslo_utils import importutils from oslo_utils import importutils
import six import six
@ -286,9 +283,6 @@ class Dnsmasq(DhcpLocalProcess):
_TAG_PREFIX = 'tag%d' _TAG_PREFIX = 'tag%d'
NEUTRON_NETWORK_ID_KEY = 'NEUTRON_NETWORK_ID'
NEUTRON_RELAY_SOCKET_PATH_KEY = 'NEUTRON_RELAY_SOCKET_PATH'
@classmethod @classmethod
def check_version(cls): def check_version(cls):
pass pass
@ -399,7 +393,6 @@ class Dnsmasq(DhcpLocalProcess):
cmd_callback=self._build_cmdline_callback, cmd_callback=self._build_cmdline_callback,
namespace=self.network.namespace, namespace=self.network.namespace,
service=DNSMASQ_SERVICE_NAME, service=DNSMASQ_SERVICE_NAME,
cmd_addl_env={self.NEUTRON_NETWORK_ID_KEY: self.network.id},
reload_cfg=reload_with_HUP, reload_cfg=reload_with_HUP,
pid_file=pid_filename) pid_file=pid_filename)
@ -787,32 +780,6 @@ class Dnsmasq(DhcpLocalProcess):
isolated_subnets = cls.get_isolated_subnets(network) isolated_subnets = cls.get_isolated_subnets(network)
return any(isolated_subnets[subnet.id] for subnet in network.subnets) return any(isolated_subnets[subnet.id] for subnet in network.subnets)
@classmethod
def lease_update(cls):
network_id = os.environ.get(cls.NEUTRON_NETWORK_ID_KEY)
dhcp_relay_socket = os.environ.get(cls.NEUTRON_RELAY_SOCKET_PATH_KEY)
action = sys.argv[1]
if action not in ('add', 'del', 'old'):
sys.exit()
mac_address = sys.argv[2]
ip_address = sys.argv[3]
if action == 'del':
lease_remaining = 0
else:
lease_remaining = int(os.environ.get('DNSMASQ_TIME_REMAINING', 0))
data = dict(network_id=network_id, mac_address=mac_address,
ip_address=ip_address, lease_remaining=lease_remaining)
if os.path.exists(dhcp_relay_socket):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(dhcp_relay_socket)
sock.send(jsonutils.dumps(data))
sock.close()
class DeviceManager(object): class DeviceManager(object):

View File

@ -768,18 +768,11 @@ class TestDnsmasq(TestBase):
def mock_get_conf_file_name(kind): def mock_get_conf_file_name(kind):
return '/dhcp/%s/%s' % (network.id, kind) return '/dhcp/%s/%s' % (network.id, kind)
def fake_argv(index):
if index == 0:
return '/usr/local/bin/neutron-dhcp-agent'
else:
raise IndexError()
# if you need to change this path here, think twice, # if you need to change this path here, think twice,
# that means pid files will move around, breaking upgrades # that means pid files will move around, breaking upgrades
# or backwards-compatibility # or backwards-compatibility
expected_pid_file = '/dhcp/%s/pid' % network.id expected_pid_file = '/dhcp/%s/pid' % network.id
expected_env = {'NEUTRON_NETWORK_ID': network.id}
expected = [ expected = [
'dnsmasq', 'dnsmasq',
'--no-hosts', '--no-hosts',
@ -839,26 +832,23 @@ class TestDnsmasq(TestBase):
) )
mocks['interface_name'].__get__ = mock.Mock(return_value='tap0') mocks['interface_name'].__get__ = mock.Mock(return_value='tap0')
with mock.patch.object(dhcp.sys, 'argv') as argv: dm = self._get_dnsmasq(network, test_pm)
argv.__getitem__.side_effect = fake_argv dm.spawn_process()
dm = self._get_dnsmasq(network, test_pm) self.assertTrue(mocks['_output_opts_file'].called)
dm.spawn_process()
self.assertTrue(mocks['_output_opts_file'].called)
test_pm.enable.assert_called_once_with( test_pm.enable.assert_called_once_with(
cmd_addl_env=expected_env, uuid=network.id,
uuid=network.id, service='dnsmasq',
service='dnsmasq', namespace='qdhcp-ns',
namespace='qdhcp-ns', cmd_callback=mock.ANY,
cmd_callback=mock.ANY, reload_cfg=False,
reload_cfg=False, pid_file=expected_pid_file)
pid_file=expected_pid_file) call_kwargs = test_pm.method_calls[0][2]
call_kwargs = test_pm.method_calls[0][2] cmd_callback = call_kwargs['cmd_callback']
cmd_callback = call_kwargs['cmd_callback']
result_cmd = cmd_callback(expected_pid_file) result_cmd = cmd_callback(expected_pid_file)
self.assertEqual(expected, result_cmd) self.assertEqual(expected, result_cmd)
def test_spawn(self): def test_spawn(self):
self._test_spawn(['--conf-file=', '--domain=openstacklocal']) self._test_spawn(['--conf-file=', '--domain=openstacklocal'])
@ -1228,7 +1218,6 @@ class TestDnsmasq(TestBase):
cmd_callback=mock.ANY, cmd_callback=mock.ANY,
namespace=mock.ANY, namespace=mock.ANY,
service=mock.ANY, service=mock.ANY,
cmd_addl_env=mock.ANY,
reload_cfg=True, reload_cfg=True,
pid_file=mock.ANY)]) pid_file=mock.ANY)])