This commit is contained in:
Stephan Huber 2018-06-14 09:07:09 +02:00
parent 6d12c83b89
commit cc799b55da
2 changed files with 22 additions and 21 deletions

View File

@ -99,6 +99,7 @@ class Image(BaseObject):
def __init__(self, tag, manifest, repository, digest=None, registry_id=DEFAULT_REGISTRY_ID):
self.image_tag = tag
self.image_tags = [tag]
self.image_manifest = manifest
self.image_size_in_bytes = 50 * 1024 * 1024
self.repository = repository
@ -118,6 +119,11 @@ class Image(BaseObject):
def get_image_manifest(self):
return self.image_manifest
def update_tag(self, tag):
self.image_tag = tag
if tag not in self.image_tags:
self.image_tags.append(tag)
@property
def response_object(self):
response_object = self.gen_response_object()
@ -139,7 +145,7 @@ class Image(BaseObject):
@property
def response_describe_object(self):
response_object = self.gen_response_object()
response_object['imageTags'] = [self.image_tag]
response_object['imageTags'] = self.image_tags
response_object['imageDigest'] = self.get_image_digest()
response_object['imageManifest'] = self.image_manifest
response_object['repositoryName'] = self.repository
@ -255,15 +261,16 @@ class ECRBackend(BaseBackend):
else:
raise Exception("{0} is not a repository".format(repository_name))
existing_image = list(filter(lambda x: x.response_object['imageManifest'] == image_manifest, repository.images))
if not existing_image:
existing_images = list(filter(lambda x: x.response_object['imageManifest'] == image_manifest, repository.images))
if not existing_images:
# this image is not in ECR yet
image = Image(image_tag, image_manifest, repository_name)
repository.images.append(image)
return image
else:
image = Image(image_tag, image_manifest, repository_name, existing_image[0].get_image_digest())
repository.images.append(image)
return image
# update existing image
existing_images[0].update_tag(image_tag)
return existing_images[0]
def batch_get_image(self, repository_name, registry_id=None, image_ids=None, accepted_media_types=None):
if repository_name in self.repositories:

View File

@ -45,7 +45,8 @@ def _create_image_manifest():
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 73109,
"digest": _create_image_digest("layer3")
# randomize image digest
"digest": _create_image_digest()
}
]
}
@ -230,21 +231,14 @@ def test_put_image_with_multiple_tags():
type(response2['imageDetails']).should.be(list)
len(response2['imageDetails']).should.be(1)
response['imageDetails'][0]['imageDigest'].should.contain("sha")
response2['imageDetails'][0]['imageDigest'].should.contain("sha")
# response['imageDetails'][0]['registryId'].should.equal("012345678910")
# response['imageDetails'][1]['registryId'].should.equal("012345678910")
# response['imageDetails'][2]['registryId'].should.equal("012345678910")
# response['imageDetails'][3]['registryId'].should.equal("012345678910")
#
# response['imageDetails'][0]['repositoryName'].should.equal("test_repository")
# response['imageDetails'][1]['repositoryName'].should.equal("test_repository")
# response['imageDetails'][2]['repositoryName'].should.equal("test_repository")
# response['imageDetails'][3]['repositoryName'].should.equal("test_repository")
#
# response['imageDetails'][0].should_not.have.key('imageTags')
# len(response['imageDetails'][1]['imageTags']).should.be(1)
response2['imageDetails'][0]['registryId'].should.equal("012345678910")
response2['imageDetails'][0]['repositoryName'].should.equal("test_repository")
len(response2['imageDetails'][0]['imageTags']).should.be(2)
response2['imageDetails'][0]['imageTags'].should.be.equal(['v1', 'latest'])
@mock_ecr
def test_list_images():