From b0ed9306273c8ed3bb4a8b93a02b292b7f461070 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 2 Oct 2015 14:33:38 -0400 Subject: [PATCH] Make sure registry pull tests verify the images expected --- test/registry_tests.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/test/registry_tests.py b/test/registry_tests.py index 8b1c2c622..a068f385a 100644 --- a/test/registry_tests.py +++ b/test/registry_tests.py @@ -272,7 +272,10 @@ class V1RegistryPushMixin(V1RegistryMixin): class V1RegistryPullMixin(V1RegistryMixin): - def do_pull(self, namespace, repository, username=None, password='password', expected_code=200): + def do_pull(self, namespace, repository, username=None, password='password', expected_code=200, + images=None): + images = images or self._get_default_images() + auth = None if username: auth = (username, password) @@ -290,7 +293,12 @@ class V1RegistryPullMixin(V1RegistryMixin): # GET /v1/repositories/{namespace}/{repository}/ result = json.loads(self.conduct('GET', prefix + 'tags', auth='sig').text) - for image_id in result.values(): + self.assertEquals(len(images), len(result.values())) + + for image_data in images: + image_id = image_data['id'] + self.assertIn(image_id, result.values()) + # /v1/images/{imageID}/{ancestry, json, layer} image_prefix = '/v1/images/%s/' % image_id self.conduct('GET', image_prefix + 'ancestry', auth='sig') @@ -469,7 +477,9 @@ class V2RegistryPushMixin(V2RegistryMixin): class V2RegistryPullMixin(V2RegistryMixin): def do_pull(self, namespace, repository, username=None, password='password', expected_code=200, - manifest_id=None, expected_manifest_code=200): + manifest_id=None, expected_manifest_code=200, images=None): + images = images or self._get_default_images() + # Ping! self.v2_ping() @@ -491,8 +501,8 @@ class V2RegistryPullMixin(V2RegistryMixin): # Ensure the manifest returned by us is valid. validate_schema(manifest_data, V2RegistryMixin.MANIFEST_SCHEMA) + # Verify the layers. blobs = {} - for layer in manifest_data['fsLayers']: blob_id = layer['blobSum'] result = self.conduct('GET', '/v2/%s/%s/blobs/%s' % (namespace, repository, blob_id), @@ -500,6 +510,16 @@ class V2RegistryPullMixin(V2RegistryMixin): blobs[blob_id] = result.text + # Verify the V1 metadata is present for each expected image. + found_v1_layers = set() + history = manifest_data['history'] + for entry in history: + v1_history = json.loads(entry['v1Compatibility']) + found_v1_layers.add(v1_history['id']) + + for image in images: + self.assertIn(image['id'], found_v1_layers) + return blobs @@ -703,7 +723,7 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images) # Pull the image back and verify the contents. - blobs = self.do_pull('devtable', 'newrepo', 'devtable', 'password') + blobs = self.do_pull('devtable', 'newrepo', 'devtable', 'password', images=images) self.assertEquals(len(blobs.items()), 1) self.assertEquals(blobs.items()[0][1], contents) @@ -724,7 +744,7 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images) # Pull the image back and verify the contents. - blobs = self.do_pull('devtable', 'newrepo', 'devtable', 'password') + blobs = self.do_pull('devtable', 'newrepo', 'devtable', 'password', images=images) self.assertEquals(len(blobs.items()), 1) self.assertEquals(blobs.items()[0][1], contents) @@ -746,7 +766,7 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images) # Pull the image back and verify the contents. - blobs = self.do_pull('devtable', 'newrepo', 'devtable', 'password') + blobs = self.do_pull('devtable', 'newrepo', 'devtable', 'password', images=images) self.assertEquals(len(blobs.items()), 1) self.assertEquals(blobs.items()[0][1], contents)