]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Skip bindings with agent_id=None
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Wed, 21 Oct 2015 14:37:34 +0000 (17:37 +0300)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Sat, 14 Nov 2015 06:23:55 +0000 (06:23 +0000)
To avoid having extra L3HARouterAgentPortBinding with l3_agent as None,
operation of setting l3_agent should be atomic.
For this purpose, transaction was added in methods
create_ha_port_and_bind and _bind_ha_router_to_agents in change
Iaad82fe522cfd70061daecf411c924fdc11b7e41

In case if router was just created and l3 agent was not scheduled yet,
so l3_agent_id is None, l3-agent-list-hosting-router <router> will fail.
This change makes it work by skipping binding with agent_id=None.

Partial-bug: #1499647

Change-Id: I1aaf4b651f738febc26b0e1105aeabe066bca2a0

neutron/db/l3_hamode_db.py
neutron/tests/unit/db/test_l3_hamode_db.py

index 56fa3d0a756c915929031382f84140625984f89d..aefc46da282d410f4221f784b803299b9e06451c 100644 (file)
@@ -494,7 +494,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
             self, context, router_id):
         """Return a list of [(agent, ha_state), ...]."""
         bindings = self.get_ha_router_port_bindings(context, [router_id])
-        return [(binding.agent, binding.state) for binding in bindings]
+        return [(binding.agent, binding.state) for binding in bindings
+                if binding.agent is not None]
 
     def get_active_host_for_ha_router(self, context, router_id):
         bindings = self.get_l3_bindings_hosting_router_with_ha_states(
index 10b0bf4e5bd369fcfb1b29013c6f85347680f88f..fbfda4cf05b015cba6f3973b3c24462208772891 100644 (file)
@@ -160,8 +160,27 @@ class L3HATestCase(L3HATestFramework):
         self.assertIn((self.agent1['id'], 'active'), agent_ids)
         self.assertIn((self.agent2['id'], 'standby'), agent_ids)
 
+    def test_get_l3_bindings_hosting_router_with_ha_states_agent_none(self):
+        router = self._create_router()
+        # Do not bind router to leave agents as None
+        res = self.admin_ctx.session.query(
+            l3_hamode_db.L3HARouterAgentPortBinding).filter(
+            l3_hamode_db.L3HARouterAgentPortBinding.router_id == router['id']
+        ).all()
+        # Check that agents are None
+        self.assertEqual([None, None], [r.agent for r in res])
+        bindings = self.plugin.get_l3_bindings_hosting_router_with_ha_states(
+            self.admin_ctx, router['id'])
+        self.assertEqual([], bindings)
+
     def test_get_l3_bindings_hosting_router_with_ha_states_not_scheduled(self):
         router = self._create_router(ha=False)
+        # Check that there no L3 agents scheduled for this router
+        res = self.admin_ctx.session.query(
+            l3_hamode_db.L3HARouterAgentPortBinding).filter(
+            l3_hamode_db.L3HARouterAgentPortBinding.router_id == router['id']
+        ).all()
+        self.assertEqual([], [r.agent for r in res])
         bindings = self.plugin.get_l3_bindings_hosting_router_with_ha_states(
             self.admin_ctx, router['id'])
         self.assertEqual([], bindings)