-
Notifications
You must be signed in to change notification settings - Fork 73
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
fix: UTF-8 data in the JSON response for ansible 2.18< #693
base: master
Are you sure you want to change the base?
fix: UTF-8 data in the JSON response for ansible 2.18< #693
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #693 +/- ##
==========================================
- Coverage 73.55% 73.21% -0.34%
==========================================
Files 6 6
Lines 934 941 +7
Branches 143 145 +2
==========================================
+ Hits 687 689 +2
- Misses 210 212 +2
- Partials 37 40 +3 ☔ View full report in Codecov by Sentry. |
@@ -466,6 +469,13 @@ def convert_to_supported(val): | |||
return str(val) | |||
elif isinstance(val, ObjectId): | |||
return str(val) | |||
# This is for replicasets in the output of general.signature.hash segment | |||
# This is intended to solve userId output of | |||
elif isinstance(val, bytes) and len(val) == 16: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure about the need to test the length of the value here. What happens if there's a bytes value of <16, 17,18,19 or >20? A generic solution would probably make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can also be solved here as I think was the intention and possibly something that worked once (https://github.com/ansible-collections/community.mongodb/blob/979ca9f72cb47e7571d89531bfe17375c011193e/plugins/modules/mongodb_info.py#L223C1-L226C1 The forloop in that function to check if isinstance(val, UUID) but I never got it to trigger on being uuid when debugging that. It can likely be omitted.
You mean we check if it is bytes and then have a length-if-section for 16(being UUID) and one for 20(signature-hash) and then possibly another catch all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well.. something like that i guess, otherwise the bug is still there.
Tests exists for both sytandalone and replicaset MongoDB Instance in https://github.com/ansible-collections/community.mongodb/tree/master/tests/integration/targets/mongodb_info/tasks It's probably easy to add a test for this case. |
[master_tasks/mongod_replicaset](https://github.com/ansible-collections/community.mongodb/blob/master/tests/integration/targets/master_tasks/mongod_replicaset.yml) Is it possible to use the mongodb_info there? So like...
are there tests running that also create users? |
You can use all of the mongodb_ modules here. Tests exist for mongodb_user, if that's what you mean. |
Yes thank you! I am more concerned about the userid part as it will fail the entire This seems useful, I have played around with assert in my playbook. This seems to work:
While it fails when i change it to
But I guess this should be added after the fix have been applied that corrects the userid |
…ying to convert unknown bytes instance length.
SUMMARY
Fixes #692
ISSUE TYPE
COMPONENT NAME
This is done to solve mongodb_info module related
ADDITIONAL INFORMATION
See #692
Before output of mongodb_info
After the fix the signature looks correct.
Equivalent to what mongosh: rs.status()
The userid from mongodb_info output look like this:
As the userid from mongosh show users look like:
``
userId: UUID('748a2493-e8c5-46b1-8733-151ca8f11690'),