Image: Catch glance image not found exception

If we run a container from a glance image uuid, zun will fail as 500
error.

Fix this by catching NotFound exception while try to get image by uuid

Change-Id: I0620caad085b9e4bbae9fb9a57956329826e5fc7
Closes-Bug: #1691320
This commit is contained in:
taget 2017-05-17 07:01:01 +00:00
parent fa4f0ce8b4
commit 45ab53ff98

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from glanceclient.common import exceptions as glance_exceptions
from oslo_utils import uuidutils
from zun.common import clients
@ -45,9 +46,13 @@ def find_images(context, image_ident, exact_match):
glance = create_glanceclient(context)
if uuidutils.is_uuid_like(image_ident):
images = []
image = glance.images.get(image_ident)
if image.container_format == 'docker':
images.append(image)
try:
image = glance.images.get(image_ident)
if image.container_format == 'docker':
images.append(image)
except glance_exceptions.NotFound:
# ignore exception
pass
else:
filters = {'container_format': 'docker'}
images = list(glance.images.list(filters=filters))