]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Change to improve dhcp-agent sync_state
authorEd Bak <ed.bak2@hp.com>
Tue, 3 Dec 2013 23:00:23 +0000 (23:00 +0000)
committerEd Bak <ed.bak2@hp.com>
Thu, 5 Dec 2013 18:59:50 +0000 (18:59 +0000)
Added a pool.waitall to dhcp-agent sync_state
to ensure that the last pool of threads are complete
before another sync_state begins.  Added another
log message to aid in debugging. Also added the
test_sync_state_waitall unit test.

Change-Id: I13d79a212672c4086e3082783743cb1ef2b48cfb
Closes-Bug: #1257514

neutron/agent/dhcp_agent.py
neutron/tests/unit/test_dhcp_agent.py

index 2cbd1494926d8146fca5ed991a8b040bc6da3439..c8994ef1c551a1c50ec53b984f3ccd191b5c5909 100644 (file)
@@ -158,6 +158,8 @@ class DhcpAgent(manager.Manager):
 
             for network in active_networks:
                 pool.spawn_n(self.safe_configure_dhcp_for_network, network)
+            pool.waitall()
+            LOG.info(_('Synchronizing state complete'))
 
         except Exception:
             self.needs_resync = True
index cd7d0a2aade4e7b4d850b3a0e779a27748ede194..f305547fe88dfec839476644ebc251449486c2dc 100644 (file)
@@ -269,6 +269,22 @@ class TestDhcpAgent(base.BaseTestCase):
     def test_sync_state_disabled_net(self):
         self._test_sync_state_helper(['b'], ['a'])
 
+    def test_sync_state_waitall(self):
+        class mockNetwork():
+            id = '0'
+            admin_state_up = True
+            subnets = []
+
+            def __init__(self, id):
+                self.id = id
+        with mock.patch.object(dhcp_agent.eventlet.GreenPool, 'waitall') as w:
+            active_networks = [mockNetwork('1'), mockNetwork('2'),
+                               mockNetwork('3'), mockNetwork('4'),
+                               mockNetwork('5')]
+            known_networks = ['1', '2', '3', '4', '5']
+            self._test_sync_state_helper(known_networks, active_networks)
+            w.assert_called_once_with()
+
     def test_sync_state_plugin_error(self):
         with mock.patch(DHCP_PLUGIN) as plug:
             mock_plugin = mock.Mock()