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:
Louis Taylor 2014-08-14 10:21:36 +00:00
parent 8c31eb5cbe
commit 66c987479a
1 changed files with 12 additions and 11 deletions

View File

@ -1107,19 +1107,20 @@ def _can_show_deleted(context):
def image_tag_set_all(context, image_id, tags): def image_tag_set_all(context, image_id, tags):
session = get_session() #NOTE(kragniz): tag ordering should match exactly what was provided, so a
existing_tags = set(image_tag_get_all(context, image_id, session)) # subsequent call to image_tag_get_all returns them in the correct order
tags = set(tags)
tags_to_create = tags - existing_tags session = get_session()
#NOTE(bcwaldon): we call 'reversed' here to ensure the ImageTag.id fields existing_tags = image_tag_get_all(context, image_id, session)
# will be populated in the order required to reflect the correct ordering
# on a subsequent call to image_tag_get_all tags_created = []
for tag in reversed(list(tags_to_create)): 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) image_tag_create(context, image_id, tag, session)
tags_to_delete = existing_tags - tags for tag in existing_tags:
for tag in tags_to_delete: if tag not in tags:
image_tag_delete(context, image_id, tag, session) image_tag_delete(context, image_id, tag, session)