]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fix DHCP port changed when dhcp-agent restart
authordql <duquanglong@gmail.com>
Mon, 9 Mar 2015 04:52:11 +0000 (12:52 +0800)
committerdql <duquanglong@gmail.com>
Wed, 20 May 2015 08:20:27 +0000 (16:20 +0800)
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

neutron/agent/dhcp/agent.py
neutron/tests/unit/agent/dhcp/test_agent.py

index 89fd0773ed51c385721993925c806e8ed9cbe0fc..4d52df8d61c3cf841b96f3020934d621d105e3e3 100644 (file)
@@ -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:
index 6ea10afefd5e122bb74b4559598ffab2381cda8a..19dfcaa59fea6024a890b8b31d7d8227cf67b3ee 100644 (file)
@@ -221,6 +221,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