From 6f12f45f457202feb510d668fa2dc6a867408c41 Mon Sep 17 00:00:00 2001 From: miaohb Date: Mon, 15 May 2017 19:37:51 +0800 Subject: [PATCH] Handle the case when get_by_host_and_binary return None This patch adds the code for get_by_host_and_binary return None in service delete. Change-Id: I37f8fcbcc4786f0b0a886b00784d635e9b8607f8 --- zun/api/controllers/v1/zun_services.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zun/api/controllers/v1/zun_services.py b/zun/api/controllers/v1/zun_services.py index 6b3dc0b51..b1ae8f594 100644 --- a/zun/api/controllers/v1/zun_services.py +++ b/zun/api/controllers/v1/zun_services.py @@ -83,5 +83,10 @@ class ZunServiceController(base.Controller): context = pecan.request.context policy.enforce(context, "zun-service:delete", action="zun-service:delete") - objects.ZunService.get_by_host_and_binary( - context, host, binary).destroy(context) + svc = objects.ZunService.get_by_host_and_binary( + context, host, binary) + if svc is None: + raise exception.ZunServiceNotFound( + binary=binary, host=host) + else: + svc.destroy(context)