Parsing __grains__ with json.dumps in a module is returning an empty dict in 2016.3.3
Description of Issue/Question
We migrated from 2015.8.7 to 2016.3.3 and we have some custom modules that store the pillar and grains data in an external database in json format. It worked in 2015.8.7 but not in 2016.3.3. I see you have a partial patch in the 2016.3 branch, but that only works if you cast it to a string first. #36496
Setup
Here is some example module code to reproduce (/var/cache/salt/minion/extmods/modules/broken.py).
#!/usr/bin/env python
import salt
import logging
import json
log = logging.getLogger(__name__)
def set_grains():
log.debug("jsongrains native: %r", json.dumps(__grains__))
log.debug("jsongrains string: %r", json.dumps(str(__grains__)))
log.debug(__grains__)
log.debug("saltversion: %r", __grains__['saltversion'])
Steps to Reproduce Issue
Here it works on 2015.8.7
[[email protected] modules]# salt-call broken.set_grains -l debug
[DEBUG ] Reading configuration from /etc/salt/minion
<SNIP>
[DEBUG ] LazyLoaded jinja.render
[DEBUG ] LazyLoaded yaml.render
[DEBUG ] LazyLoaded broken.set_grains
[DEBUG ] jsongrains native: {"kernelrelease": "3.10.0-327.el7.x86_64", "os": "RedHat"}
[DEBUG ] jsongrains string: {"kernelrelease": "3.10.0-327.el7.x86_64", "os": "RedHat"}
[DEBUG ] {u'kernelrelease': '3.10.0-327.el7.x86_64', 'os': 'RedHat'}
[DEBUG ] saltversion: 2015.8.7
[DEBUG ] LazyLoaded mysql.returner
[DEBUG ] LazyLoaded config.option
local:
None
Here it doesn't work on 2016.3.3
[[email protected] modules]# salt-call broken.set_grains -l debug
<SNIP>
[DEBUG ] LazyLoaded jinja.render
[DEBUG ] LazyLoaded yaml.render
[DEBUG ] LazyLoaded broken.set_grains
[DEBUG ] jsongrains native: '{}'
[DEBUG ] jsongrains string: '"{u\'kernelrelease\': \'3.10.0-327.el7.x86_64\', \'os\': \'RedHat\'}"'
[DEBUG ] {}
[DEBUG ] saltversion: '2016.3.3'
[DEBUG ] LazyLoaded mysql.returner
[DEBUG ] LazyLoaded config.option
[DEBUG ] Generating new MySQL connection pool
[DEBUG ] LazyLoaded nested.output
local:
None
Versions Report
Salt Version:
Salt: 2016.3.3
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.7
mysql-python: 1.2.3
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.5 (default, Oct 11 2015, 17:47:16)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.7.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: redhat 7.2 Maipo
machine: x86_64
release: 3.10.0-327.x86_64
system: Linux
version: Red Hat Enterprise Linux Server 7.2 Maipo
Confirmed as seeing the same output and issue. cc: @cachedout
This PR should fix this problem https://github.com/saltstack/salt/pull/37279
Confirmed this fixes the issue.
Fix was merged. Closing.
Thanks all!