From 2a00b4cc67df91c5eac10f4762aff543d3740e05 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Tue, 10 Mar 2020 15:55:14 +0000 Subject: [PATCH] Fix ironic inspector rule creation idempotency Ironic inspector rules are registered both with the seed and (if using) overcloud ironic inspector services. These tasks often show up as changed even when no configuration changes have been made that would affect the rules. This is caused by inspector returning default values for fields that may be omitted in the requested rule. This change fixes the issue by including those defaults in the comparison. Change-Id: Ia24e328d4531201d76a65b6385e4463bb1f3c5c6 Story: 2007399 Task: 38997 --- .../library/os_ironic_inspector_rule.py | 13 ++++++++++++- ...inspector-rule-idempotency-f6e5a61f7dca580f.yaml | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-inspector-rule-idempotency-f6e5a61f7dca580f.yaml diff --git a/ansible/roles/ironic-inspector-rules/library/os_ironic_inspector_rule.py b/ansible/roles/ironic-inspector-rules/library/os_ironic_inspector_rule.py index cb58ad600..e71e19ceb 100644 --- a/ansible/roles/ironic-inspector-rules/library/os_ironic_inspector_rule.py +++ b/ansible/roles/ironic-inspector-rules/library/os_ironic_inspector_rule.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +import copy + from ansible.module_utils.basic import * from ansible.module_utils.openstack import * @@ -102,7 +104,16 @@ def _ensure_rule_present(module, client): # Check whether the rule differs from the request. keys = ('conditions', 'actions', 'description') for key in keys: - if rule[key] != module.params[key]: + expected = module.params[key] + if key == 'conditions': + # Rules returned from the API include default values in the + # conditions that may not be in the requested rule. Apply + # defaults to allow the comparison to succeed. + expected = copy.deepcopy(expected) + for condition in expected: + condition.setdefault('invert', False) + condition.setdefault('multiple', 'any') + if rule[key] != expected: break else: # Nothing to do - rule exists and is as requested. diff --git a/releasenotes/notes/fix-inspector-rule-idempotency-f6e5a61f7dca580f.yaml b/releasenotes/notes/fix-inspector-rule-idempotency-f6e5a61f7dca580f.yaml new file mode 100644 index 000000000..0c9ff9a9a --- /dev/null +++ b/releasenotes/notes/fix-inspector-rule-idempotency-f6e5a61f7dca580f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue with idempotency of Ironic Inspector rule creation. See + `story 2007399 `__ for + details.