Fix grafana_dashboard py2/3 compatibility (#49194)

* Fix grafana_dashboard py2 compatibility

* Convert URL output to a text/unicode string for json.loads
This commit is contained in:
Johann Queuniet 2018-12-12 18:42:55 +01:00 committed by ansibot
parent 920be06670
commit b079070688

View file

@ -140,6 +140,7 @@ import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url, url_argument_spec
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_text
__metaclass__ = type
@ -182,8 +183,10 @@ def get_grafana_version(module, grafana_url, headers):
r, info = fetch_url(module, '%s/api/frontend/settings' % grafana_url, headers=headers, method='GET')
if info['status'] == 200:
try:
settings = json.loads(r.read())
grafana_version = str.split(settings['buildInfo']['version'], '.')[0]
settings = json.loads(to_text(r.read()))
grafana_version = settings['buildInfo']['version'].split('.')[0]
except UnicodeError as e:
raise GrafanaAPIException('Unable to decode version string to Unicode')
except Exception as e:
raise GrafanaAPIException(e)
else: