Use router state in get_ha_device_name and ha_network_added

get_ha_device_name and ha_network_added were moved from the
agent to the router class, but they're not using the router
state. Rather, they're accepting arguments that they don't
need.

Partially-Implements: bp/restructure-l3-agent
Change-Id: I9a70cbc4c45ceadd8b0a86c49ac35f0885db4997
This commit is contained in:
Assaf Muller 2015-03-24 19:56:37 -04:00
parent 807b74dc0c
commit af1f994787
2 changed files with 25 additions and 25 deletions

View File

@ -83,10 +83,7 @@ class HaRouter(router.RouterInfo):
self._set_subnet_info(ha_port) self._set_subnet_info(ha_port)
self.ha_port = ha_port self.ha_port = ha_port
self._init_keepalived_manager(process_monitor) self._init_keepalived_manager(process_monitor)
self.ha_network_added(ha_port['network_id'], self.ha_network_added()
ha_port['id'],
ha_port['ip_cidr'],
ha_port['mac_address'])
self.update_initial_state(state_change_callback) self.update_initial_state(state_change_callback)
self.spawn_state_change_monitor(process_monitor) self.spawn_state_change_monitor(process_monitor)
@ -105,7 +102,7 @@ class HaRouter(router.RouterInfo):
config = self.keepalived_manager.config config = self.keepalived_manager.config
interface_name = self.get_ha_device_name(self.ha_port['id']) interface_name = self.get_ha_device_name()
ha_port_cidr = self.ha_port['subnet']['cidr'] ha_port_cidr = self.ha_port['subnet']['cidr']
instance = keepalived.KeepalivedInstance( instance = keepalived.KeepalivedInstance(
'BACKUP', 'BACKUP',
@ -139,22 +136,26 @@ class HaRouter(router.RouterInfo):
def _get_primary_vip(self): def _get_primary_vip(self):
return self._get_keepalived_instance().get_primary_vip() return self._get_keepalived_instance().get_primary_vip()
def get_ha_device_name(self, port_id): def get_ha_device_name(self):
return (HA_DEV_PREFIX + port_id)[:self.driver.DEV_NAME_LEN] return (HA_DEV_PREFIX + self.ha_port['id'])[:self.driver.DEV_NAME_LEN]
def ha_network_added(self, network_id, port_id, internal_cidr, def ha_network_added(self):
mac_address): interface_name = self.get_ha_device_name()
interface_name = self.get_ha_device_name(port_id)
self.driver.plug(network_id, port_id, interface_name, mac_address, self.driver.plug(self.ha_port['network_id'],
self.ha_port['id'],
interface_name,
self.ha_port['mac_address'],
namespace=self.ns_name, namespace=self.ns_name,
prefix=HA_DEV_PREFIX) prefix=HA_DEV_PREFIX)
self.driver.init_l3(interface_name, [internal_cidr], self.driver.init_l3(interface_name,
[self.ha_port['ip_cidr']],
namespace=self.ns_name, namespace=self.ns_name,
preserve_ips=[self._get_primary_vip()]) preserve_ips=[self._get_primary_vip()])
def ha_network_removed(self): def ha_network_removed(self):
interface_name = self.get_ha_device_name(self.ha_port['id']) self.driver.unplug(self.get_ha_device_name(),
self.driver.unplug(interface_name, namespace=self.ns_name, namespace=self.ns_name,
prefix=HA_DEV_PREFIX) prefix=HA_DEV_PREFIX)
self.ha_port = None self.ha_port = None
@ -279,7 +280,7 @@ class HaRouter(router.RouterInfo):
default_cmd_callback=self._get_state_change_monitor_callback()) default_cmd_callback=self._get_state_change_monitor_callback())
def _get_state_change_monitor_callback(self): def _get_state_change_monitor_callback(self):
ha_device = self.get_ha_device_name(self.ha_port['id']) ha_device = self.get_ha_device_name()
ha_cidr = self._get_primary_vip() ha_cidr = self._get_primary_vip()
def callback(pid_file): def callback(pid_file):
@ -312,7 +313,7 @@ class HaRouter(router.RouterInfo):
def update_initial_state(self, callback): def update_initial_state(self, callback):
ha_device = ip_lib.IPDevice( ha_device = ip_lib.IPDevice(
self.get_ha_device_name(self.ha_port['id']), self.get_ha_device_name(),
self.ns_name) self.ns_name)
addresses = ha_device.addr.list() addresses = ha_device.addr.list()
cidrs = (address['cidr'] for address in addresses) cidrs = (address['cidr'] for address in addresses)

