Merge pull request #3397 from quay/joseph.schorr/QUAY-1418/fix-v1-push

Fix V1 push for layers already uploaded
This commit is contained in:
Joseph Schorr 2019-03-05 13:40:19 -05:00 committed by GitHub
commit d3dd2f7b7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 10 deletions

View file

@ -55,15 +55,22 @@ def store_blob_record_and_temp_link(namespace, repo_name, blob_digest, location_
""" Store a record of the blob and temporarily link it to the specified repository. """ Store a record of the blob and temporarily link it to the specified repository.
""" """
assert blob_digest assert blob_digest
assert byte_count is not None
with db_transaction(): with db_transaction():
try: try:
storage = ImageStorage.get(content_checksum=blob_digest) storage = ImageStorage.get(content_checksum=blob_digest)
save_changes = False
if storage.image_size is None:
storage.image_size = byte_count storage.image_size = byte_count
save_changes = True
if uncompressed_byte_count is not None: if storage.uncompressed_size is None and uncompressed_byte_count is not None:
storage.uncompressed_size = uncompressed_byte_count storage.uncompressed_size = uncompressed_byte_count
save_changes = True
if save_changes:
storage.save() storage.save()
ImageStoragePlacement.get(storage=storage, location=location_obj) ImageStoragePlacement.get(storage=storage, location=location_obj)

View file

@ -21,8 +21,10 @@ def test_store_blob(initialized_db):
blob_storage2 = model.blob.store_blob_record_and_temp_link(ADMIN_ACCESS_USER, REPO, digest, blob_storage2 = model.blob.store_blob_record_and_temp_link(ADMIN_ACCESS_USER, REPO, digest,
location, 2048, 0, 6000) location, 2048, 0, 6000)
assert blob_storage2.id == blob_storage.id assert blob_storage2.id == blob_storage.id
assert blob_storage2.image_size == 2048
assert blob_storage2.uncompressed_size == 6000 # The sizes should be unchanged.
assert blob_storage2.image_size == 1024
assert blob_storage2.uncompressed_size == 5000
# Add a new digest, ensure it has a new record. # Add a new digest, ensure it has a new record.
otherdigest = 'anotherdigest' otherdigest = 'anotherdigest'

View file

@ -161,11 +161,6 @@ def put_image_layer(namespace, repository, image_id):
if repository_ref is None: if repository_ref is None:
abort(403) abort(403)
logger.debug('Retrieving image')
legacy_image = registry_model.get_legacy_image(repository_ref, image_id)
if legacy_image is not None and not legacy_image.uploading:
exact_abort(409, 'Image already exists')
logger.debug('Checking for image in manifest builder') logger.debug('Checking for image in manifest builder')
builder = lookup_manifest_builder(repository_ref, session.get('manifest_builder'), store) builder = lookup_manifest_builder(repository_ref, session.get('manifest_builder'), store)
if builder is None: if builder is None:

View file

@ -53,6 +53,27 @@ def test_empty_layer(pusher, puller, images_with_empty_layer, liveserver_session
credentials=credentials) credentials=credentials)
def test_empty_layer_push_again(pusher, puller, images_with_empty_layer, liveserver_session,
app_reloader):
""" Test: Push and pull of an image with an empty layer to a new repository and then push it
again. """
credentials = ('devtable', 'password')
# Push a new repository.
pusher.push(liveserver_session, 'devtable', 'newrepo', 'latest', images_with_empty_layer,
credentials=credentials)
# Pull the repository to verify.
puller.pull(liveserver_session, 'devtable', 'newrepo', 'latest', images_with_empty_layer,
credentials=credentials)
# Push to the repository again, to ensure everything is skipped properly.
options = ProtocolOptions()
options.skip_head_checks = True
pusher.push(liveserver_session, 'devtable', 'newrepo', 'latest', images_with_empty_layer,
credentials=credentials, options=options)
def test_multi_layer_images_push_pull(pusher, puller, multi_layer_images, liveserver_session, def test_multi_layer_images_push_pull(pusher, puller, multi_layer_images, liveserver_session,
app_reloader): app_reloader):
""" Test: Basic push and pull of a multi-layered image to a new repository. """ """ Test: Basic push and pull of a multi-layered image to a new repository. """