diff options
author | Mark Goddard <mark@stackhpc.com> | 2019-02-28 11:58:05 +0000 |
---|---|---|
committer | Mark Goddard <mark@stackhpc.com> | 2019-02-28 12:11:13 +0000 |
commit | e989a21f06dab5421b02b49d69b9f24779154d9c (patch) | |
tree | b6bf57b9d468dc37c17f31c7be885539c59cf6ab /ironic/db/sqlalchemy/api.py | |
parent | 1e4a1cb7cbe7ba8cdf510adff9861a0e0ef21f89 (diff) | |
download | ironic-e989a21f06dab5421b02b49d69b9f24779154d9c.tar.gz |
Deploy templates: fix updating steps in Python 3
If a step in a deploy template is updated, changing only the step's
'args' field, then we see the following error on Python 3:
TypeError: unorderable types: dict() < dict()
In Python 3, dicts are no longer orderable, so cannot be used as part of
the key to a sort function. This change uses a JSON dump of the step
with sorted keys for comparison, as suggested in [1].
[1] https://stackoverflow.com/a/22003440
Change-Id: I70b806d5850f0678f3dd6633228947f6cd39d691
Story: 1722275
Task: 29750
Diffstat (limited to 'ironic/db/sqlalchemy/api.py')
-rw-r--r-- | ironic/db/sqlalchemy/api.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py index f14d83059..af403cc56 100644 --- a/ironic/db/sqlalchemy/api.py +++ b/ironic/db/sqlalchemy/api.py @@ -16,6 +16,7 @@ import collections import datetime +import json import threading from oslo_db import api as oslo_db_api @@ -1848,7 +1849,11 @@ class Connection(api.Connection): def _step_key(step): """Compare two deploy template steps.""" - return step.interface, step.step, step.args, step.priority + # NOTE(mgoddard): In python 3, dicts are not orderable so cannot be + # used as a sort key. Serialise the step arguments to a JSON string + # for comparison. Taken from https://stackoverflow.com/a/22003440. + sortable_args = json.dumps(step.args, sort_keys=True) + return step.interface, step.step, sortable_args, step.priority # List all existing steps for the template. current_steps = (model_query(models.DeployTemplateStep) |