View File

@ -153,7 +153,7 @@ class L3AgentTestFramework(base.BaseOVSLinuxTestCase):
def get_expected_keepalive_configuration(self, router): def get_expected_keepalive_configuration(self, router):
router_id = router.router_id router_id = router.router_id
ha_device_name = router.get_ha_device_name(router.ha_port['id']) ha_device_name = router.get_ha_device_name()
ha_device_cidr = router.ha_port['ip_cidr'] ha_device_cidr = router.ha_port['ip_cidr']
external_port = router.get_ex_gw_port() external_port = router.get_ex_gw_port()
ex_port_ipv6 = ip_lib.get_ipv6_lladdr(external_port['mac_address']) ex_port_ipv6 = ip_lib.get_ipv6_lladdr(external_port['mac_address'])
@ -275,8 +275,7 @@ class L3AgentTestFramework(base.BaseOVSLinuxTestCase):
namespace=router.ns_name) for fip in floating_ips) namespace=router.ns_name) for fip in floating_ips)
def fail_ha_router(self, router): def fail_ha_router(self, router):
device_name = router.get_ha_device_name( device_name = router.get_ha_device_name()
router.router[l3_constants.HA_INTERFACE_KEY]['id'])
ha_device = ip_lib.IPDevice(device_name, router.ns_name) ha_device = ip_lib.IPDevice(device_name, router.ns_name)
ha_device.link.set_down() ha_device.link.set_down()
@ -510,9 +509,10 @@ class L3AgentTestCase(L3AgentTestFramework):
self.assertEqual(expected_gateway, existing_gateway) self.assertEqual(expected_gateway, existing_gateway)
def _assert_ha_device(self, router): def _assert_ha_device(self, router):
self.assertTrue(self.device_exists_with_ip_mac( device = router.router[l3_constants.HA_INTERFACE_KEY]
router.router[l3_constants.HA_INTERFACE_KEY], self.assertTrue(ip_lib.device_exists_with_ip_mac(
router.get_ha_device_name, router.ns_name)) router.get_ha_device_name(), device['ip_cidr'],
device['mac_address'], router.ns_name))
@classmethod @classmethod
def _get_addresses_on_device(cls, namespace, interface): def _get_addresses_on_device(cls, namespace, interface):
@ -535,7 +535,7 @@ class L3AgentTestCase(L3AgentTestFramework):
router1._get_primary_vip(), router1._get_primary_vip(),
self._get_addresses_on_device( self._get_addresses_on_device(
router1.ns_name, router1.ns_name,
router1.get_ha_device_name(router1.ha_port['id']))) router1.get_ha_device_name()))
class L3HATestFramework(L3AgentTestFramework): class L3HATestFramework(L3AgentTestFramework):
@ -578,8 +578,7 @@ class L3HATestFramework(L3AgentTestFramework):
utils.wait_until_true(lambda: router1.ha_state == 'master') utils.wait_until_true(lambda: router1.ha_state == 'master')
utils.wait_until_true(lambda: router2.ha_state == 'backup') utils.wait_until_true(lambda: router2.ha_state == 'backup')
device_name = router1.get_ha_device_name( device_name = router1.get_ha_device_name()
router1.router[l3_constants.HA_INTERFACE_KEY]['id'])
ha_device = ip_lib.IPDevice(device_name, namespace=router1.ns_name) ha_device = ip_lib.IPDevice(device_name, namespace=router1.ns_name)
ha_device.link.set_down() ha_device.link.set_down()