]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add transaction for setting agent_id in L3HARouterAgentPortBinding
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Fri, 25 Sep 2015 12:30:30 +0000 (15:30 +0300)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Fri, 13 Nov 2015 09:59:33 +0000 (09:59 +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.

Closes-Bug: #1499647

Change-Id: Iaad82fe522cfd70061daecf411c924fdc11b7e41

neutron/scheduler/l3_agent_scheduler.py

index 844c640bb4152f58d7f5e5da4ed8011935b15969..63258c2afba5ad8d3ae6a21633d78a2c2643c552 100644 (file)
@@ -292,9 +292,10 @@ class L3Scheduler(object):
                                 tenant_id, agent):
         """Creates and binds a new HA port for this agent."""
         ha_network = plugin.get_ha_network(context, tenant_id)
-        port_binding = plugin.add_ha_port(context.elevated(), router_id,
-                                          ha_network.network.id, tenant_id)
-        port_binding.l3_agent_id = agent['id']
+        with context.session.begin(subtransactions=True):
+            port_binding = plugin.add_ha_port(context.elevated(), router_id,
+                                              ha_network.network.id, tenant_id)
+            port_binding.l3_agent_id = agent['id']
         self.bind_router(context, router_id, agent)
 
     def _schedule_ha_routers_to_additional_agent(self, plugin, context, agent):
@@ -327,8 +328,9 @@ class L3Scheduler(object):
         port_bindings = plugin.get_ha_router_port_bindings(context,
                                                            [router_id])
         for port_binding, agent in zip(port_bindings, chosen_agents):
-            port_binding.l3_agent_id = agent.id
-            self.bind_router(context, router_id, agent)
+            with context.session.begin(subtransactions=True):
+                port_binding.l3_agent_id = agent.id
+                self.bind_router(context, router_id, agent)
 
             LOG.debug('HA Router %(router_id)s is scheduled to L3 agent '
                       '%(agent_id)s)',