Allow deletion of ERRORed load balancers

The API was not allowing the deletion of load balancers in ERROR state.
Users should be able to delete their load balancers in ACTIVE or ERROR
state.  This is good for users and good for operators.

Change-Id: Ie40b062e1b5cc6d90274190676fb81ee1c32e63e
Closes-Bug: #1607502
This commit is contained in:
Brandon Logan 2016-07-28 14:27:27 -05:00
parent 114eacdd34
commit 0fa0828432
4 changed files with 24 additions and 1 deletions

View File

@ -63,6 +63,7 @@ SUPPORTED_PROVISIONING_STATUSES = (ACTIVE, AMPHORA_ALLOCATED,
PENDING_DELETE, PENDING_CREATE,
PENDING_UPDATE, DELETED, ERROR)
MUTABLE_STATUSES = (ACTIVE,)
DELETABLE_STATUSES = (ACTIVE, ERROR)
SUPPORTED_AMPHORA_STATUSES = (AMPHORA_ALLOCATED, AMPHORA_BOOTING,
AMPHORA_READY, DELETED, PENDING_DELETE)

View File

@ -322,7 +322,12 @@ class LoadBalancerRepository(BaseRepository):
with session.begin(subtransactions=True):
lb = session.query(self.model_class).with_for_update().filter_by(
id=id).one()
if lb.provisioning_status not in constants.MUTABLE_STATUSES:
is_delete = status == constants.PENDING_DELETE
acceptable_statuses = (
constants.DELETABLE_STATUSES
if is_delete else constants.MUTABLE_STATUSES
)
if lb.provisioning_status not in acceptable_statuses:
return False
lb.provisioning_status = status
session.add(lb)

View File

@ -200,6 +200,12 @@ class TestLoadBalancer(base.BaseAPITest):
self.put(self.LB_PATH.format(lb_id=lb.get('id')), lb_json)
self.delete(self.LB_PATH.format(lb_id=lb.get('id')), status=409)
def test_delete_with_error_status(self):
lb = self.create_load_balancer({}, name='lb1', description='desc1',
enabled=False)
lb = self.set_lb_status(lb.get('id'), status=constants.ERROR)
self.delete(self.LB_PATH.format(lb_id=lb.get('id')), status=202)
def test_update_pending_delete(self):
lb = self.create_load_balancer({}, name='lb1', description='desc1',
enabled=False)

View File

@ -1250,6 +1250,17 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
lb = self.lb_repo.get(self.session, id=lb_id)
self.assertEqual(constants.PENDING_UPDATE, lb.provisioning_status)
def test_test_and_set_provisioning_status_error_on_delete(self):
lb_id = uuidutils.generate_uuid()
self.lb_repo.create(self.session, id=lb_id,
provisioning_status=constants.ERROR,
operating_status=constants.OFFLINE,
enabled=True)
self.lb_repo.test_and_set_provisioning_status(
self.session, lb_id, constants.PENDING_DELETE)
lb = self.lb_repo.get(self.session, id=lb_id)
self.assertEqual(constants.PENDING_DELETE, lb.provisioning_status)
def test_check_load_balancer_expired_default_exp_age(self):
"""When exp_age defaults to load_balancer_expiry_age."""
newdate = datetime.datetime.utcnow() - datetime.timedelta(minutes=10)