Fix bug when rolling back prov and op status for some API calls

POST l7rule API call and PUT pool API call had a bug that might have
kept a load balancer in provisioning_status when the call was rejected
by the provider.

The code didn't use the right locked DB session to set the statuses and
then to rollback them when an exception was caught.

Story 2010210
Task 45947

Change-Id: I494ea357afc072360765d7a30a9488e08bfda52c
This commit is contained in:
Gregory Thiemonge 2022-08-08 18:14:45 +02:00
parent e962401585
commit fdcea400c6
5 changed files with 44 additions and 2 deletions

View File

@ -157,7 +157,7 @@ class L7RuleController(base.BaseController):
l7rule_dict = db_prepare.create_l7rule(
l7rule.to_dict(render_unsets=True), self.l7policy_id)
self._test_lb_listener_policy_statuses(context.session)
self._test_lb_listener_policy_statuses(lock_session)
db_l7rule = self._validate_create_l7rule(lock_session, l7rule_dict)

View File

@ -460,7 +460,7 @@ class PoolsController(base.BaseController):
with db_api.get_lock_session() as lock_session:
self._test_lb_and_listener_statuses(
context.session, lb_id=db_pool.load_balancer_id,
lock_session, lb_id=db_pool.load_balancer_id,
listener_ids=self._get_affected_listener_ids(db_pool))
# Prepare the data for the driver data model

View File

@ -1304,3 +1304,19 @@ class TestL7Rule(base.BaseAPITest):
self.set_lb_status(self.lb_id, status=constants.DELETED)
self.delete(self.l7rule_path.format(l7rule_id=l7rule.get('id')),
status=404)
@mock.patch("octavia.api.drivers.noop_driver.driver.NoopManager."
"l7rule_create")
def test_create_with_exception_in_provider_driver(self,
l7rule_create_mock):
l7rule_create_mock.side_effect = Exception("Provider error")
self.create_l7rule(
self.l7policy_id, constants.L7RULE_TYPE_PATH,
constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
'/api', status=500)
lb = self.get(self.LB_PATH.format(lb_id=self.lb_id)).json.get(
"loadbalancer")
self.assertEqual(lb[constants.PROVISIONING_STATUS],
constants.ACTIVE)

View File

@ -2706,3 +2706,24 @@ class TestPool(base.BaseAPITest):
'Invalid input for field/attribute alpn_protocols', fault)
self.assertIn('Value should be a valid ALPN protocol ID', fault)
self.assert_correct_status(lb_id=self.lb_id)
@mock.patch("octavia.api.drivers.noop_driver.driver.NoopManager."
"pool_update")
def test_update_with_exception_in_provider_driver(self, pool_update_mock):
pool_update_mock.side_effect = Exception("Provider error")
api_pool = self.create_pool(
self.lb_id,
constants.PROTOCOL_HTTP,
constants.LB_ALGORITHM_ROUND_ROBIN,
listener_id=self.listener_id).get(self.root_tag)
self.set_lb_status(lb_id=self.lb_id)
new_pool = {'name': 'foo'}
self.put(self.POOL_PATH.format(pool_id=api_pool.get('id')),
self._build_body(new_pool), status=500)
lb = self.get(self.LB_PATH.format(lb_id=self.lb_id)).json.get(
"loadbalancer")
self.assertEqual(lb[constants.PROVISIONING_STATUS],
constants.ACTIVE)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fix load balancers stuck in PENDING_UPDATE issues for some API calls (POST
/l7rule, PUT /pool) when a provider denied the call.