From fef1a495e1e3106f9a40e3dc02c3c8759d86cfc4 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 22:31:44 +0100 Subject: [PATCH] [PR #7795/31de16ce backport][stable-7] ipa_otptoken: fix wrong return value string to bool (#7851) ipa_otptoken: fix wrong return value string to bool (#7795) ipa_data is return ipatokendisable in boolean format and the module expects it as a string this behavior causes a lack of idempotency and the get_diff module will fail in the second run. (cherry picked from commit 31de16cee33bf6f2f500fabfd150aee1dc0c1507) Co-authored-by: Parsa Yousefi --- .../7797-ipa-fix-otp-idempotency.yml | 2 ++ plugins/modules/ipa_otptoken.py | 2 +- .../unit/plugins/modules/test_ipa_otptoken.py | 22 +++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 changelogs/fragments/7797-ipa-fix-otp-idempotency.yml diff --git a/changelogs/fragments/7797-ipa-fix-otp-idempotency.yml b/changelogs/fragments/7797-ipa-fix-otp-idempotency.yml new file mode 100644 index 0000000000..43fd4f5251 --- /dev/null +++ b/changelogs/fragments/7797-ipa-fix-otp-idempotency.yml @@ -0,0 +1,2 @@ +bugfixes: + - ipa_otptoken - the module expect ``ipatokendisabled`` as string but the ``ipatokendisabled`` value is returned as a boolean (https://github.com/ansible-collections/community.general/pull/7795). diff --git a/plugins/modules/ipa_otptoken.py b/plugins/modules/ipa_otptoken.py index 22c21b61a6..567674f935 100644 --- a/plugins/modules/ipa_otptoken.py +++ b/plugins/modules/ipa_otptoken.py @@ -237,7 +237,7 @@ def get_otptoken_dict(ansible_to_ipa, uniqueid=None, newuniqueid=None, otptype=N if owner is not None: otptoken[ansible_to_ipa['owner']] = owner if enabled is not None: - otptoken[ansible_to_ipa['enabled']] = 'FALSE' if enabled else 'TRUE' + otptoken[ansible_to_ipa['enabled']] = False if enabled else True if notbefore is not None: otptoken[ansible_to_ipa['notbefore']] = notbefore + 'Z' if notafter is not None: diff --git a/tests/unit/plugins/modules/test_ipa_otptoken.py b/tests/unit/plugins/modules/test_ipa_otptoken.py index c06e19c3b5..23911e5a5b 100644 --- a/tests/unit/plugins/modules/test_ipa_otptoken.py +++ b/tests/unit/plugins/modules/test_ipa_otptoken.py @@ -104,7 +104,7 @@ class TestIPAOTPToken(ModuleTestCase): { 'method': 'otptoken_add', 'name': 'NewToken1', - 'item': {'ipatokendisabled': 'FALSE', + 'item': {'ipatokendisabled': False, 'all': True} } ) @@ -130,7 +130,7 @@ class TestIPAOTPToken(ModuleTestCase): { 'method': 'otptoken_add', 'name': 'NewToken1', - 'item': {'ipatokendisabled': 'FALSE', + 'item': {'ipatokendisabled': False, 'all': True} } ) @@ -176,7 +176,7 @@ class TestIPAOTPToken(ModuleTestCase): 'ipatokenotpkey': 'KRSXG5CTMVRXEZLUGE======', 'description': 'Test description', 'ipatokenowner': 'pinky', - 'ipatokendisabled': 'FALSE', + 'ipatokendisabled': False, 'ipatokennotbefore': '20200101010101Z', 'ipatokennotafter': '20900101010101Z', 'ipatokenvendor': 'Acme', @@ -220,7 +220,7 @@ class TestIPAOTPToken(ModuleTestCase): 'ipatokenotpkey': [{'__base64__': 'VGVzdFNlY3JldDE='}], 'description': ['Test description'], 'ipatokenowner': ['pinky'], - 'ipatokendisabled': ['FALSE'], + 'ipatokendisabled': [False], 'ipatokennotbefore': ['20200101010101Z'], 'ipatokennotafter': ['20900101010101Z'], 'ipatokenvendor': ['Acme'], @@ -271,7 +271,7 @@ class TestIPAOTPToken(ModuleTestCase): 'ipatokenotpkey': [{'__base64__': 'VGVzdFNlY3JldDE='}], 'description': ['Test description'], 'ipatokenowner': ['pinky'], - 'ipatokendisabled': ['FALSE'], + 'ipatokendisabled': [False], 'ipatokennotbefore': ['20200101010101Z'], 'ipatokennotafter': ['20900101010101Z'], 'ipatokenvendor': ['Acme'], @@ -296,7 +296,7 @@ class TestIPAOTPToken(ModuleTestCase): 'name': 'NewToken1', 'item': {'description': 'Test description', 'ipatokenowner': 'brain', - 'ipatokendisabled': 'FALSE', + 'ipatokendisabled': False, 'ipatokennotbefore': '20200101010101Z', 'ipatokennotafter': '20900101010101Z', 'ipatokenvendor': 'Acme', @@ -335,7 +335,7 @@ class TestIPAOTPToken(ModuleTestCase): 'ipatokenotpkey': [{'__base64__': 'VGVzdFNlY3JldDE='}], 'description': ['Test description'], 'ipatokenowner': ['pinky'], - 'ipatokendisabled': ['FALSE'], + 'ipatokendisabled': [False], 'ipatokennotbefore': ['20200101010101Z'], 'ipatokennotafter': ['20900101010101Z'], 'ipatokenvendor': ['Acme'], @@ -360,7 +360,7 @@ class TestIPAOTPToken(ModuleTestCase): 'name': 'NewToken1', 'item': {'description': 'New Test description', 'ipatokenowner': 'pinky', - 'ipatokendisabled': 'TRUE', + 'ipatokendisabled': True, 'ipatokennotbefore': '20200101010102Z', 'ipatokennotafter': '20900101010102Z', 'ipatokenvendor': 'NewAcme', @@ -384,7 +384,7 @@ class TestIPAOTPToken(ModuleTestCase): 'ipatokenotpkey': [{'__base64__': 'KRSXG5CTMVRXEZLUGE======'}], 'description': ['Test description'], 'ipatokenowner': ['pinky'], - 'ipatokendisabled': ['FALSE'], + 'ipatokendisabled': [False], 'ipatokennotbefore': ['20200101010101Z'], 'ipatokennotafter': ['20900101010101Z'], 'ipatokenvendor': ['Acme'], @@ -425,7 +425,7 @@ class TestIPAOTPToken(ModuleTestCase): 'ipatokenotpkey': [{'__base64__': 'KRSXG5CTMVRXEZLUGE======'}], 'description': ['Test description'], 'ipatokenowner': ['pinky'], - 'ipatokendisabled': ['FALSE'], + 'ipatokendisabled': [False], 'ipatokennotbefore': ['20200101010101Z'], 'ipatokennotafter': ['20900101010101Z'], 'ipatokenvendor': ['Acme'], @@ -448,7 +448,7 @@ class TestIPAOTPToken(ModuleTestCase): { 'method': 'otptoken_mod', 'name': 'NewToken1', - 'item': {'ipatokendisabled': 'TRUE', + 'item': {'ipatokendisabled': True, 'all': True} } )