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

consul_kv: decodes kv values from Consul to utf-8 #35894

Merged
merged 3 commits into from
Mar 22, 2018

Conversation

colin-nolan
Copy link
Contributor

SUMMARY

Fixes #35893 by decoding values from Consul as utf-8.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

consul_kv

ANSIBLE VERSION
ansible 2.4.2.0
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.2 (default, Sep 13 2017, 14:26:54) [GCC 4.9.2]
ADDITIONAL INFORMATION

N/A

@ansibot
Copy link
Contributor

ansibot commented Feb 8, 2018

@ansibot ansibot added bugfix_pull_request community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Feb 8, 2018
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Feb 9, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Feb 17, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 2, 2018
@abadger
Copy link
Contributor

abadger commented Mar 20, 2018

This looks like the right idea but you should use our helper functions for encoding and decoding text. When you do that, the code will look like this:

from ansible.module_utils._text import to_text
[...]
try:
    changed = not existing or (existing and to_text(existing['Value'], errors='surrogate_or_strict') != value)
except UnicodeError:
    # Existing value was undecodable but all values we set are valid utf-8
    changed = True

@colin-nolan
Copy link
Contributor Author

@abadger thanks. Why does the _text module name suggest that it's (package) private? It does not look like somewhere I should be importing things from for general use!

@abadger
Copy link
Contributor

abadger commented Mar 20, 2018 via email

@colin-nolan colin-nolan force-pushed the fix/35893-consul-kv-py3-idempotence branch from 41abd67 to 41a5273 Compare March 20, 2018 15:17
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 20, 2018
@colin-nolan
Copy link
Contributor Author

Updated to use decoding helper. Also added self to authors list to speed up acceptance of future community PRs (I'm already an author on consul_acl).

@abadger abadger merged commit a4a2b4a into ansible:devel Mar 22, 2018
abadger pushed a commit to abadger/ansible that referenced this pull request Mar 22, 2018
* Decodes kv values from Consul to utf-8.

* Switches to using module utils to perform text decoding.

* Adds self to authors list to help community maintenance.

(cherry picked from commit a4a2b4a)
@abadger abadger moved this from TODO to Done in Python 3 compatibility Mar 22, 2018
@colin-nolan colin-nolan deleted the fix/35893-consul-kv-py3-idempotence branch March 23, 2018 09:47
abadger added a commit that referenced this pull request Apr 10, 2018
* consul_kv: decodes kv values from Consul to utf-8 (#35894)

* Decodes kv values from Consul to utf-8.

* Switches to using module utils to perform text decoding.

* Adds self to authors list to help community maintenance.

(cherry picked from commit a4a2b4a)

* Add a changelog fragment for consul_kv python3 fix
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

consul_kv: putting string into Consul is not idempotent in Python 3
4 participants