if not snat_bindings and router_gw_exists:
# If GW exists for DVR routers and no SNAT binding
# call the schedule_snat_router
- plugin.schedule_snat_router(context, router_id, sync_router)
+ return plugin.schedule_snat_router(
+ context, router_id, sync_router)
if not router_gw_exists and snat_bindings:
# If DVR router and no Gateway but SNAT Binding exists then
# call the unbind_snat_servicenode to unbind the snat service
# from agent
plugin.unbind_snat_servicenode(context, router_id)
+ return
candidates = candidates or self.get_candidates(
plugin, context, sync_router)
if not candidates:
sync_router = {'id': 'foo_router_id',
'distributed': True}
plugin.get_router.return_value = sync_router
- with contextlib.nested(
- mock.patch.object(scheduler, 'bind_router'),
- mock.patch.object(plugin, 'get_snat_bindings', return_value=True)):
+ with mock.patch.object(plugin, 'get_snat_bindings', return_value=True):
scheduler._schedule_router(
plugin, self.adminContext, 'foo_router_id', None)
expected_calls = [
mock.call.get_router(mock.ANY, 'foo_router_id'),
mock.call.unbind_snat_servicenode(mock.ANY, 'foo_router_id'),
- mock.call.get_l3_agents_hosting_routers(
- mock.ANY, ['foo_router_id'], admin_state_up=True),
- mock.call.get_l3_agents(mock.ANY, active=True),
- mock.call.get_l3_agent_candidates(mock.ANY, sync_router, [agent]),
]
plugin.assert_has_calls(expected_calls)
}
}
plugin.get_router.return_value = sync_router
- with contextlib.nested(
- mock.patch.object(scheduler, 'bind_router'),
- mock.patch.object(
- plugin, 'get_snat_bindings', return_value=False)
- ):
+ with mock.patch.object(
+ plugin, 'get_snat_bindings', return_value=False):
scheduler._schedule_router(
plugin, self.adminContext, 'foo_router_id', None)
expected_calls = [
mock.call.get_router(mock.ANY, 'foo_router_id'),
mock.call.schedule_snat_router(
mock.ANY, 'foo_router_id', sync_router),
- mock.call.get_l3_agents_hosting_routers(
- mock.ANY, ['foo_router_id'], admin_state_up=True),
- mock.call.get_l3_agents(mock.ANY, active=True),
- mock.call.get_l3_agent_candidates(mock.ANY, sync_router, [agent]),
]
plugin.assert_has_calls(expected_calls)
self.assertTrue(mock_bind_snat.called)
self.assertFalse(mock_bind_dvr.called)
+ def test_schedule_snat_router_return_value(self):
+ agent, router = self._prepare_schedule_snat_tests()
+ with contextlib.nested(
+ mock.patch.object(self.dut, 'get_l3_agents'),
+ mock.patch.object(self.dut, 'get_snat_candidates'),
+ mock.patch.object(self.dut, 'bind_snat_servicenode'),
+ mock.patch.object(self.dut, 'bind_dvr_router_servicenode')
+ ) as (mock_gl3, mock_snat_canidates, mock_bind_snat, mock_bind_dvr):
+ mock_snat_canidates.return_value = [agent]
+ mock_bind_snat.return_value = [agent]
+ mock_bind_dvr.return_value = [agent]
+ chosen_agent = self.dut.schedule_snat_router(
+ self.adminContext, 'foo_router_id', router)
+ self.assertEqual(chosen_agent, [agent])
+
def test_schedule_router_unbind_snat_servicenode_negativetest(self):
router = {
'id': 'foo_router_id',