From 66c987479ae3485d308ec3505a6a6b7404736f1c Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Thu, 14 Aug 2014 10:21:36 +0000 Subject: [PATCH] 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 --- glance/db/sqlalchemy/api.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/glance/db/sqlalchemy/api.py b/glance/db/sqlalchemy/api.py index 8a1d7f7749..662310f384 100644 --- a/glance/db/sqlalchemy/api.py +++ b/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) + existing_tags = image_tag_get_all(context, image_id, session) - 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_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: - image_tag_delete(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):