From 68459f99edc2f71a5f6357c7e5594afa5883a9ea Mon Sep 17 00:00:00 2001 From: dql Date: Mon, 9 Mar 2015 12:52:11 +0800 Subject: [PATCH] fix DHCP port changed when dhcp-agent restart When DHCP server is started, the periodic task is running before loading cache state.The method port_update_end need to use the cache information, but the cache information has not been loaded. Change-Id: I0d1da11bb559b7f0f9d4428b82573fb26916a933 Closes-Bug: #1420042 (cherry picked from commit 3d2543d710c7071ffeb5c9857ac30a4d95695a7b) --- neutron/agent/dhcp/agent.py | 3 +++ neutron/tests/unit/agent/dhcp/test_agent.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index 1942fc65262..d54b745053f 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -70,6 +70,9 @@ class DhcpAgent(manager.Manager): config=self.conf, resource_type='dhcp') + def init_host(self): + self.sync_state() + def _populate_networks_cache(self): """Populate the networks cache when the DHCP-agent starts.""" try: diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py index 24c0d10564c..7911d871f14 100644 --- a/neutron/tests/unit/agent/dhcp/test_agent.py +++ b/neutron/tests/unit/agent/dhcp/test_agent.py @@ -222,6 +222,12 @@ class TestDhcpAgent(base.BaseTestCase): self.mock_makedirs_p = mock.patch("os.makedirs") self.mock_makedirs = self.mock_makedirs_p.start() + def test_init_host(self): + dhcp = dhcp_agent.DhcpAgent(HOSTNAME) + with mock.patch.object(dhcp, 'sync_state') as sync_state: + dhcp.init_host() + sync_state.assert_called_once_with() + def test_dhcp_agent_manager(self): state_rpc_str = 'neutron.agent.rpc.PluginReportStateAPI' # sync_state is needed for this test