Browse Source

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
changes/94/114194/4
Louis Taylor 8 years ago
parent
commit
66c987479a
  1. 27
      glance/db/sqlalchemy/api.py

27
glance/db/sqlalchemy/api.py

@ -1107,20 +1107,21 @@ def _can_show_deleted(context):
def image_tag_set_all(context, image_id, 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
session = get_session()
existing_tags = set(image_tag_get_all(context, image_id, session))
tags = set(tags)
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)):
image_tag_create(context, image_id, tag, session)
tags_to_delete = existing_tags - tags
for tag in tags_to_delete:
image_tag_delete(context, image_id, tag, 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)
for tag in existing_tags:
if tag not in tags:
image_tag_delete(context, image_id, tag, session)
def image_tag_create(context, image_id, value, session=None):

Loading…
Cancel
Save