saltstack / saltstack/salt

[BUG] mysql_query.run output=grain - Whitespace in dictionary key

Open
#58,135 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
I'm writing a state for automate Icingaweb2 database stuff.
For checking if someone has changed the password of an account "admin" i will check the pasword_hash and must save the mysq_query.run output to the grains to be able to use the content of the grain for later checks.
My problem now is that in the dictionary of the grain is a key called "rows returned" that has a whitespace in his name. So i'm not able to call it with salt-call grains.get icingaweb2:mysql_check_user:rows returned.
But if this key would be called "rows_returned" then i can call it with salt-call grains.get icingaweb2:mysql_check_user:rows_returned.

Setup
State:

Check_user_{{ username }}_and_password:
  mysql_query.run:
    - database: icingaweb2
    - query: "Select name,password_hash FROM icingaweb_user WHERE name = 'admin' AND password_hash = '{{ user['pwdhash'] }}';"
    - output: grain
    - grain: icingaweb2
    - key: mysql_check_user

debianserver: ~/ $ salt-call grains.get icingaweb2:mysql_check_user

local:
    ----------
    columns:
        - name
        - password_hash
    query time:
        ----------
        human:
            0.2ms
        raw:
            0.00018
    results:
    rows returned:
        0

Expected behavior
debianserver: ~/ $ salt-call grains.get icingaweb2:mysql_check_user

local:
    ----------
    columns:
        - name
        - password_hash
    query time:
        ----------
        human:
            0.2ms
        raw:
            0.00018
    results:
    rows_returned:
        0

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

Salt Version:
Salt: 2019.2.5

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: 1.3.10
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.7.3 (default, Jul 25 2020, 13:03:44)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: 17.1.2
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.1

System Versions:
dist: debian 10.5
locale: UTF-8
machine: x86_64
release: 4.19.0-9-amd64
system: Linux
version: debian 10.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the mysql_query.run handling for output=grain and trace how its result dictionary is exposed through salt-call grains.get. Reproduce the icingaweb2 example, then verify that the returned key uses an underscore so it can be queried as rows_returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.