Merge "DHCP: enhance DHCPAgent startup procedure" into stable/mitaka
This commit is contained in:
commit
774cb42f42
|
@ -94,7 +94,6 @@ class DhcpAgent(manager.Manager):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Activate the DHCP agent."""
|
"""Activate the DHCP agent."""
|
||||||
self.sync_state()
|
|
||||||
self.periodic_resync()
|
self.periodic_resync()
|
||||||
|
|
||||||
def call_driver(self, action, network, **action_kwargs):
|
def call_driver(self, action, network, **action_kwargs):
|
||||||
|
|
|
@ -246,42 +246,35 @@ class TestDhcpAgent(base.BaseTestCase):
|
||||||
# sync_state is needed for this test
|
# sync_state is needed for this test
|
||||||
cfg.CONF.set_override('report_interval', 1, 'AGENT')
|
cfg.CONF.set_override('report_interval', 1, 'AGENT')
|
||||||
with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
|
with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
|
||||||
'sync_state',
|
'periodic_resync',
|
||||||
autospec=True) as mock_sync_state:
|
autospec=True) as mock_periodic_resync:
|
||||||
with mock.patch.object(dhcp_agent.DhcpAgentWithStateReport,
|
with mock.patch(state_rpc_str) as state_rpc:
|
||||||
'periodic_resync',
|
with mock.patch.object(sys, 'argv') as sys_argv:
|
||||||
autospec=True) as mock_periodic_resync:
|
sys_argv.return_value = [
|
||||||
with mock.patch(state_rpc_str) as state_rpc:
|
'dhcp', '--config-file',
|
||||||
with mock.patch.object(sys, 'argv') as sys_argv:
|
base.etcdir('neutron.conf')]
|
||||||
sys_argv.return_value = [
|
cfg.CONF.register_opts(dhcp_config.DHCP_AGENT_OPTS)
|
||||||
'dhcp', '--config-file',
|
config.register_interface_driver_opts_helper(cfg.CONF)
|
||||||
base.etcdir('neutron.conf')]
|
config.register_agent_state_opts_helper(cfg.CONF)
|
||||||
cfg.CONF.register_opts(dhcp_config.DHCP_AGENT_OPTS)
|
cfg.CONF.register_opts(interface.OPTS)
|
||||||
config.register_interface_driver_opts_helper(cfg.CONF)
|
common_config.init(sys.argv[1:])
|
||||||
config.register_agent_state_opts_helper(cfg.CONF)
|
agent_mgr = dhcp_agent.DhcpAgentWithStateReport(
|
||||||
cfg.CONF.register_opts(interface.OPTS)
|
'testhost')
|
||||||
common_config.init(sys.argv[1:])
|
eventlet.greenthread.sleep(1)
|
||||||
agent_mgr = dhcp_agent.DhcpAgentWithStateReport(
|
agent_mgr.after_start()
|
||||||
'testhost')
|
mock_periodic_resync.assert_called_once_with(agent_mgr)
|
||||||
eventlet.greenthread.sleep(1)
|
state_rpc.assert_has_calls(
|
||||||
agent_mgr.after_start()
|
[mock.call(mock.ANY),
|
||||||
mock_sync_state.assert_called_once_with(agent_mgr)
|
mock.call().report_state(mock.ANY, mock.ANY,
|
||||||
mock_periodic_resync.assert_called_once_with(agent_mgr)
|
mock.ANY)])
|
||||||
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):
|
def test_run_completes_single_pass(self):
|
||||||
with mock.patch(DEVICE_MANAGER):
|
with mock.patch(DEVICE_MANAGER):
|
||||||
dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
|
dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
|
||||||
attrs_to_mock = dict(
|
with mock.patch.object(dhcp,
|
||||||
[(a, mock.DEFAULT) for a in
|
'periodic_resync') as periodic_resync_mock:
|
||||||
['sync_state', 'periodic_resync']])
|
|
||||||
with mock.patch.multiple(dhcp, **attrs_to_mock) as mocks:
|
|
||||||
dhcp.run()
|
dhcp.run()
|
||||||
mocks['sync_state'].assert_called_once_with()
|
periodic_resync_mock.assert_called_once_with()
|
||||||
mocks['periodic_resync'].assert_called_once_with()
|
|
||||||
|
|
||||||
def test_call_driver(self):
|
def test_call_driver(self):
|
||||||
network = mock.Mock()
|
network = mock.Mock()
|
||||||
|
|
Loading…
Reference in New Issue