Fix parent rewrite bug in schema1 manifest code and add a bunch more tests

Before this change, if you ended up writing a middle layer whose parent is not in the database, the manifest would fail to rewrite. We now just lookup the parent image in the manifest given to us, ignoring whether it is in the database or not (as it doesn't actually matter if not present; it'll be created if necessary).
This commit is contained in:
Joseph Schorr 2016-10-04 14:03:39 +03:00 committed by Evan Cordell
parent f3091c6424
commit f4e1748bb7
2 changed files with 191 additions and 30 deletions

View file

@ -259,13 +259,9 @@ class DockerSchema1Manifest(object):
updated_id_map[extracted_v1_metadata.image_id] = working_image_id
# Lookup the parent image for the layer, if any.
parent_image_id = None
if extracted_v1_metadata.parent_image_id is not None:
parent_image = images_map.get(extracted_v1_metadata.parent_image_id, None)
if parent_image is None:
raise MalformedSchema1Manifest('parent not found with image ID: %s' %
extracted_v1_metadata.parent_image_id)
parent_image_id = updated_id_map.get(parent_image.image_id, parent_image.image_id)
parent_image_id = extracted_v1_metadata.parent_image_id
if parent_image_id is not None:
parent_image_id = updated_id_map.get(parent_image_id, parent_image_id)
# Synthesize and store the v1 metadata in the db.
v1_metadata_json = layer.raw_v1_metadata
@ -285,7 +281,6 @@ class DockerSchema1Manifest(object):
content_checksum=digest_str,
)
images_map[updated_image.image_id] = updated_image
yield updated_image