cfg.CONF.set_override('allow_overlapping_ips', True)
self.plugin = FakeL3PluginWithAgents()
+ self.plugin.router_scheduler = l3_agent_scheduler.ChanceScheduler()
self.agent1 = helpers.register_l3_agent()
self.agent2 = helpers.register_l3_agent(
'host_2', constants.L3_AGENT_MODE_DVR_SNAT)
def _bind_router(self, router_id):
with self.admin_ctx.session.begin(subtransactions=True):
- scheduler = l3_agent_scheduler.ChanceScheduler()
agents_db = self.plugin.get_agents_db(self.admin_ctx)
- scheduler._bind_ha_router_to_agents(
+ self.plugin.router_scheduler._bind_ha_router_to_agents(
self.plugin,
self.admin_ctx,
router_id,
self.assertEqual(0, len(bound_agents))
self.assertEqual(2, mock_manager.call_count)
+ def test_get_ha_sync_data_for_host_with_non_dvr_agent(self):
+ with mock.patch.object(self.plugin,
+ '_get_dvr_sync_data') as mock_get_sync:
+ self.plugin.supported_extension_aliases = ['dvr', 'l3-ha']
+ self.plugin.get_ha_sync_data_for_host(self.admin_ctx,
+ self.agent1['host'],
+ self.agent1)
+ self.assertFalse(mock_get_sync.called)
+
+ def test_get_ha_sync_data_for_host_with_dvr_agent(self):
+ with mock.patch.object(self.plugin,
+ '_get_dvr_sync_data') as mock_get_sync:
+ self.plugin.supported_extension_aliases = ['dvr', 'l3-ha']
+ self.plugin.get_ha_sync_data_for_host(self.admin_ctx,
+ self.agent2['host'],
+ self.agent2)
+ self.assertTrue(mock_get_sync.called)
+
def test_l3_agent_routers_query_interface(self):
router = self._create_router()
self._bind_router(router['id'])
routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx,
- self.agent1['host'])
+ self.agent1['host'],
+ self.agent1)
self.assertEqual(1, len(routers))
router = routers[0]
ha_network1['network_id'], ha_network2['network_id'])
def _deployed_router_change_ha_flag(self, to_ha):
- self._create_router(ha=not to_ha)
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx)
+ router1 = self._create_router(ha=not to_ha)
+ self._bind_router(router1['id'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
router = routers[0]
interface = router.get(constants.HA_INTERFACE_KEY)
if to_ha:
self.assertIsNotNone(interface)
self._migrate_router(router['id'], to_ha)
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx)
+ self.plugin.schedule_router(self.admin_ctx, router1['id'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
router = routers[0]
interface = router.get(constants.HA_INTERFACE_KEY)
if to_ha:
self.assertTrue(self.notif_m.called)
def test_unique_vr_id_between_routers(self):
- self._create_router()
- self._create_router()
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx)
+ router1 = self._create_router()
+ router2 = self._create_router()
+ self._bind_router(router1['id'])
+ self._bind_router(router2['id'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
self.assertEqual(2, len(routers))
self.assertNotEqual(routers[0]['ha_vr_id'], routers[1]['ha_vr_id'])
@mock.patch('neutron.db.l3_hamode_db.VR_ID_RANGE', new=set(range(1, 2)))
def test_vr_id_unique_range_per_tenant(self):
- self._create_router()
- self._create_router(tenant_id=_uuid())
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx)
+ router1 = self._create_router()
+ router2 = self._create_router(tenant_id=_uuid())
+ self._bind_router(router1['id'])
+ self._bind_router(router2['id'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
self.assertEqual(2, len(routers))
self.assertEqual(routers[0]['ha_vr_id'], routers[1]['ha_vr_id'])
self.assertEqual(allocs_before, allocs_after)
def test_one_ha_router_one_not(self):
- self._create_router(ha=False)
- self._create_router()
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx)
+ router1 = self._create_router(ha=False)
+ router2 = self._create_router()
+ self._bind_router(router1['id'])
+ self._bind_router(router2['id'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
ha0 = routers[0]['ha']
ha1 = routers[1]['ha']
router2 = self._create_router()
self._bind_router(router2['id'])
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx,
- self.agent1['host'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
for router in routers:
self.assertEqual('standby', router[constants.HA_ROUTER_STATE_KEY])
self.plugin.update_routers_states(
self.admin_ctx, states, self.agent1['host'])
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx,
- self.agent1['host'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
for router in routers:
self.assertEqual(states[router['id']],
router[constants.HA_ROUTER_STATE_KEY])
self.plugin._set_router_states(
self.admin_ctx, bindings, {router1['id']: 'active',
router2['id']: 'active'})
- routers = self.plugin.get_ha_sync_data_for_host(self.admin_ctx,
- self.agent1['host'])
+ routers = self.plugin.get_ha_sync_data_for_host(
+ self.admin_ctx, self.agent1['host'], self.agent1)
self.assertEqual('active', routers[0][constants.HA_ROUTER_STATE_KEY])
def test_exclude_dvr_agents_for_ha_candidates(self):