LOG.exception(_LE('Unable to %(action)s dhcp for %(net_id)s.'),
{'net_id': network.id, 'action': action})
- def schedule_resync(self, reason, network=None):
+ def schedule_resync(self, reason, network_id=None):
"""Schedule a resync for a given network and reason. If no network is
specified, resync all networks.
"""
- self.needs_resync_reasons[network].append(reason)
+ self.needs_resync_reasons[network_id].append(reason)
@utils.synchronized('dhcp-agent')
def sync_state(self, networks=None):
LOG.info(_LI('Synchronizing state complete'))
except Exception as e:
- self.schedule_resync(e)
+ if only_nets:
+ for network_id in only_nets:
+ self.schedule_resync(e, network_id)
+ else:
+ self.schedule_resync(e)
LOG.exception(_LE('Unable to sync network state.'))
@utils.exception_logger()
self._test_sync_state_helper(known_net_ids, active_net_ids)
w.assert_called_once_with()
- def test_sync_state_plugin_error(self):
+ def test_sync_state_for_all_networks_plugin_error(self):
with mock.patch(DHCP_PLUGIN) as plug:
mock_plugin = mock.Mock()
mock_plugin.get_active_networks_info.side_effect = Exception
self.assertTrue(log.called)
self.assertTrue(schedule_resync.called)
+ def test_sync_state_for_one_network_plugin_error(self):
+ with mock.patch(DHCP_PLUGIN) as plug:
+ mock_plugin = mock.Mock()
+ exc = Exception()
+ mock_plugin.get_active_networks_info.side_effect = exc
+ plug.return_value = mock_plugin
+
+ with mock.patch.object(dhcp_agent.LOG, 'exception') as log:
+ dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
+ with mock.patch.object(dhcp,
+ 'schedule_resync') as schedule_resync:
+ dhcp.sync_state(['foo_network'])
+
+ self.assertTrue(log.called)
+ schedule_resync.assert_called_with(exc, 'foo_network')
+
def test_periodic_resync(self):
dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
with mock.patch.object(dhcp_agent.eventlet, 'spawn') as spawn: