]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix InvalidRequestError in auto_schedule_routers
authorarmando-migliaccio <armamig@gmail.com>
Fri, 22 Aug 2014 15:21:09 +0000 (08:21 -0700)
committerArmando Migliaccio <armamig@gmail.com>
Wed, 27 Aug 2014 05:11:53 +0000 (05:11 +0000)
This was discussed in review [1], and was deferred until the time was ripe
for the appropriate fix. As suggested and reported, auto_schedule_routers
is too affected by this error.

This patch takes care of the issue, in a similar way.

[1] - https://review.openstack.org/#/c/112740/

Related-bug: #1354072
Closes-bug: #1360104

Change-Id: Ie3cb0c31dfa571c694cd38e19f72ff8503815635

neutron/scheduler/l3_agent_scheduler.py
neutron/tests/unit/test_l3_schedulers.py

index c07faba7db329a736207f1e9abfb6caeac421d69..5e3823fb56d046bd67529f7be0156acee67ef22c 100644 (file)
@@ -116,26 +116,25 @@ class L3Scheduler(object):
 
         :returns: True if routers have been successfully assigned to host
         """
-        with context.session.begin(subtransactions=True):
-            l3_agent = plugin.get_enabled_agent_on_host(
-                context, constants.AGENT_TYPE_L3, host)
-            if not l3_agent:
-                return False
-
-            unscheduled_routers = self.get_routers_to_schedule(
-                context, plugin, router_ids)
-            if not unscheduled_routers:
-                return False
-
-            target_routers = self.get_routers_can_schedule(
-                context, plugin, unscheduled_routers, l3_agent)
-            if not target_routers:
-                LOG.warn(_('No routers compatible with L3 agent configuration'
-                           ' on host %s'), host)
-                return False
-
-            self.bind_routers(context, target_routers, l3_agent)
-            return True
+        l3_agent = plugin.get_enabled_agent_on_host(
+            context, constants.AGENT_TYPE_L3, host)
+        if not l3_agent:
+            return False
+
+        unscheduled_routers = self.get_routers_to_schedule(
+            context, plugin, router_ids)
+        if not unscheduled_routers:
+            return False
+
+        target_routers = self.get_routers_can_schedule(
+            context, plugin, unscheduled_routers, l3_agent)
+        if not target_routers:
+            LOG.warn(_('No routers compatible with L3 agent configuration'
+                       ' on host %s'), host)
+            return False
+
+        self.bind_routers(context, target_routers, l3_agent)
+        return True
 
     def get_candidates(self, plugin, context, sync_router, subnet_id):
         """Return L3 agents where a router could be scheduled."""
index 86d7c0d0a0004c3df21be407d5ebee4afffd28c7..5aa75562fbc26a0b7cf9420ffc199fdfdf84a719 100644 (file)
@@ -100,7 +100,6 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
         super(L3SchedulerBaseTestCase, self).setUp()
         self.scheduler = FakeL3Scheduler()
         self.plugin = mock.Mock()
-        self.context = q_context.get_admin_context()
 
     def test_auto_schedule_routers(self):
         self.plugin.get_enabled_agent_on_host.return_value = [mock.ANY]
@@ -109,7 +108,7 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
             mock.patch.object(self.scheduler, 'get_routers_can_schedule')) as (
             gs, gr):
             result = self.scheduler.auto_schedule_routers(
-                self.plugin, self.context, mock.ANY, mock.ANY)
+                self.plugin, mock.ANY, mock.ANY, mock.ANY)
         self.assertTrue(self.plugin.get_enabled_agent_on_host.called)
         self.assertTrue(result)
         self.assertTrue(gs.called)
@@ -118,7 +117,7 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
     def test_auto_schedule_routers_no_agents(self):
         self.plugin.get_enabled_agent_on_host.return_value = None
         result = self.scheduler.auto_schedule_routers(
-            self.plugin, self.context, mock.ANY, mock.ANY)
+            self.plugin, mock.ANY, mock.ANY, mock.ANY)
         self.assertTrue(self.plugin.get_enabled_agent_on_host.called)
         self.assertFalse(result)
 
@@ -127,7 +126,7 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
                                'get_routers_to_schedule') as mock_routers:
             mock_routers.return_value = None
             result = self.scheduler.auto_schedule_routers(
-                self.plugin, self.context, mock.ANY, mock.ANY)
+                self.plugin, mock.ANY, mock.ANY, mock.ANY)
         self.assertTrue(self.plugin.get_enabled_agent_on_host.called)
         self.assertFalse(result)
 
@@ -140,7 +139,7 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
             mock_unscheduled_routers.return_value = mock.ANY
             mock_target_routers.return_value = None
             result = self.scheduler.auto_schedule_routers(
-                self.plugin, self.context, mock.ANY, mock.ANY)
+                self.plugin, mock.ANY, mock.ANY, mock.ANY)
         self.assertTrue(self.plugin.get_enabled_agent_on_host.called)
         self.assertFalse(result)