From 3bbd32a2a5588ab1502efdb6f9556c646d6e8f19 Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Fri, 21 Feb 2020 10:48:43 +0100 Subject: [PATCH] Fix uncaught DB exception when trying to get a spare amphora The MapLoadbalancerToAmphora task performs some database queries but doesn't catch any exception from it. In case something goes wrong with the database or the query, this commit catchs any exception from the DB call, logs it and then returns None to switch to the next decider branch (boot a new amphora). Story 2007320 Task 38831 Change-Id: Ifb6c34426e0927534d332a8bbf2c66aac6c002c5 --- .../controller/worker/v1/tasks/database_tasks.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/octavia/controller/worker/v1/tasks/database_tasks.py b/octavia/controller/worker/v1/tasks/database_tasks.py index 55a1c1308d..b3eefb020b 100644 --- a/octavia/controller/worker/v1/tasks/database_tasks.py +++ b/octavia/controller/worker/v1/tasks/database_tasks.py @@ -529,10 +529,17 @@ class MapLoadbalancerToAmphora(BaseDatabaseTask): else: amp_az = CONF.nova.availability_zone - amp = self.amphora_repo.allocate_and_associate( - db_apis.get_session(), - loadbalancer_id, - amp_az) + try: + amp = self.amphora_repo.allocate_and_associate( + db_apis.get_session(), + loadbalancer_id, + amp_az) + except Exception as e: + LOG.error("Failed to get a spare amphora (AZ: {}) for " + "loadbalancer {} due to: {}".format( + amp_az, loadbalancer_id, e)) + return None + if amp is None: LOG.debug("No Amphora available for load balancer with id %s", loadbalancer_id)