Merge pull request #583 from coreos-inc/python-registry-v2-betterpulltest

Make sure registry pull tests verify the images expected
This commit is contained in:
josephschorr 2015-10-02 14:35:48 -04:00
commit a9278f1653

View file

@ -272,7 +272,10 @@ class V1RegistryPushMixin(V1RegistryMixin):
class V1RegistryPullMixin(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 auth = None
if username: if username:
auth = (username, password) auth = (username, password)
@ -290,7 +293,12 @@ class V1RegistryPullMixin(V1RegistryMixin):
# GET /v1/repositories/{namespace}/{repository}/ # GET /v1/repositories/{namespace}/{repository}/
result = json.loads(self.conduct('GET', prefix + 'tags', auth='sig').text) 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} # /v1/images/{imageID}/{ancestry, json, layer}
image_prefix = '/v1/images/%s/' % image_id image_prefix = '/v1/images/%s/' % image_id
self.conduct('GET', image_prefix + 'ancestry', auth='sig') self.conduct('GET', image_prefix + 'ancestry', auth='sig')
@ -469,7 +477,9 @@ class V2RegistryPushMixin(V2RegistryMixin):
class V2RegistryPullMixin(V2RegistryMixin): class V2RegistryPullMixin(V2RegistryMixin):
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,
manifest_id=None, expected_manifest_code=200): manifest_id=None, expected_manifest_code=200, images=None):
images = images or self._get_default_images()
# Ping! # Ping!
self.v2_ping() self.v2_ping()
@ -491,8 +501,8 @@ class V2RegistryPullMixin(V2RegistryMixin):
# Ensure the manifest returned by us is valid. # Ensure the manifest returned by us is valid.
validate_schema(manifest_data, V2RegistryMixin.MANIFEST_SCHEMA) validate_schema(manifest_data, V2RegistryMixin.MANIFEST_SCHEMA)
# Verify the layers.
blobs = {} blobs = {}
for layer in manifest_data['fsLayers']: for layer in manifest_data['fsLayers']:
blob_id = layer['blobSum'] blob_id = layer['blobSum']
result = self.conduct('GET', '/v2/%s/%s/blobs/%s' % (namespace, repository, blob_id), 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 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 return blobs
@ -703,7 +723,7 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix
self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images) self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images)
# Pull the image back and verify the contents. # 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(len(blobs.items()), 1)
self.assertEquals(blobs.items()[0][1], contents) 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) self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images)
# Pull the image back and verify the contents. # 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(len(blobs.items()), 1)
self.assertEquals(blobs.items()[0][1], contents) 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) self.do_push('devtable', 'newrepo', 'devtable', 'password', images=images)
# Pull the image back and verify the contents. # 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(len(blobs.items()), 1)
self.assertEquals(blobs.items()[0][1], contents) self.assertEquals(blobs.items()[0][1], contents)