Merge "Return meaningful error message on pool creation error"

This commit is contained in:
Jenkins 2014-03-24 10:25:03 +00:00 committed by Gerrit Code Review
commit c521c7bf42
4 changed files with 28 additions and 5 deletions

View File

@ -22,6 +22,7 @@ from neutron.api.v2 import base
from neutron.api.v2 import resource from neutron.api.v2 import resource
from neutron.common import constants from neutron.common import constants
from neutron.extensions import agent from neutron.extensions import agent
from neutron.extensions import loadbalancer
from neutron import manager from neutron import manager
from neutron.plugins.common import constants as plugin_const from neutron.plugins.common import constants as plugin_const
from neutron import policy from neutron import policy
@ -113,7 +114,7 @@ class Lbaas_agentscheduler(extensions.ExtensionDescriptor):
return {} return {}
class NoEligibleLbaasAgent(agent.AgentNotFound): class NoEligibleLbaasAgent(loadbalancer.NoEligibleBackend):
message = _("No eligible loadbalancer agent found " message = _("No eligible loadbalancer agent found "
"for pool %(pool_id)s.") "for pool %(pool_id)s.")

View File

@ -31,6 +31,10 @@ from neutron.services.service_base import ServicePluginBase
# Loadbalancer Exceptions # Loadbalancer Exceptions
class NoEligibleBackend(qexception.NotFound):
message = _("No eligible backend for pool %(pool_id)s")
class VipNotFound(qexception.NotFound): class VipNotFound(qexception.NotFound):
message = _("Vip %(vip_id)s could not be found") message = _("Vip %(vip_id)s could not be found")

View File

@ -21,6 +21,7 @@ from neutron import context
from neutron.db import api as qdbapi from neutron.db import api as qdbapi
from neutron.db.loadbalancer import loadbalancer_db as ldb from neutron.db.loadbalancer import loadbalancer_db as ldb
from neutron.db import servicetype_db as st_db 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 excutils
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
from neutron.plugins.common import constants 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 #because provider was not known to db plugin at pool creation
p['provider'] = provider_name p['provider'] = provider_name
driver = self.drivers[provider_name] driver = self.drivers[provider_name]
try:
driver.create_pool(context, p) 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 return p
def update_pool(self, context, id, pool): def update_pool(self, context, id, pool):

View File

@ -24,6 +24,7 @@ from neutron import context
from neutron.db import servicetype_db as st_db from neutron.db import servicetype_db as st_db
from neutron.extensions import agent from neutron.extensions import agent
from neutron.extensions import lbaas_agentscheduler from neutron.extensions import lbaas_agentscheduler
from neutron.extensions import loadbalancer
from neutron import manager from neutron import manager
from neutron.plugins.common import constants as plugin_const from neutron.plugins.common import constants as plugin_const
from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer 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(1, len(pools['pools']))
self.assertEqual(pool['pool'], pools['pools'][0]) 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 = { lbaas_hosta = {
'binary': 'neutron-loadbalancer-agent', 'binary': 'neutron-loadbalancer-agent',
'host': LBAAS_HOSTA, 'host': LBAAS_HOSTA,
@ -141,8 +142,12 @@ class LBaaSAgentSchedulerTestCase(test_agent_ext_plugin.AgentDBTestMixIn,
'description': 'test'}} 'description': 'test'}}
lbaas_plugin = manager.NeutronManager.get_service_plugins()[ lbaas_plugin = manager.NeutronManager.get_service_plugins()[
plugin_const.LOADBALANCER] plugin_const.LOADBALANCER]
self.assertRaises(lbaas_agentscheduler.NoEligibleLbaasAgent, self.assertRaises(loadbalancer.NoEligibleBackend,
lbaas_plugin.create_pool, self.adminContext, pool) 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): def test_schedule_pool_with_down_agent(self):
lbaas_hosta = { lbaas_hosta = {
@ -171,9 +176,13 @@ class LBaaSAgentSchedulerTestCase(test_agent_ext_plugin.AgentDBTestMixIn,
'description': 'test'}} 'description': 'test'}}
lbaas_plugin = manager.NeutronManager.get_service_plugins()[ lbaas_plugin = manager.NeutronManager.get_service_plugins()[
plugin_const.LOADBALANCER] plugin_const.LOADBALANCER]
self.assertRaises(lbaas_agentscheduler.NoEligibleLbaasAgent, self.assertRaises(loadbalancer.NoEligibleBackend,
lbaas_plugin.create_pool, lbaas_plugin.create_pool,
self.adminContext, 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): def test_pool_unscheduling_on_pool_deletion(self):
self._register_agent_states(lbaas_agents=True) self._register_agent_states(lbaas_agents=True)