From aee7b890496d2d30637ef57e8e236957dc2171ad Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 13 Nov 2013 20:17:19 +0000 Subject: [PATCH] [ADMIN_API] Handle case that shouldn't happen If a device fails and there is no VIP assigned an exception is thrown. This state shouldn't happen but did in a 4.18 setup that was upgrade to 4.19 The device in question would have gone wrong in 4.18 Change-Id: I8173e4eb34fed456b679df751181aad3ac78b534 --- .../admin_api/stats/drivers/database/driver.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libra/admin_api/stats/drivers/database/driver.py b/libra/admin_api/stats/drivers/database/driver.py index f6c2e0fd..24bfca7d 100644 --- a/libra/admin_api/stats/drivers/database/driver.py +++ b/libra/admin_api/stats/drivers/database/driver.py @@ -111,7 +111,8 @@ class DbDriver(AlertDriver): new_device = session.query(Device).\ filter(Device.id == new_device_id).first() vip = session.query(Vip).filter(Vip.device == device_id).first() - vip.device = new_device_id + if vip: + vip.device = new_device_id device = session.query(Device).\ filter(Device.id == device_id).first() device.status = 'DELETED' @@ -120,12 +121,13 @@ class DbDriver(AlertDriver): filter(Device.id == new_device_id).all() for lb in lbs: lb.errmsg = "Load Balancer rebuild on new device" - LOG.info( - "Moving IP {0} and marking device {1} for deletion" - .format(str(ipaddress.IPv4Address(vip.ip)), device_id) - ) - submit_vip_job( - 'ASSIGN', new_device_name, vip.id - ) + if vip: + LOG.info( + "Moving IP {0} and marking device {1} for deletion" + .format(str(ipaddress.IPv4Address(vip.ip)), device_id) + ) + submit_vip_job( + 'ASSIGN', new_device_name, vip.id + ) new_device.status = 'ONLINE' session.commit()