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
This commit is contained in:
miaohb
2017-05-15 19:37:51 +08:00
parent f450740c09
commit 6f12f45f45

View File

@@ -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)