Add blob support to get_legacy_image
This commit is contained in:
parent
6d5489b254
commit
1bbe41bb36
4 changed files with 27 additions and 7 deletions
|
@ -122,13 +122,14 @@ class LegacyImage(datatype('LegacyImage', ['docker_image_id', 'created', 'commen
|
||||||
'image_size', 'aggregate_size', 'uploading'])):
|
'image_size', 'aggregate_size', 'uploading'])):
|
||||||
""" LegacyImage represents a Docker V1-style image found in a repository. """
|
""" LegacyImage represents a Docker V1-style image found in a repository. """
|
||||||
@classmethod
|
@classmethod
|
||||||
def for_image(cls, image, images_map=None, tags_map=None):
|
def for_image(cls, image, images_map=None, tags_map=None, blob=None):
|
||||||
if image is None:
|
if image is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return LegacyImage(db_id=image.id,
|
return LegacyImage(db_id=image.id,
|
||||||
inputs=dict(images_map=images_map, tags_map=tags_map,
|
inputs=dict(images_map=images_map, tags_map=tags_map,
|
||||||
ancestor_id_list=image.ancestor_id_list()),
|
ancestor_id_list=image.ancestor_id_list(),
|
||||||
|
blob=blob),
|
||||||
docker_image_id=image.docker_image_id,
|
docker_image_id=image.docker_image_id,
|
||||||
created=image.created,
|
created=image.created,
|
||||||
comment=image.comment,
|
comment=image.comment,
|
||||||
|
@ -148,6 +149,14 @@ class LegacyImage(datatype('LegacyImage', ['docker_image_id', 'created', 'commen
|
||||||
for ancestor_id in reversed(ancestor_id_list)
|
for ancestor_id in reversed(ancestor_id_list)
|
||||||
if images_map.get(ancestor_id)]
|
if images_map.get(ancestor_id)]
|
||||||
|
|
||||||
|
@property
|
||||||
|
@requiresinput('blob')
|
||||||
|
def blob(self, blob):
|
||||||
|
""" Returns the blob for this image. Raises an exception if the blob has
|
||||||
|
not been loaded before this property is invoked.
|
||||||
|
"""
|
||||||
|
return blob
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@requiresinput('tags_map')
|
@requiresinput('tags_map')
|
||||||
def tags(self, tags_map):
|
def tags(self, tags_map):
|
||||||
|
|
|
@ -42,7 +42,8 @@ class RegistryDataInterface(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_legacy_image(self, repository_ref, docker_image_id, include_parents=False):
|
def get_legacy_image(self, repository_ref, docker_image_id, include_parents=False,
|
||||||
|
include_blob=False):
|
||||||
"""
|
"""
|
||||||
Returns the matching LegacyImages under the matching repository, if any. If none,
|
Returns the matching LegacyImages under the matching repository, if any. If none,
|
||||||
returns None.
|
returns None.
|
||||||
|
|
|
@ -99,7 +99,8 @@ class PreOCIModel(RegistryDataInterface):
|
||||||
return [LegacyImage.for_image(image, images_map=all_images_map, tags_map=tags_by_image_id)
|
return [LegacyImage.for_image(image, images_map=all_images_map, tags_map=tags_by_image_id)
|
||||||
for image in all_images]
|
for image in all_images]
|
||||||
|
|
||||||
def get_legacy_image(self, repository_ref, docker_image_id, include_parents=False):
|
def get_legacy_image(self, repository_ref, docker_image_id, include_parents=False,
|
||||||
|
include_blob=False):
|
||||||
"""
|
"""
|
||||||
Returns the matching LegacyImages under the matching repository, if any. If none,
|
Returns the matching LegacyImages under the matching repository, if any. If none,
|
||||||
returns None.
|
returns None.
|
||||||
|
@ -117,7 +118,14 @@ class PreOCIModel(RegistryDataInterface):
|
||||||
parent_images = model.image.get_parent_images(repo.namespace_user.username, repo.name, image)
|
parent_images = model.image.get_parent_images(repo.namespace_user.username, repo.name, image)
|
||||||
parent_images_map = {image.id: image for image in parent_images}
|
parent_images_map = {image.id: image for image in parent_images}
|
||||||
|
|
||||||
return LegacyImage.for_image(image, images_map=parent_images_map)
|
blob = None
|
||||||
|
if include_blob:
|
||||||
|
placements = list(model.storage.get_storage_locations(image.storage.uuid))
|
||||||
|
blob = Blob.for_image_storage(image.storage,
|
||||||
|
storage_path=model.storage.get_layer_path(image.storage),
|
||||||
|
placements=placements)
|
||||||
|
|
||||||
|
return LegacyImage.for_image(image, images_map=parent_images_map, blob=blob)
|
||||||
|
|
||||||
def create_manifest_label(self, manifest, key, value, source_type_name, media_type_name=None):
|
def create_manifest_label(self, manifest, key, value, source_type_name, media_type_name=None):
|
||||||
""" Creates a label on the manifest with the given key and value. """
|
""" Creates a label on the manifest with the given key and value. """
|
||||||
|
|
|
@ -105,11 +105,13 @@ def test_legacy_images(repo_namespace, repo_name, pre_oci_model):
|
||||||
found_image = pre_oci_model.get_legacy_image(repository_ref, image.docker_image_id,
|
found_image = pre_oci_model.get_legacy_image(repository_ref, image.docker_image_id,
|
||||||
include_parents=True)
|
include_parents=True)
|
||||||
|
|
||||||
with assert_query_count(4 if found_image.parents else 3):
|
with assert_query_count(5 if found_image.parents else 4):
|
||||||
found_image = pre_oci_model.get_legacy_image(repository_ref, image.docker_image_id,
|
found_image = pre_oci_model.get_legacy_image(repository_ref, image.docker_image_id,
|
||||||
include_parents=True)
|
include_parents=True, include_blob=True)
|
||||||
assert found_image.docker_image_id == image.docker_image_id
|
assert found_image.docker_image_id == image.docker_image_id
|
||||||
assert found_image.parents == image.parents
|
assert found_image.parents == image.parents
|
||||||
|
assert found_image.blob
|
||||||
|
assert found_image.blob.placements
|
||||||
|
|
||||||
# Check that the tags list can be retrieved.
|
# Check that the tags list can be retrieved.
|
||||||
assert image.tags is not None
|
assert image.tags is not None
|
||||||
|
|
Reference in a new issue