Ensure constant order when setting all image tags
The newer version of tox (>=1.7.0) sets a random hash seed, which makes the order of sets unpredictable. This patchset fixes the test_image_tag_set_all test, which otherwise broke with a randomized PYTHONHASHSEED. This new tox behaviour is consistent with python (>=3.3), meaning this change should avoid bugs on that platform at a later date. Change-Id: Ie281b04fc9c4c2a96a9eec9bde7b05229ebf57fc Partial-bug: #1348818
This commit is contained in:
parent
8c31eb5cbe
commit
66c987479a
|
@ -1107,19 +1107,20 @@ def _can_show_deleted(context):
|
|||
|
||||
|
||||
def image_tag_set_all(context, image_id, tags):
|
||||
session = get_session()
|
||||
existing_tags = set(image_tag_get_all(context, image_id, session))
|
||||
tags = set(tags)
|
||||
#NOTE(kragniz): tag ordering should match exactly what was provided, so a
|
||||
# subsequent call to image_tag_get_all returns them in the correct order
|
||||
|
||||
tags_to_create = tags - existing_tags
|
||||
#NOTE(bcwaldon): we call 'reversed' here to ensure the ImageTag.id fields
|
||||
# will be populated in the order required to reflect the correct ordering
|
||||
# on a subsequent call to image_tag_get_all
|
||||
for tag in reversed(list(tags_to_create)):
|
||||
session = get_session()
|
||||
existing_tags = image_tag_get_all(context, image_id, session)
|
||||
|
||||
tags_created = []
|
||||
for tag in tags:
|
||||
if tag not in tags_created and tag not in existing_tags:
|
||||
tags_created.append(tag)
|
||||
image_tag_create(context, image_id, tag, session)
|
||||
|
||||
tags_to_delete = existing_tags - tags
|
||||
for tag in tags_to_delete:
|
||||
for tag in existing_tags:
|
||||
if tag not in tags:
|
||||
image_tag_delete(context, image_id, tag, session)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue