Merge pull request #47168 from gtmanfred/metadata

fix metadata grain for py3 and windows
This commit is contained in:
Nicole Thomas 2018-04-20 15:07:49 -04:00 committed by GitHub
commit a56eb7e05d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,11 @@ import os
import socket
# Import salt libs
import salt.ext.six as six
import salt.utils.data
import salt.utils.http as http
import salt.utils.json
import salt.utils.stringutils
# metadata server information
@ -51,9 +54,10 @@ def _search(prefix="latest/"):
linedata = http.query(os.path.join(HOST, prefix), headers=True)
if 'body' not in linedata:
return ret
body = salt.utils.stringutils.to_unicode(linedata['body'])
if linedata['headers'].get('Content-Type', 'text/plain') == 'application/octet-stream':
return linedata['body']
for line in linedata['body'].split('\n'):
return body
for line in body.split('\n'):
if line.endswith('/'):
ret[line[:-1]] = _search(prefix=os.path.join(prefix, line))
elif prefix == 'latest/':
@ -70,11 +74,14 @@ def _search(prefix="latest/"):
retdata = http.query(os.path.join(HOST, prefix, line)).get('body', None)
# (gtmanfred) This try except block is slightly faster than
# checking if the string starts with a curly brace
if isinstance(retdata, six.binary_type):
try:
ret[line] = salt.utils.json.loads(retdata)
ret[line] = salt.utils.json.loads(salt.utils.stringutils.to_unicode(retdata))
except ValueError:
ret[line] = salt.utils.stringutils.to_unicode(retdata)
else:
ret[line] = retdata
return ret
return salt.utils.data.decode(ret)
def metadata():