saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.13k stars 5.47k forks source link

loop.until state cannot run without kwargs #52503

Open fattybenji opened 5 years ago

fattybenji commented 5 years ago

Description of Issue/Question

Setup

version v2018.3.2

Steps to Reproduce Issue

Run something like this :

Wait for something:
  loop_until:
    - name: test.sleep
    - condition: number_of_whatever == n
    - args:
      - 5

And it should break, saying that kwargs cannot be NoneType. In that case, test.sleep only has one arg, "length". Same when we only give it as kwarg :

     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1913, in call
                  cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1898, in wrapper
                  return f(*args, kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/loop.py", line 106, in until
                  m_ret = saltname
              TypeError: sleep() argument after ** must be a mapping, not NoneType
     Started: 18:02:06.437522
    Duration: 9.991 ms

I think it's because the loop.until state doesn't test null args or kwargs. I think it has not been modified in later version. We could maybe test whether args or kwargs are null and adapt the call, or create a default value...

If no one has the time I can probably give it a shot (if someone agrees on an implementation)

Versions Report

Salt Version:
           Salt: 2018.3.2

Dependency Versions:
           cffi: 1.6.0
       cherrypy: unknown
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: 0.26.3
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.26.4
         Python: 2.7.5 (default, Aug  4 2017, 00:39:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.4.1708 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-693.2.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.4.1708 Core

Don't hesitate to ask for more details.

Ch3LL commented 5 years ago

looks like i'm able to replicate this and seems you have a good grasp that the issue is m_kwargs is None. if you want to push a PR should be an easy fix.

fattybenji commented 5 years ago

Looks fixed by https://github.com/saltstack/salt/commit/f0c0bd08b82e97401b39bb59395d880bda14676a which is only in develop branch.

mmanea-tc commented 4 years ago

Is this fixed in 2018.3.4 or 2019.2.2 ? I am seeing same problem in these versions...

local:

      ID: wait_for_lock
Function: loop.until
    Name: vault.read_secret
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1933, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1951, in wrapper
              return f(*args, **kwargs)
            File "/usr/lib/python2.7/dist-packages/salt/states/loop.py", line 106, in until
              m_ret = __salt__[name](*m_args, **m_kwargs)
          TypeError: read_secret() argument after ** must be a mapping, not NoneType
 Started: 13:36:16.123531
Duration: 1.78 ms
 Changes:

cat loop.sls wait_for_lock: loop.until:

fattybenji commented 4 years ago

Right now, I see that the commit is only included in develop, neon and tornado50, so not fixed in those versions. Maybe the commit should be included in the 2018.3 and/or 2019.2 branches, but I don't know how that could be done (I'm not familiar with the process there)

Maybe our dear @Ch3LL could give us some information there.

mmanea-tc commented 4 years ago

Is there a workaround for this to make it work in the meantime? like declaring an empty mapping, or something like that?

mmanea-tc commented 4 years ago

anyone? no workaround?

fattybenji commented 4 years ago

Not 100% sure about the process here, but I will create two pull requests from and towards 2018.3 and 2019.2

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.