salt icon indicating copy to clipboard operation
salt copied to clipboard

Parsing __grains__ with json.dumps in a module is returning an empty dict in 2016.3.3

Open junster1 opened this issue 10 years ago • 4 comments

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

junster1 avatar Oct 26 '16 22:10 junster1

Confirmed as seeing the same output and issue. cc: @cachedout

SEJeff avatar Oct 26 '16 22:10 SEJeff

This PR should fix this problem https://github.com/saltstack/salt/pull/37279

gtmanfred avatar Oct 27 '16 17:10 gtmanfred

Confirmed this fixes the issue.

junster1 avatar Oct 27 '16 21:10 junster1

Fix was merged. Closing.

Thanks all!

rallytime avatar Nov 01 '16 15:11 rallytime