From b54aee38dd0b92898f8dd2bfae0fbf89f36ab5d9 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 2 May 2022 12:18:27 +0200 Subject: [PATCH] report smaller diffs by dropping ``null`` values. This should result in not showing fields that were unset to begin with, and mark fields that were explicitly removed as "deleted" instead of "replaced by ``null``" --- changelogs/fragments/smaller-diffs.yml | 2 ++ plugins/module_utils/foreman_helper.py | 12 ++++++++++-- tests/test_playbooks/activation_key.yml | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/smaller-diffs.yml diff --git a/changelogs/fragments/smaller-diffs.yml b/changelogs/fragments/smaller-diffs.yml new file mode 100644 index 0000000000..accf403534 --- /dev/null +++ b/changelogs/fragments/smaller-diffs.yml @@ -0,0 +1,2 @@ +minor_changes: + - all modules - report smaller diffs by dropping ``null`` values. This should result in not showing fields that were unset to begin with, and mark fields that were explicitly removed as "deleted" instead of "replaced by ``null``" diff --git a/plugins/module_utils/foreman_helper.py b/plugins/module_utils/foreman_helper.py index 0fb5a4c1a8..a2250bc3ac 100644 --- a/plugins/module_utils/foreman_helper.py +++ b/plugins/module_utils/foreman_helper.py @@ -946,10 +946,18 @@ def auto_lookup_nested_entities(self): item[nested_key] = self._lookup_entity(item[nested_key], nested_spec) def record_before(self, resource, entity): - self._before[resource].append(entity) + if isinstance(entity, dict): + to_record = _recursive_dict_without_none(entity) + else: + to_record = entity + self._before[resource].append(to_record) def record_after(self, resource, entity): - self._after[resource].append(entity) + if isinstance(entity, dict): + to_record = _recursive_dict_without_none(entity) + else: + to_record = entity + self._after[resource].append(to_record) def record_after_full(self, resource, entity): self._after_full[resource].append(entity) diff --git a/tests/test_playbooks/activation_key.yml b/tests/test_playbooks/activation_key.yml index 1747c40c5e..133dab3045 100644 --- a/tests/test_playbooks/activation_key.yml +++ b/tests/test_playbooks/activation_key.yml @@ -106,7 +106,7 @@ expected_change: true expected_diff: true expected_diff_before: "Test_Organization_Test_Product_Test_Repository.*false" - expected_diff_after: "Test_Organization_Test_Product_Test_Repository.*null" + expected_diff_after: "content_overrides.*{}" - name: update AK with content overrides set to default again, no change include_tasks: tasks/activation_key.yml vars: