Handle exception on searching for images

If an error occurs when search images,It will always be
a "creating" state, although the container has failed to create.
Add exception in in searching for images when create containers.

Change-Id: Ic1f3dd27e99bdf70848f7ca8750543fc30452350
Closes-bug: #1747374
This commit is contained in:
weikeyou 2018-02-05 16:51:14 +08:00
parent b7ac6127a6
commit 9c095cc4db

View File

@ -55,11 +55,17 @@ class API(object):
# before proceeding to create container. If image is not found, # before proceeding to create container. If image is not found,
# container create will fail with 400 status. # container create will fail with 400 status.
if CONF.api.enable_image_validation: if CONF.api.enable_image_validation:
images = self.rpcapi.image_search( try:
context, new_container.image, images = self.rpcapi.image_search(
new_container.image_driver, True, host_state['host']) context, new_container.image,
if not images: new_container.image_driver, True, host_state['host'])
raise exception.ImageNotFound(image=new_container.image) if not images:
raise exception.ImageNotFound(image=new_container.image)
except Exception as e:
new_container.status = consts.ERROR
new_container.status_reason = str(e)
new_container.save(context)
raise
self._record_action_start(context, new_container, self._record_action_start(context, new_container,
container_actions.CREATE) container_actions.CREATE)