]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Return meaningful error message on pool creation error
authorEugene Nikanorov <enikanorov@mirantis.com>
Thu, 20 Mar 2014 14:43:18 +0000 (18:43 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Fri, 21 Mar 2014 11:15:08 +0000 (15:15 +0400)
Instead of returning exception specific to haproxy (agent-based),
return more generic BackendNotFound exception.
It also could be used later when binding to devices will be
introduced. That exception will indicate scheduling failure, e.g.
inability to find appropriate backend for the resource.
Resource (pool) is then marked with ERROR state with corresponding
error description.

Change-Id: Ic18ff20102b4bb2b97e7b186fcf797133bd3ba3d
Closes-Bug: #1295214

neutron/extensions/lbaas_agentscheduler.py
neutron/extensions/loadbalancer.py
neutron/services/loadbalancer/plugin.py
neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py

index 2ee7a5daaadf186952a46367aca2b7cf3363bf54..3463db93627a378f287158fa7d5f547458e134ea 100644 (file)
@@ -22,6 +22,7 @@ from neutron.api.v2 import base
 from neutron.api.v2 import resource
 from neutron.common import constants
 from neutron.extensions import agent
+from neutron.extensions import loadbalancer
 from neutron import manager
 from neutron.plugins.common import constants as plugin_const
 from neutron import policy
@@ -113,7 +114,7 @@ class Lbaas_agentscheduler(extensions.ExtensionDescriptor):
         return {}
 
 
-class NoEligibleLbaasAgent(agent.AgentNotFound):
+class NoEligibleLbaasAgent(loadbalancer.NoEligibleBackend):
     message = _("No eligible loadbalancer agent found "
                 "for pool %(pool_id)s.")
 
index 67c231490b22ccdc083111af739d98794fef04e4..c534b77f72a0dc753da79e2221cf923ac7313dfc 100644 (file)
@@ -31,6 +31,10 @@ from neutron.services.service_base import ServicePluginBase
 
 
 # Loadbalancer Exceptions
+class NoEligibleBackend(qexception.NotFound):
+    message = _("No eligible backend for pool %(pool_id)s")
+
+
 class VipNotFound(qexception.NotFound):
     message = _("Vip %(vip_id)s could not be found")
 
index b87b7a85aab782f3cf8c52d27fdb7fb020dfe7ec..a95e658413940e58712b04c7d6301b1c09367cbf 100644 (file)
@@ -21,6 +21,7 @@ from neutron import context
 from neutron.db import api as qdbapi
 from neutron.db.loadbalancer import loadbalancer_db as ldb
 from neutron.db import servicetype_db as st_db
+from neutron.extensions import loadbalancer
 from neutron.openstack.common import excutils
 from neutron.openstack.common import log as logging
 from neutron.plugins.common import constants
@@ -154,7 +155,15 @@ class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
         #because provider was not known to db plugin at pool creation
         p['provider'] = provider_name
         driver = self.drivers[provider_name]
-        driver.create_pool(context, p)
+        try:
+            driver.create_pool(context, p)
+        except loadbalancer.NoEligibleBackend:
+            # that should catch cases when backend of any kind
+            # is not available (agent, appliance, etc)
+            self.update_status(context, ldb.Pool,
+                               p['id'], constants.ERROR,
+                               "No eligible backend")
+            raise loadbalancer.NoEligibleBackend(pool_id=p['id'])
         return p
 
     def update_pool(self, context, id, pool):
index e9e1f38821dfa78165c77269709fb3b2b22fdd31..5ee947944bf6fd2caf8f8aad57ee2788f4ceff93 100644 (file)
@@ -24,6 +24,7 @@ from neutron import context
 from neutron.db import servicetype_db as st_db
 from neutron.extensions import agent
 from neutron.extensions import lbaas_agentscheduler
+from neutron.extensions import loadbalancer
 from neutron import manager
 from neutron.plugins.common import constants as plugin_const
 from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
@@ -117,7 +118,7 @@ class LBaaSAgentSchedulerTestCase(test_agent_ext_plugin.AgentDBTestMixIn,
             self.assertEqual(1, len(pools['pools']))
             self.assertEqual(pool['pool'], pools['pools'][0])
 
-    def test_schedule_poll_with_disabled_agent(self):
+    def test_schedule_pool_with_disabled_agent(self):
         lbaas_hosta = {
             'binary': 'neutron-loadbalancer-agent',
             'host': LBAAS_HOSTA,
@@ -141,8 +142,12 @@ class LBaaSAgentSchedulerTestCase(test_agent_ext_plugin.AgentDBTestMixIn,
                          'description': 'test'}}
         lbaas_plugin = manager.NeutronManager.get_service_plugins()[
             plugin_const.LOADBALANCER]
-        self.assertRaises(lbaas_agentscheduler.NoEligibleLbaasAgent,
+        self.assertRaises(loadbalancer.NoEligibleBackend,
                           lbaas_plugin.create_pool, self.adminContext, pool)
+        pools = lbaas_plugin.get_pools(self.adminContext)
+        self.assertEqual('ERROR', pools[0]['status'])
+        self.assertEqual('No eligible backend',
+                         pools[0]['status_description'])
 
     def test_schedule_pool_with_down_agent(self):
         lbaas_hosta = {
@@ -171,9 +176,13 @@ class LBaaSAgentSchedulerTestCase(test_agent_ext_plugin.AgentDBTestMixIn,
                              'description': 'test'}}
             lbaas_plugin = manager.NeutronManager.get_service_plugins()[
                 plugin_const.LOADBALANCER]
-            self.assertRaises(lbaas_agentscheduler.NoEligibleLbaasAgent,
+            self.assertRaises(loadbalancer.NoEligibleBackend,
                               lbaas_plugin.create_pool,
                               self.adminContext, pool)
+            pools = lbaas_plugin.get_pools(self.adminContext)
+            self.assertEqual('ERROR', pools[0]['status'])
+            self.assertEqual('No eligible backend',
+                             pools[0]['status_description'])
 
     def test_pool_unscheduling_on_pool_deletion(self):
         self._register_agent_states(lbaas_agents=True)