Merge "LBaaS: throw proper exception on duplicating monitor association"
This commit is contained in:
commit
ea16d6583a
@ -565,6 +565,13 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
|
||||
def create_pool_health_monitor(self, context, health_monitor, pool_id):
|
||||
monitor_id = health_monitor['health_monitor']['id']
|
||||
with context.session.begin(subtransactions=True):
|
||||
assoc_qry = context.session.query(PoolMonitorAssociation)
|
||||
assoc = assoc_qry.filter_by(pool_id=pool_id,
|
||||
monitor_id=monitor_id).first()
|
||||
if assoc:
|
||||
raise loadbalancer.PoolMonitorAssociationExists(
|
||||
monitor_id=monitor_id, pool_id=pool_id)
|
||||
|
||||
pool = self._get_resource(context, Pool, pool_id)
|
||||
|
||||
assoc = PoolMonitorAssociation(pool_id=pool_id,
|
||||
|
@ -54,6 +54,11 @@ class PoolMonitorAssociationNotFound(qexception.NotFound):
|
||||
"with Pool %(pool_id)s")
|
||||
|
||||
|
||||
class PoolMonitorAssociationExists(qexception.Conflict):
|
||||
message = _('health_monitor %(monitor_id)s is already associated '
|
||||
'with pool %(pool_id)s')
|
||||
|
||||
|
||||
class StateInvalid(qexception.NeutronException):
|
||||
message = _("Invalid state %(state)s of Loadbalancer resource %(id)s")
|
||||
|
||||
|
@ -1210,6 +1210,24 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
|
||||
driver_call.assert_called_once_with(
|
||||
mock.ANY, hm['health_monitor'], pool['pool']['id'])
|
||||
|
||||
def test_create_pool_health_monitor_already_associated(self):
|
||||
with contextlib.nested(
|
||||
self.pool(name="pool"),
|
||||
self.health_monitor(),
|
||||
) as (pool, hm):
|
||||
res = self.plugin.create_pool_health_monitor(
|
||||
context.get_admin_context(),
|
||||
hm, pool['pool']['id']
|
||||
)
|
||||
self.assertEqual({'health_monitor':
|
||||
[hm['health_monitor']['id']]},
|
||||
res)
|
||||
self.assertRaises(loadbalancer.PoolMonitorAssociationExists,
|
||||
self.plugin.create_pool_health_monitor,
|
||||
context.get_admin_context(),
|
||||
hm,
|
||||
pool['pool']['id'])
|
||||
|
||||
def test_create_pool_healthmon_invalid_pool_id(self):
|
||||
with self.health_monitor() as healthmon:
|
||||
self.assertRaises(loadbalancer.PoolNotFound,
|
||||
|
Loading…
Reference in New Issue
Block a user