179
182
router = self._create_router(ha=False)
180
183
self.assertFalse(router['ha'])
185
def test_add_ha_network_settings(self):
186
cfg.CONF.set_override('l3_ha_network_type', 'abc')
187
cfg.CONF.set_override('l3_ha_network_physical_name', 'def')
190
self.plugin._add_ha_network_settings(network)
192
self.assertEqual('abc', network[providernet.NETWORK_TYPE])
193
self.assertEqual('def', network[providernet.PHYSICAL_NETWORK])
182
195
def test_router_create_with_ha_conf_enabled(self):
183
196
cfg.CONF.set_override('l3_ha', True)
420
433
routers_after = self.plugin.get_routers(self.admin_ctx)
421
434
self.assertEqual(routers_before, routers_after)
436
def test_get_active_host_for_ha_router(self):
437
router = self._create_router()
438
self._bind_router(router['id'])
441
self.plugin.get_active_host_for_ha_router(
442
self.admin_ctx, router['id']))
443
self.plugin.update_routers_states(
444
self.admin_ctx, {router['id']: 'active'}, self.agent2['host'])
447
self.plugin.get_active_host_for_ha_router(
448
self.admin_ctx, router['id']))
423
450
def test_update_routers_states(self):
424
451
router1 = self._create_router()
425
452
self._bind_router(router1['id'])
520
547
self.admin_ctx, [router['id']])
521
548
self.assertEqual(2, len(bindings))
550
def test_update_router_port_bindings_no_ports(self):
551
self.plugin._update_router_port_bindings(
552
self.admin_ctx, {}, self.agent1['host'])
554
def _get_first_interface(self, router_id):
555
device_filter = {'device_id': [router_id],
557
[constants.DEVICE_OWNER_ROUTER_INTF]}
558
return self.core_plugin.get_ports(
560
filters=device_filter)[0]
562
def test_update_router_port_bindings_updates_host(self):
563
network_id = self._create_network(self.core_plugin, self.admin_ctx)
564
subnet = self._create_subnet(self.core_plugin, self.admin_ctx,
566
interface_info = {'subnet_id': subnet['id']}
568
router = self._create_router()
569
self._bind_router(router['id'])
570
self.plugin.add_router_interface(self.admin_ctx,
573
self.plugin._update_router_port_bindings(
574
self.admin_ctx, {router['id']: 'active'}, self.agent1['host'])
576
port = self._get_first_interface(router['id'])
577
self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
579
self.plugin._update_router_port_bindings(
580
self.admin_ctx, {router['id']: 'active'}, self.agent2['host'])
581
port = self._get_first_interface(router['id'])
582
self.assertEqual(self.agent2['host'], port[portbindings.HOST_ID])
584
def test_ensure_host_set_on_ports_binds_correctly(self):
585
network_id = self._create_network(self.core_plugin, self.admin_ctx)
586
subnet = self._create_subnet(self.core_plugin, self.admin_ctx,
588
interface_info = {'subnet_id': subnet['id']}
590
router = self._create_router()
591
self._bind_router(router['id'])
592
self.plugin.add_router_interface(self.admin_ctx,
595
port = self._get_first_interface(router['id'])
596
self.assertEqual('', port[portbindings.HOST_ID])
598
# Update the router object to include the first interface
600
self.plugin.list_active_sync_routers_on_active_l3_agent(
601
self.admin_ctx, self.agent1['host'], [router['id']]))[0]
603
# ensure_host_set_on_ports binds an unbound port
604
callback = l3_rpc.L3RpcCallback()
605
callback._l3plugin = self.plugin
606
callback._ensure_host_set_on_ports(
607
self.admin_ctx, self.agent1['host'], [router])
608
port = self._get_first_interface(router['id'])
609
self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
611
# ensure_host_set_on_ports does not rebind a bound port
613
self.plugin.list_active_sync_routers_on_active_l3_agent(
614
self.admin_ctx, self.agent1['host'], [router['id']]))[0]
615
callback._ensure_host_set_on_ports(
616
self.admin_ctx, self.agent2['host'], [router])
617
port = self._get_first_interface(router['id'])
618
self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
524
621
class L3HAUserTestCase(L3HATestFramework):