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

Fb keycloak client improvement #9644

Conversation

amPrimeSign
Copy link
Contributor

@amPrimeSign amPrimeSign commented Jan 28, 2025

SUMMARY

Fix and improve existing tests for keycloak_client module

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

keycloak_client

ADDITIONAL INFORMATION

Run ansible-test integration -v keycloak_client --allow-unsupported --docker fedora40 --docker-network host

Before:

[...]
TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
    task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
    fatal: [testhost]: FAILED! => {
        "assertion": "check_client_when_present_and_same is not changed",
        "changed": false,
        "evaluated_to": false,
        "msg": "Assertion failed"
    }
[...]

After:

[...]
TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-bhrae54u-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
ok: [testhost] => {
    "changed": false,
    "msg": "All assertions passed"
}
[...]

TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
fatal: [testhost]: FAILED! => {
    "assertion": "check_client_when_present_and_same is not changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}
@amPrimeSign amPrimeSign force-pushed the fb-keycloak-client-improvement branch 2 times, most recently from 431a6c5 to 0a088f8 Compare January 28, 2025 08:49
@amPrimeSign amPrimeSign force-pushed the fb-keycloak-client-improvement branch from 0a088f8 to 8495695 Compare January 28, 2025 08:50
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug integration tests/integration module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) tests tests and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jan 28, 2025
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @amPrimeSign thanks for your contribution

I have a couple of suggestions on it, and I think the test file actually needs fixing.

tests/integration/targets/keycloak_client/vars/main.yml Outdated Show resolved Hide resolved
plugins/modules/keycloak_client.py Outdated Show resolved Hide resolved
plugins/modules/keycloak_client.py Outdated Show resolved Hide resolved
Co-authored-by: Alexei Znamensky <[email protected]>
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-10 Automatically create a backport for the stable-10 branch backport-9 Automatically create a backport for the stable-9 branch labels Jan 28, 2025
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @amPrimeSign thanks for the adjustments.

The changelog might use a bit of a tweak, and I left another comment with a suggestion that you may disregard at will.

Comment on lines +762 to +765
if 'config' in mapper:
for key, value in mapper['config'].items():
if isinstance(value, bool):
mapper['config'][key] = str(value).lower()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be overthinking this, but you are modifying items of a dict that you are iterating over. I remember this causing problems in some versions of Python back in the day. But assuming that the tests cover this part of the code, it should be alright.

Also, an alternative way that would not incur in the non-existent problem 😆 (feel free to disregard) to implement this could be:

Suggested change
if 'config' in mapper:
for key, value in mapper['config'].items():
if isinstance(value, bool):
mapper['config'][key] = str(value).lower()
if 'config' in mapper:
bool_items = {k: str(v).lower() for k,v in mapper['config'].items() if isinstance(v, bool)}
mapper['config'].update(bool_items)

Copy link
Contributor Author

@amPrimeSign amPrimeSign Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think editing an existing value should be ok, but I'm not a Python expert. For me, both options are fine, please pick your preferred one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying dict values is fine, deleting or adding items would cause issues.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for chipping in @apollo13 !
@amPrimeSign so there you go, we're good the way it is now. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@russoz Thanks :)

Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Feb 1, 2025
@felixfontein felixfontein merged commit 250dc11 into ansible-collections:main Feb 1, 2025
138 checks passed
Copy link

patchback bot commented Feb 1, 2025

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/250dc1139c53ab429196fe64d8f3676e75977c61/pr-9644

Backported as #9670

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Feb 1, 2025
* Fix for failed test

TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
fatal: [testhost]: FAILED! => {
    "assertion": "check_client_when_present_and_same is not changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

* Improved test data to test more scenarios, e.g documentation uses True in examples

* Normalize values in config

* add changelog

* Apply suggestions from code review

Co-authored-by: Alexei Znamensky <[email protected]>

* Update tests/integration/targets/keycloak_client/vars/main.yml

Co-authored-by: Alexei Znamensky <[email protected]>

* Update changelogs/fragments/9644-kc_client-test-improvement-and-fix.yaml

Co-authored-by: Alexei Znamensky <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
(cherry picked from commit 250dc11)
Copy link

patchback bot commented Feb 1, 2025

Backport to stable-10: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-10/250dc1139c53ab429196fe64d8f3676e75977c61/pr-9644

Backported as #9671

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator

@amPrimeSign thanks for your contribution!
@russoz @apollo13 thanks for reviewing!

patchback bot pushed a commit that referenced this pull request Feb 1, 2025
* Fix for failed test

TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
fatal: [testhost]: FAILED! => {
    "assertion": "check_client_when_present_and_same is not changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

* Improved test data to test more scenarios, e.g documentation uses True in examples

* Normalize values in config

* add changelog

* Apply suggestions from code review

Co-authored-by: Alexei Znamensky <[email protected]>

* Update tests/integration/targets/keycloak_client/vars/main.yml

Co-authored-by: Alexei Znamensky <[email protected]>

* Update changelogs/fragments/9644-kc_client-test-improvement-and-fix.yaml

Co-authored-by: Alexei Znamensky <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
(cherry picked from commit 250dc11)
felixfontein pushed a commit that referenced this pull request Feb 1, 2025
…#9670)

Fb keycloak client improvement (#9644)

* Fix for failed test

TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
fatal: [testhost]: FAILED! => {
    "assertion": "check_client_when_present_and_same is not changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

* Improved test data to test more scenarios, e.g documentation uses True in examples

* Normalize values in config

* add changelog

* Apply suggestions from code review

Co-authored-by: Alexei Znamensky <[email protected]>

* Update tests/integration/targets/keycloak_client/vars/main.yml

Co-authored-by: Alexei Znamensky <[email protected]>

* Update changelogs/fragments/9644-kc_client-test-improvement-and-fix.yaml

Co-authored-by: Alexei Znamensky <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
(cherry picked from commit 250dc11)

Co-authored-by: amPrimeSign <[email protected]>
felixfontein pushed a commit that referenced this pull request Feb 1, 2025
#9671)

Fb keycloak client improvement (#9644)

* Fix for failed test

TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
fatal: [testhost]: FAILED! => {
    "assertion": "check_client_when_present_and_same is not changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

* Improved test data to test more scenarios, e.g documentation uses True in examples

* Normalize values in config

* add changelog

* Apply suggestions from code review

Co-authored-by: Alexei Znamensky <[email protected]>

* Update tests/integration/targets/keycloak_client/vars/main.yml

Co-authored-by: Alexei Znamensky <[email protected]>

* Update changelogs/fragments/9644-kc_client-test-improvement-and-fix.yaml

Co-authored-by: Alexei Znamensky <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
(cherry picked from commit 250dc11)

Co-authored-by: amPrimeSign <[email protected]>
@amPrimeSign
Copy link
Contributor Author

@russoz, @felixfontein thanks for the feedback and for the quick processing

Massl123 pushed a commit to Massl123/community.general that referenced this pull request Feb 7, 2025
* Fix for failed test

TASK [keycloak_client : Assert changes not detected in last two tasks (desire when same, and check)] ***
task path: /root/ansible_collections/community/general/tests/output/.tmp/integration/keycloak_client-p3ttqf7d-ÅÑŚÌβŁÈ/tests/integration/targets/keycloak_client/tasks/main.yml:79
fatal: [testhost]: FAILED! => {
    "assertion": "check_client_when_present_and_same is not changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

* Improved test data to test more scenarios, e.g documentation uses True in examples

* Normalize values in config

* add changelog

* Apply suggestions from code review

Co-authored-by: Alexei Znamensky <[email protected]>

* Update tests/integration/targets/keycloak_client/vars/main.yml

Co-authored-by: Alexei Znamensky <[email protected]>

* Update changelogs/fragments/9644-kc_client-test-improvement-and-fix.yaml

Co-authored-by: Alexei Znamensky <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch bug This issue/PR relates to a bug integration tests/integration module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants