Add additional assertions and further checks in storage code

This commit is contained in:
Joseph Schorr 2019-02-20 12:05:21 -05:00
parent 6b30702699
commit 693e47e063
3 changed files with 8 additions and 2 deletions

View file

@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
def get_repository_blob_by_digest(repository, blob_digest):
""" Find the content-addressable blob linked to the specified repository.
"""
assert blob_digest
try:
storage = (ImageStorage
.select(ImageStorage.uuid)
@ -32,6 +33,7 @@ def get_repository_blob_by_digest(repository, blob_digest):
def get_repo_blob_by_digest(namespace, repo_name, blob_digest):
""" Find the content-addressable blob linked to the specified repository.
"""
assert blob_digest
try:
storage = (ImageStorage
.select(ImageStorage.uuid)
@ -81,6 +83,8 @@ def temp_link_blob(namespace, repo_name, blob_digest, link_expiration_s):
""" Temporarily links to the blob record from the given namespace. If the blob record is not
found, return None.
"""
assert blob_digest
with db_transaction():
try:
storage = ImageStorage.get(content_checksum=blob_digest)
@ -172,6 +176,7 @@ def get_shared_blob(digest):
globally accessible, such as the special empty gzipped tar layer that Docker
no longer pushes to us.
"""
assert digest
try:
return ImageStorage.get(content_checksum=digest, uploading=False)
except ImageStorage.DoesNotExist:

View file

@ -489,7 +489,8 @@ def find_or_create_derived_storage(source_image, transformation_name, preferred_
transformation=trans, uniqueness_hash=uniqueness_hash)
except IntegrityError:
# Storage was created while this method executed. Just return the existing.
new_storage.delete_instance(recursive=True)
ImageStoragePlacement.delete().where(ImageStoragePlacement.storage == new_storage).execute()
new_storage.delete_instance()
return find_derived_storage_for_image(source_image, transformation_name, varying_metadata)
return derived

View file

@ -189,7 +189,7 @@ def garbage_collect_storage(storage_id_whitelist):
def create_v1_storage(location_name):
storage = ImageStorage.create(cas_path=False)
storage = ImageStorage.create(cas_path=False, uploading=True)
location = get_image_location_for_name(location_name)
ImageStoragePlacement.create(location=location.id, storage=storage)
storage.locations = {location_name}