Fix the translation of old ids to new ids, again.
This commit is contained in:
parent
61ca29de04
commit
4b689a7a7c
4 changed files with 21 additions and 11 deletions
|
@ -884,16 +884,20 @@ def create_repository(namespace, name, creating_user, visibility='private'):
|
|||
return repo
|
||||
|
||||
|
||||
def __translate_ancestry(old_ancestry, translations, existing_images):
|
||||
def __translate_ancestry(old_ancestry, translations, repository, username):
|
||||
if old_ancestry == '/':
|
||||
return '/'
|
||||
|
||||
def translate_id(old_id):
|
||||
logger.debug('Translating id: %s', old_id)
|
||||
if old_id not in translations:
|
||||
# Figure out which docker_image_id the old id refers to, then find a
|
||||
# a local one
|
||||
old = Image.select(Image.docker_image_id).where(Image.id == old_id).get()
|
||||
translations[old_id] = existing_images[old.docker_image_id]
|
||||
image_in_repo = find_create_or_link_image(old.docker_image_id,
|
||||
repository, username,
|
||||
translations)
|
||||
translations[old_id] = image_in_repo.id
|
||||
|
||||
return translations[old_id]
|
||||
|
||||
|
@ -902,9 +906,14 @@ def __translate_ancestry(old_ancestry, translations, existing_images):
|
|||
return '/%s/' % '/'.join(new_ids)
|
||||
|
||||
|
||||
def create_or_link_image(docker_image_id, repository, username, translations,
|
||||
existing_images):
|
||||
def find_create_or_link_image(docker_image_id, repository, username,
|
||||
translations):
|
||||
with transaction_factory(db):
|
||||
repo_image = get_repo_image(repository.namespace, repository.name,
|
||||
docker_image_id)
|
||||
if repo_image:
|
||||
return repo_image
|
||||
|
||||
query = (Image
|
||||
.select(Image, ImageStorage)
|
||||
.distinct()
|
||||
|
@ -926,7 +935,8 @@ def create_or_link_image(docker_image_id, repository, username, translations,
|
|||
logger.debug(msg, docker_image_id, to_copy.storage.uuid)
|
||||
|
||||
new_image_ancestry = __translate_ancestry(to_copy.ancestors,
|
||||
translations, existing_images)
|
||||
translations, repository,
|
||||
username)
|
||||
|
||||
storage = to_copy.storage
|
||||
origin_image_id = to_copy.id
|
||||
|
@ -939,6 +949,7 @@ def create_or_link_image(docker_image_id, repository, username, translations,
|
|||
ancestors=new_image_ancestry)
|
||||
|
||||
if origin_image_id:
|
||||
logger.debug('Storing translation %s -> %s', origin_image_id, new_image.id)
|
||||
translations[origin_image_id] = new_image.id
|
||||
|
||||
return new_image
|
||||
|
|
|
@ -193,17 +193,15 @@ def create_repository(namespace, repository):
|
|||
for desc in image_descriptions])
|
||||
new_repo_images = dict(added_images)
|
||||
|
||||
existing_image_translations = {}
|
||||
for existing in model.get_repository_images(namespace, repository):
|
||||
if existing.docker_image_id in new_repo_images:
|
||||
existing_image_translations[existing.docker_image_id] = existing.id
|
||||
added_images.pop(existing.docker_image_id)
|
||||
|
||||
username = get_authenticated_user() and get_authenticated_user().username
|
||||
translations = {}
|
||||
for image_description in added_images.values():
|
||||
model.create_or_link_image(image_description['id'], repo, username,
|
||||
translations, existing_image_translations)
|
||||
model.find_create_or_link_image(image_description['id'], repo, username,
|
||||
translations)
|
||||
|
||||
response = make_response('Created', 201)
|
||||
|
||||
|
|
|
@ -67,7 +67,8 @@ def __create_subtree(repo, structure, creator_username, parent):
|
|||
logger.debug('new docker id: %s' % docker_image_id)
|
||||
checksum = __gen_checksum(docker_image_id)
|
||||
|
||||
new_image = model.create_or_link_image(docker_image_id, repo, None, {}, {})
|
||||
new_image = model.find_create_or_link_image(docker_image_id, repo, None,
|
||||
{})
|
||||
new_image.storage.uuid = IMAGE_UUIDS[image_num % len(IMAGE_UUIDS)]
|
||||
new_image.storage.save()
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class TestImageSharing(unittest.TestCase):
|
|||
|
||||
def createStorage(self, docker_image_id, repository=REPO, username=ADMIN_ACCESS_USER):
|
||||
repository_obj = model.get_repository(repository.split('/')[0], repository.split('/')[1])
|
||||
image = model.create_or_link_image(docker_image_id, repository_obj, username, {}, {})
|
||||
image = model.find_create_or_link_image(docker_image_id, repository_obj, username, {})
|
||||
return image.storage.id
|
||||
|
||||
def assertSameStorage(self, docker_image_id, storage_id, repository=REPO, username=ADMIN_ACCESS_USER):
|
||||
|
|
Reference in a new issue