diff --git a/data/model/image.py b/data/model/image.py index c1f1eba38..d1ec8563b 100644 --- a/data/model/image.py +++ b/data/model/image.py @@ -139,8 +139,8 @@ def get_repository_images(namespace_name, repository_name): def get_image_by_id(namespace_name, repository_name, docker_image_id): image = get_repo_image_extended(namespace_name, repository_name, docker_image_id) if not image: - raise DataModelException('Unable to find image \'%s\' for repo \'%s/%s\'' % - (docker_image_id, namespace_name, repository_name)) + raise InvalidImageException('Unable to find image \'%s\' for repo \'%s/%s\'' % + (docker_image_id, namespace_name, repository_name)) return image diff --git a/endpoints/v1/registry.py b/endpoints/v1/registry.py index 42ad34ba1..2f9c9d5cb 100644 --- a/endpoints/v1/registry.py +++ b/endpoints/v1/registry.py @@ -383,7 +383,11 @@ def get_image_ancestry(namespace, repository, image_id, headers): if not permission.can() and not model.repository.repository_is_public(namespace, repository): abort(403) - image = model.image.get_image_by_id(namespace, repository, image_id) + try: + image = model.image.get_image_by_id(namespace, repository, image_id) + except model.InvalidImageException: + abort(404, 'Image %(image_id)s not found', issue='unknown-image', image_id=image_id) + parents = model.image.get_parent_images(namespace, repository, image) ancestry_docker_ids = [image.docker_image_id] diff --git a/test/test_gc.py b/test/test_gc.py index 27f67f82a..aee5119ee 100644 --- a/test/test_gc.py +++ b/test/test_gc.py @@ -68,9 +68,15 @@ class TestGarbageCollection(unittest.TestCase): if not image_id in image_map: image_map[image_id] = self.createImage(image_id, repo, namespace) + v1_metadata = { + 'id': image_id, + } + if parent is not None: + v1_metadata['parent'] = parent.docker_image_id + # Set the ancestors for the image. parent = model.image.set_image_metadata(image_id, namespace, name, '', '', '', - parent=parent) + v1_metadata, parent=parent) # Set the tag for the image. model.tag.create_or_update_tag(namespace, name, tag_name, image_ids[-1])