From c04587110fef24c189d439bacbbbc7105085cbe1 Mon Sep 17 00:00:00 2001 From: Swaminathan Vasudevan Date: Tue, 22 Dec 2015 13:40:33 -0800 Subject: [PATCH] DVR: Agent side change for live migration with floatingip During live migration when an instance is in a pre-migration state, and if the fixed_ip of the port has an associated floatingip, the floatingip namespace should be created in the destination node, before the VM instance lands on the node. The server side code will handle the pre-live migration case and initiate the router creation on the destination node and also will provide the 'dest_host' as an additional attribute to the floatingips dictionary that is being passed to the agent. So this patch reads the 'dest_host' and the 'host' variable and if any of the two matches with the host, it will allow the floatingip to be processed. This will be an agent side change for addressing the vm migration with Floatingip enabled. Closes-Bug: #1456073 Change-Id: Idfbea7f3c66d6a1df5d3050912d620591c69b614 --- neutron/agent/l3/dvr_local_router.py | 4 +++- .../functional/agent/l3/test_dvr_router.py | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/neutron/agent/l3/dvr_local_router.py b/neutron/agent/l3/dvr_local_router.py index 3ec964e2a1d..be894b80f95 100644 --- a/neutron/agent/l3/dvr_local_router.py +++ b/neutron/agent/l3/dvr_local_router.py @@ -51,7 +51,9 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): def get_floating_ips(self): """Filter Floating IPs to be hosted on this agent.""" floating_ips = super(DvrLocalRouter, self).get_floating_ips() - return [i for i in floating_ips if i['host'] == self.host] + return [i for i in floating_ips if ( + (i['host'] == self.host) or + (i.get('dest_host') == self.host))] def _handle_fip_nat_rules(self, interface_name): """Configures NAT rules for Floating IPs for DVR.""" diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index 202e19de305..2e9eef9f793 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -495,6 +495,30 @@ class TestDvrRouter(framework.L3AgentTestFramework): self.assertFalse(self._namespace_exists(fip_ns)) self._assert_snat_namespace_does_not_exist(router1) + def test_dvr_router_fip_create_for_migrating_port(self): + """Test to validate the floatingip create on port migrate. + + This test validates the condition where floatingip host + mismatches with the agent, but the 'dest_host' variable + matches with the agent host, due to port pre-migrate + phase. + + """ + self.agent.conf.agent_mode = 'dvr' + router_info = self.generate_dvr_router_info() + floating_ip = router_info['_floatingips'][0] + floating_ip['host'] = 'my_new_host' + floating_ip['dest_host'] = self.agent.host + # Now we have the floatingip 'host' pointing to host that + # does not match to the 'agent.host' and the floatingip + # 'dest_host' matches with the agent.host in the case + # of live migration due to the port_profile update from + # nova. + router1 = self.manage_router(self.agent, router_info) + fip_ns = router1.fip_ns.get_name() + self.assertTrue(self._namespace_exists(router1.ns_name)) + self.assertTrue(self._namespace_exists(fip_ns)) + def test_dvr_router_fip_late_binding(self): """Test to validate the floatingip migration or latebinding.