Re-check image alias prior to sync from glance
If two processes attempt to upload the same image at the same time, the second will fail as the image alias will already have been created by the first process. Re-check by image alias as part of the lock context for the image prior to syncing the image from glance to ensure that a duplicate sync is not executed. Change-Id: Ie5ef1fcf9170e18cf41767683036162fd509ee94 Closes-bug: 1697455
This commit is contained in:
parent
41ac333680
commit
698f3da561
@ -215,6 +215,17 @@ def _sync_glance_image_to_lxd(client, context, image_ref):
|
|||||||
lock_path, external=True,
|
lock_path, external=True,
|
||||||
lock_file_prefix='lxd-image-{}'.format(image_ref)):
|
lock_file_prefix='lxd-image-{}'.format(image_ref)):
|
||||||
|
|
||||||
|
# NOTE(jamespage): Re-query by image_ref to ensure
|
||||||
|
# that another process did not
|
||||||
|
# sneak infront of this one and create
|
||||||
|
# the same image already.
|
||||||
|
try:
|
||||||
|
client.images.get_by_alias(image_ref)
|
||||||
|
return
|
||||||
|
except lxd_exceptions.LXDAPIException as e:
|
||||||
|
if e.response.status_code != 404:
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image_file = tempfile.mkstemp()[1]
|
image_file = tempfile.mkstemp()[1]
|
||||||
manifest_file = tempfile.mkstemp()[1]
|
manifest_file = tempfile.mkstemp()[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user