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

Fix grafana_dashboard py2/3 compatibility #49194

Merged
merged 2 commits into from
Dec 12, 2018

Conversation

jqueuniet
Copy link
Contributor

SUMMARY

Fix grafana_dashboard Python 2 compatibility

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

grafana_dashboard

ADDITIONAL INFORMATION

Merge request #47708 added a regression with Python 2, causing the following error:

failed: [grafana-infra-000] (item=['node_exporter.json', 'prometheus-infra-000']) => {"changed": false, "item": ["node_exporter.json", "prometheus-infra-000"], "msg": "error : descriptor 'split' requires a 'str' object but received a 'unicode'"}

Issue was the json.loads in the Grafana version check returned a unicode variable, incompatible with str.split.

I switched to using the split method from the returned object, either str.split or unicode.split depending on the type. The integer cast at the end of the function works with either type and normalizes the function output.

I also got the following error testing this fix for Python 3, also in the Grafana version check, and tried to correct it too:

failed: [grafana-infra-000] (item=['node_exporter.json', 'prometheus-infra-000']) => {"changed": false, "item": ["node_exporter.json", "prometheus-infra-000"], "msg": "error : the JSON object must be str, not 'bytes'"}

This time, it was the json.loads that was choking on a bytes object. I added a call to the to_text function to handle this issue, and added a case for UnicodeError in the exception handling.

Some data on my environment:

ansible 2.8.0.dev0 (fix_grafana_py2 7008e1bb47) last updated 2018/11/27 16:42:11 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/johann/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/johann/src/ansible/lib/ansible
  executable location = /home/johann/src/ansible/bin/ansible
  python version = 3.7.1 (default, Oct 22 2018, 10:41:28) [GCC 8.2.1 20180831]

@ansibot
Copy link
Contributor

ansibot commented Nov 27, 2018

Hi @jqueuniet, thank you for submitting this pull-request!

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 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. 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 Nov 27, 2018
@Akasurde Akasurde removed the needs_triage Needs a first human triage before being processed. label Nov 28, 2018
@remyleone
Copy link
Contributor

@pilou- Could you review?

@ansibot
Copy link
Contributor

ansibot commented Dec 7, 2018

cc @seuf
click here for bot help

@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 Dec 7, 2018
Copy link
Contributor

@seuf seuf left a comment

Choose a reason for hiding this comment

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

I've tried both python2.7 and python 3 and it worked for me.
Thanks for your contribution 😃
LGTM

@gundalow
Copy link
Contributor

rebuild_merge

Once merged please raise a backport PR including a changelog/fragment

@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 Dec 12, 2018
@ansibot ansibot merged commit b079070 into ansible:devel Dec 12, 2018
kbreit pushed a commit to kbreit/ansible that referenced this pull request Jan 11, 2019
* Fix grafana_dashboard py2 compatibility

* Convert URL output to a text/unicode string for json.loads
@dagwieers dagwieers added the grafana Grafana community label Feb 7, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. grafana Grafana community module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants