Fix non-cascade LB delete with children

When the user attempts to delete a load balancer, without the cascade option,
the load balancer is locked in "PENDING_DELETE" prior to the check for child
objects. The child object check will return the error to the user, but would
leave the load balancer locked in "PENDING_DELETE".
This patch corrects the order to do the validation prior to locking the
load balancer in "PENDING_DELETE".

Change-Id: If1694743d098b1c1337601770a7b3466a43dda07
Story: 2001256
Task: 5786
This commit is contained in:
Michael Johnson 2017-10-23 10:40:17 -07:00
parent ba0f87f84a
commit c05a8cfb88
2 changed files with 5 additions and 5 deletions

View File

@ -238,12 +238,12 @@ class LoadBalancersController(base.BaseController):
"""Deletes a load balancer."""
context = pecan.request.context.get('octavia_context')
db_lb = self._get_db_lb(context.session, id)
self._test_lb_status(context.session, id,
lb_status=constants.PENDING_DELETE)
if (db_lb.listeners or db_lb.pools) and not cascade:
msg = _("Cannot delete Load Balancer %s - it has children") % id
LOG.exception(msg)
LOG.warning(msg)
raise exceptions.ValidationException(detail=msg)
self._test_lb_status(context.session, id,
lb_status=constants.PENDING_DELETE)
try:
LOG.info("Sending deleted Load Balancer %s to the handler",

View File

@ -441,13 +441,13 @@ class LoadBalancersController(base.BaseController):
constants.RBAC_DELETE)
with db_api.get_lock_session() as lock_session:
self._test_lb_status(lock_session, id,
lb_status=constants.PENDING_DELETE)
if (db_lb.listeners or db_lb.pools) and not cascade:
msg = _("Cannot delete Load Balancer %s - "
"it has children") % id
LOG.warning(msg)
raise exceptions.ValidationException(detail=msg)
self._test_lb_status(lock_session, id,
lb_status=constants.PENDING_DELETE)
try:
LOG.info("Sending deleted Load Balancer %s to the handler", id)