From dc661e3899093732c551c5c9d91ef8359e1ebed6 Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Thu, 20 Mar 2014 18:43:18 +0400 Subject: [PATCH] Return meaningful error message on pool creation error 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 | 3 ++- neutron/extensions/loadbalancer.py | 4 ++++ neutron/services/loadbalancer/plugin.py | 11 ++++++++++- .../services/loadbalancer/test_agent_scheduler.py | 15 ++++++++++++--- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/neutron/extensions/lbaas_agentscheduler.py b/neutron/extensions/lbaas_agentscheduler.py index 2ee7a5daaa..3463db9362 100644 --- a/neutron/extensions/lbaas_agentscheduler.py +++ b/neutron/extensions/lbaas_agentscheduler.py @@ -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.") diff --git a/neutron/extensions/loadbalancer.py b/neutron/extensions/loadbalancer.py index 67c231490b..c534b77f72 100644 --- a/neutron/extensions/loadbalancer.py +++ b/neutron/extensions/loadbalancer.py @@ -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") diff --git a/neutron/services/loadbalancer/plugin.py b/neutron/services/loadbalancer/plugin.py index b87b7a85aa..a95e658413 100644 --- a/neutron/services/loadbalancer/plugin.py +++ b/neutron/services/loadbalancer/plugin.py @@ -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): diff --git a/neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py b/neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py index e9e1f38821..5ee947944b 100644 --- a/neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py +++ b/neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py @@ -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)