Handle listener not found during loadbalancer status update

If a call to update loadbalancer status cannot find the
specified listener, the API server will throw an exception:

"Error while updating the load balancer status: 'NoneType'
 object has no attribute 'update'"

Change ListenerRepository.update() to check the DB query
returned a record, and if not, raise a NotFound exception
back to the caller.

Change-Id: I6693be3e2d2f0e34f19f07f55b0429f8fda317b2
Task: 41108
Story: 2008254
(cherry picked from commit 17ae2625da)
This commit is contained in:
Brian Haley 2020-10-21 11:59:17 -04:00 committed by Ann Taraday
parent e5c8aeffd6
commit b0b3086680
2 changed files with 7 additions and 0 deletions

View File

@ -1148,6 +1148,9 @@ class ListenerRepository(BaseRepository):
resource.tags = tags
listener_db = session.query(self.model_class).filter_by(
id=id).first()
if not listener_db:
raise exceptions.NotFound(
resource=data_models.Listener._name(), id=id)
# Verify any newly specified default_pool_id exists
default_pool_id = model_kwargs.get('default_pool_id')
if default_pool_id:

View File

@ -2952,6 +2952,10 @@ class TestListenerRepositoryTest(BaseRepositoryTest):
new_listener = self.listener_repo.get(self.session, id=listener.id)
self.assertIn(container1_dm, new_listener.sni_containers)
def test_update_bad_id(self):
self.assertRaises(exceptions.NotFound, self.listener_repo.update,
self.session, id=uuidutils.generate_uuid())
def test_delete(self):
listener = self.create_listener(self.FAKE_UUID_1, 80)
self.listener_repo.delete(self.session, id=listener.id)