From b998eca8e5f2f83f69b0bb7252f0a42b87d593f4 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 24 Aug 2015 11:58:43 -0400 Subject: [PATCH 1/2] Fix the tests for registry v2 changes. --- data/model/image.py | 4 ++-- endpoints/v1/registry.py | 6 +++++- test/test_gc.py | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) 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]) From 3bfec1d7a93d2d63b4f9f790b4704bd814d2de90 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 24 Aug 2015 11:59:46 -0400 Subject: [PATCH 2/2] Style fixes. --- test/specs.py | 9 +++------ test/test_endpoint_security.py | 10 +++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/test/specs.py b/test/specs.py index 3e5b4e585..a723d7ce9 100644 --- a/test/specs.py +++ b/test/specs.py @@ -143,14 +143,11 @@ def build_index_specs(): IndexTestSpec(url_for('v1.get_image_json', image_id=FAKE_IMAGE_ID), ORG_REPO, 403, 403, 404, 404), - IndexTestSpec(url_for('v1.get_image_ancestry', - image_id=FAKE_IMAGE_ID), + IndexTestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID), PUBLIC_REPO, 404, 404, 404, 404), - IndexTestSpec(url_for('v1.get_image_ancestry', - image_id=FAKE_IMAGE_ID), + IndexTestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID), PRIVATE_REPO, 403, 403, 404, 404), - IndexTestSpec(url_for('v1.get_image_ancestry', - image_id=FAKE_IMAGE_ID), + IndexTestSpec(url_for('v1.get_image_ancestry', image_id=FAKE_IMAGE_ID), ORG_REPO, 403, 403, 404, 404), IndexTestSpec(url_for('v1.put_image_json', image_id=FAKE_IMAGE_ID), diff --git a/test/test_endpoint_security.py b/test/test_endpoint_security.py index 27b393cd7..ff0479116 100644 --- a/test/test_endpoint_security.py +++ b/test/test_endpoint_security.py @@ -16,10 +16,10 @@ ADMIN_ACCESS_USER = 'devtable' class EndpointTestCase(unittest.TestCase): - def setUp(self): + def setUp(self): setup_database_for_testing(self) - def tearDown(self): + def tearDown(self): finished_database_for_testing(self) @@ -68,13 +68,13 @@ class _SpecTestBuilder(type): expected_status = getattr(test_spec, attrs['result_attr']) test = _SpecTestBuilder._test_generator(url, expected_status, - open_kwargs, - session_vars) + open_kwargs, + session_vars) test_name_url = url.replace('/', '_').replace('-', '_') sess_repo = str(test_spec.sess_repo).replace('/', '_') test_name = 'test_%s%s_%s' % (open_kwargs['method'].lower(), - test_name_url, sess_repo) + test_name_url, sess_repo) attrs[test_name] = test return type(name, bases, attrs)