summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand Lallau <bertrand.lallau@thalesgroup.com>2016-12-20 10:53:41 +0100
committerDaniel Alvarez <dalvarez@redhat.com>2017-01-20 11:57:42 +0100
commit21963618ca7accfe0b5d3389ee15426d5032a2ac (patch)
treeb5b485f8cb0965a136357e2a6f87425a91db74a6
parent80fb54d8dc76ce4a9631452feb4b583f16bb00fe (diff)
downloadneutron-21963618ca7accfe0b5d3389ee15426d5032a2ac.tar.gz
DHCP: enhance DHCPAgent startup procedure
During DhcpAgent startup procedure all the following networks initialization is actually perform twice: * Killing old dnsmasq processes * set and configure all TAP interfaces * building all Dnsmasq config files (lease and host files) * launching dnsmasq processes What is done during the second iteration is just clean and redo exactly the same another time! This is really inefficient and increase dramatically DHCP startup time (near twice than needed). Initialization process 'sync_state' method is called twice: * one time during init_host() * another time during _report_state() sync_state() call must stay in init_host() due to bug #1420042. sync_state() is always called during startup in init_host() and will be periodically called by periodic_resync() to do reconciliation. Hence it can safely be removed from the run() method. Change-Id: Id6433598d5c833d2e86be605089d42feee57c257 Closes-bug: #1651368 Closes-Bug: #1650611 (cherry picked from commit f15851b98974dc16606da195cf3ecee577cd0ef8) (cherry picked from commit ae0a31d8b0c449031432117ac33c1e5bdf9d5957)
-rw-r--r--neutron/agent/dhcp/agent.py1
-rw-r--r--neutron/tests/unit/agent/dhcp/test_agent.py55
2 files changed, 24 insertions, 32 deletions
diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py
index fb0138a0d5..303545c68e 100644
--- a/neutron/agent/dhcp/agent.py
+++ b/neutron/agent/dhcp/agent.py
@@ -94,7 +94,6 @@ class DhcpAgent(manager.Manager):
def run(self):
"""Activate the DHCP agent."""
- self.sync_state()
self.periodic_resync()
def call_driver(self, action, network, **action_kwargs):
diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py
index 02181c7b51..72a57f4bb7 100644
--- a/neutron/tests/unit/agent/dhcp/test_agent.py
+++ b/neutron/tests/unit/agent/dhcp/test_agent.py
@@ -246,42 +246,35 @@ class TestDhcpAgent(base.BaseTestCase):
# sync_state is needed for this test
cfg.CONF.set_override('report_interval', 1, 'AGENT')
with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
- 'sync_state',
- autospec=True) as mock_sync_state:
- with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
- 'periodic_resync',
- autospec=True) as mock_periodic_resync:
- with mock.patch(state_rpc_str) as state_rpc:
- with mock.patch.object(sys, 'argv') as sys_argv:
- sys_argv.return_value = [
- 'dhcp', '--config-file',
- base.etcdir('neutron.conf')]
- cfg.CONF.register_opts(dhcp_config.DHCP_AGENT_OPTS)
- config.register_interface_driver_opts_helper(cfg.CONF)
- config.register_agent_state_opts_helper(cfg.CONF)
- cfg.CONF.register_opts(interface.OPTS)
- common_config.init(sys.argv[1:])
- agent_mgr = dhcp_agent.DhcpAgentWithStateReport(
- 'testhost')
- eventlet.greenthread.sleep(1)
- agent_mgr.after_start()
- mock_sync_state.assert_called_once_with(agent_mgr)
- mock_periodic_resync.assert_called_once_with(agent_mgr)
- state_rpc.assert_has_calls(
- [mock.call(mock.ANY),
- mock.call().report_state(mock.ANY, mock.ANY,
- mock.ANY)])
+ 'periodic_resync',
+ autospec=True) as mock_periodic_resync:
+ with mock.patch(state_rpc_str) as state_rpc:
+ with mock.patch.object(sys, 'argv') as sys_argv:
+ sys_argv.return_value = [
+ 'dhcp', '--config-file',
+ base.etcdir('neutron.conf')]
+ cfg.CONF.register_opts(dhcp_config.DHCP_AGENT_OPTS)
+ config.register_interface_driver_opts_helper(cfg.CONF)
+ config.register_agent_state_opts_helper(cfg.CONF)
+ cfg.CONF.register_opts(interface.OPTS)
+ common_config.init(sys.argv[1:])
+ agent_mgr = dhcp_agent.DhcpAgentWithStateReport(
+ 'testhost')
+ eventlet.greenthread.sleep(1)
+ agent_mgr.after_start()
+ mock_periodic_resync.assert_called_once_with(agent_mgr)
+ state_rpc.assert_has_calls(
+ [mock.call(mock.ANY),
+ mock.call().report_state(mock.ANY, mock.ANY,
+ mock.ANY)])
def test_run_completes_single_pass(self):
with mock.patch(DEVICE_MANAGER):
dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
- attrs_to_mock = dict(
- [(a, mock.DEFAULT) for a in
- ['sync_state', 'periodic_resync']])
- with mock.patch.multiple(dhcp, **attrs_to_mock) as mocks:
+ with mock.patch.object(dhcp,
+ 'periodic_resync') as periodic_resync_mock:
dhcp.run()
- mocks['sync_state'].assert_called_once_with()
- mocks['periodic_resync'].assert_called_once_with()
+ periodic_resync_mock.assert_called_once_with()
def test_call_driver(self):
network = mock.Mock()