Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure modules are idempotent #320

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/module_utils/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
):
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/targets/credential/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/targets/event_stream/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down