Merge "Ignore status update on deleted objects in driver-agent"

This commit is contained in:
Zuul 2022-07-08 13:22:56 +00:00 committed by Gerrit Code Review
commit 65b1c341e2
2 changed files with 50 additions and 1 deletions

View File

@ -58,6 +58,13 @@ class DriverUpdater(object):
def _decrement_quota(self, repo, object_name, record_id):
lock_session = db_apis.get_session(autocommit=False)
db_object = repo.get(lock_session, id=record_id)
if db_object is None:
lock_session.rollback()
msg = ('{} with ID of {} is not present in the '
'database, it might have already been deleted. '
'Skipping quota update.'.format(
object_name, record_id))
raise driver_exceptions.NotFound(msg)
try:
if db_object.provisioning_status == consts.DELETED:
LOG.info('%(name)s with ID of %(id)s is already in the '
@ -91,7 +98,12 @@ class DriverUpdater(object):
if object_name == consts.LOADBALANCERS:
self._check_for_lb_vip_deallocate(repo, record_id)
self._decrement_quota(repo, object_name, record_id)
try:
self._decrement_quota(repo, object_name, record_id)
except driver_exceptions.NotFound:
# prov_status is DELETED and the object no longer
# exists in the DB, ignore the update.
return
if delete_record and object_name != consts.LOADBALANCERS:
repo.delete(self.db_session, id=record_id)

View File

@ -342,3 +342,40 @@ class DriverAgentTest(base.OctaviaDBTestBase):
# Test non-existent L7 rule
result = self.driver_lib.get_l7rule('bogus')
self.assertIsNone(result)
def test_update_load_balancer_status(self):
# Add a new member
member_dict = copy.deepcopy(self.sample_data.test_member2_dict)
self.repos.member.create(self.session, **member_dict)
result = self.driver_lib.get_member(member_dict[lib_consts.ID])
self.assertEqual(self.sample_data.provider_member2_dict,
result.to_dict(render_unsets=True))
# Test deleting a member
status = {
"loadbalancers": [
{"id": self.sample_data.lb_id,
"provisioning_status": "ACTIVE",
"operating_status": "ONLINE"}
],
"healthmonitors": [],
"l7policies": [],
"l7rules": [],
"listeners": [],
"members": [
{"id": member_dict[lib_consts.ID],
"provisioning_status": "DELETED"}
],
"pools": []
}
self.driver_lib.update_loadbalancer_status(status)
result = self.driver_lib.get_member(member_dict[lib_consts.ID])
self.assertIsNone(result)
# Test deleting an already deleted member
# It should be silently ignored
self.driver_lib.update_loadbalancer_status(status)
result = self.driver_lib.get_member(member_dict[lib_consts.ID])
self.assertIsNone(result)