salt icon indicating copy to clipboard operation
salt copied to clipboard

cache.grains runner returns all minions when match is not found

Open ipmb opened this issue 8 years ago • 3 comments

Description of Issue/Question

Failure to target any minions should return 0 minions, not all minions.

Steps to Reproduce Issue

salt-run --out=json cache.grains tgt="does-not:exist" tgt_type="grain" | jq keys

# returns a list of all minions

Versions Report

Salt Version:
           Salt: 2017.7.2

Dependency Versions:
           cffi: 1.5.2
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: 0.24.0
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.24.0
         Python: 2.7.12 (default, Nov 20 2017, 18:23:56)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-59-generic
         system: Linux
        version: Ubuntu 16.04 xenial

ipmb avatar Jan 17 '18 00:01 ipmb

looks like i'm able to replicate this. Please feel free to submit a PR if you want to look at a fix.

Also anyone from @saltstack/team-core if you want to attack this one as well.

Ch3LL avatar Jan 17 '18 15:01 Ch3LL

it's not runner bug, it's more deep issue.

runner use instance of MasterPillarUtil class initialized with specific data. https://github.com/saltstack/salt/blob/502c597b1e84531c42380adc1a15daf8f1cdc702/salt/runners/cache.py#L57-L61

that function returns empty list

https://github.com/saltstack/salt/blob/502c597b1e84531c42380adc1a15daf8f1cdc702/salt/utils/master.py#L311

but we jump to if due to class initialization values and _get_cached_minion_data method returns minion cached grains for all if you call it without arguments.

https://github.com/saltstack/salt/blob/502c597b1e84531c42380adc1a15daf8f1cdc702/salt/utils/master.py#L146-L147

that data passed further and used in result

https://github.com/saltstack/salt/blob/502c597b1e84531c42380adc1a15daf8f1cdc702/salt/utils/master.py#L205-L211

I think we need to return empty dict if targets list is empty. Will submit PR.

samodid avatar Jan 21 '18 19:01 samodid

This is fixed now, beginning with the 2017.7.5 and 2018.3.0 releases.

rallytime avatar Aug 24 '18 19:08 rallytime