From ca69f0091581e98612450019839d63cc8676022a Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 10 Oct 2024 16:30:49 +0200 Subject: [PATCH] Ensure modules are idempotent (#320) Signed-off-by: Alina Buzachis Co-authored-by: Alex --- plugins/module_utils/controller.py | 4 +++- tests/integration/targets/credential/tasks/main.yml | 3 --- tests/integration/targets/event_stream/tasks/main.yml | 6 ------ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/plugins/module_utils/controller.py b/plugins/module_utils/controller.py index 553c7969..50655df5 100644 --- a/plugins/module_utils/controller.py +++ b/plugins/module_utils/controller.py @@ -242,6 +242,7 @@ def fields_could_be_same(old_field: Any, new_field: Any) -> bool: return True # all sub-fields are either equal or could be equal if old_field == Controller.ENCRYPTED_STRING: return True + return bool(new_field == old_field) def objects_could_be_different( @@ -256,13 +257,14 @@ def objects_could_be_different( for field in field_set: new_field = new.get(field, None) old_field = old.get(field, None) + if old_field != new_field: if self.update_secrets or ( not self.fields_could_be_same(old_field, new_field) ): return True # Something doesn't match, or something # might not match - elif self.has_encrypted_values(new_field) or field not in new: + elif self.has_encrypted_values(new_field): if self.update_secrets or ( not self.fields_could_be_same(old_field, new_field) ): diff --git a/tests/integration/targets/credential/tasks/main.yml b/tests/integration/targets/credential/tasks/main.yml index d537a994..4a610ec4 100644 --- a/tests/integration/targets/credential/tasks/main.yml +++ b/tests/integration/targets/credential/tasks/main.yml @@ -82,12 +82,10 @@ organization_name: Default register: _result - # [WARNING]: The field inputs of unknown 3 has encrypted data and may inaccurately report task is changed. - name: Check credential is not created again assert: that: - not _result.changed - ignore_errors: true - name: Get info about a credential ansible.eda.credential_info: @@ -121,7 +119,6 @@ organization_name: Default register: _result - # [WARNING]: The field inputs of unknown 3 has encrypted data and may inaccurately report task is changed. - name: Check credential is not updated again assert: that: diff --git a/tests/integration/targets/event_stream/tasks/main.yml b/tests/integration/targets/event_stream/tasks/main.yml index 1d0f80b2..61b60173 100644 --- a/tests/integration/targets/event_stream/tasks/main.yml +++ b/tests/integration/targets/event_stream/tasks/main.yml @@ -79,13 +79,10 @@ event_stream_type: "basic" register: _result - # [WARNING]: The field eda_credential_id of unknown 2 has encrypted data and may - # inaccurately report task is changed. - name: Check event stream is not created again assert: that: - not _result.changed - ignore_errors: true - name: Get info about an event stream ansible.eda.event_stream_info: @@ -115,13 +112,10 @@ event_stream_type: "basic" register: _result - # [WARNING]: The field eda_credential_id of unknown 5 has encrypted data and may - # inaccurately report task is changed. - name: Check event stream is not updated again assert: that: - not _result.changed - ignore_errors: true - name: Get info about event stream ansible.eda.event_stream_info: