salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG] salt/states/module.py does not handle those modules returning boolean True/False

Open gaoweisgp opened this issue 6 years ago • 7 comments

Description A clear and concise description of what the bug is.

modules like salt/modules/service.py: def status() only return a boolean of True/False. this type of return is not handled properly by salt/states/module.py: def run() in https://github.com/saltstack/salt/blob/master/salt/states/module.py#L429

So the state will always treat the module.run as True

Setup (Please provide relevant configs and/or SLS files (be sure to remove sensitive info).

state file: /srv/salt/junk.sls

test-module:
  module.run:
    - service.status:
      - salt-api

Steps to Reproduce the behavior (Include debug logs if possible and relevant)

Disable salt-api service on the salt master host salt-call state.sls junk

Expected behavior A clear and concise description of what you expected to happen.

Expect the state to return failure for label test-module

Screenshots If applicable, add screenshots to help explain your problem.

Versions Report

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

Additional context Add any other context about the problem here.

gaoweisgp avatar Jun 23 '20 20:06 gaoweisgp

@gaoweisgp could you please provide salt --versions-report for this issue, thanks

krionbsd avatar Jun 24 '20 06:06 krionbsd

based on the code, this issue should exist on all versions up to the latest 3001, as the develop branch has the same code base.

Also the unit test module linked to this could be affected for the var value False here https://github.com/saltstack/salt/blob/develop/tests/unit/states/test_module.py#L257

gaoweisgp avatar Jun 24 '20 12:06 gaoweisgp

Yeah, I just ran into this issue today with module.run when I tested switching to new module.run syntax. I added the use_superseded: [module.run] to my minion's configuration and now get a result of True, when I should get a return of False / failed state. This will break my state flow, where I might have require / onfail statements based on the outcome of the module.run.

test.sls

{{ sls }}-new:
  module.run:
    - mount.is_mounted:
      - name: /nfs/thisisinvalid

Result:

[rpenberthy@robert-salt-master ~]$ salt-call state.sls test
local:
----------
          ID: test-new
    Function: module.run
      Result: True
     Comment:
     Started: 19:46:04.477215
    Duration: 31.606 ms
     Changes:

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:  31.606 ms

Using the legacy module.run:

test.sls

{{ sls }}-legacy:
  module.run:
    - name: mount.is_mounted
    - m_name: /nfs/thisisinvalid

Result:

[rpenberthy@robert-salt-master ~]$ salt-call state.sls test
[WARNING ] The function "module.run" is using its deprecated version and will expire in version "Sodium".
[ERROR   ] {'ret': False}
local:
----------
          ID: test-legacy
    Function: module.run
        Name: mount.is_mounted
      Result: False
     Comment: Module function mount.is_mounted executed
     Started: 19:48:21.325241
    Duration: 20.259 ms
     Changes:
              ----------
              ret:
                  False

Summary for local
------------
Succeeded: 0 (changed=1)
Failed:    1
------------
Total states run:     1
Total run time:  20.259 ms

Here is my versions report @krionbsd :

Salt Version:
           Salt: 3000.3

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.8.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.11.1
        libgit2: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Apr  2 2020, 13:34:55)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 15.3.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

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

Hope this can be fixed for the 3001 release.

robertpenberthy avatar Jul 30 '20 19:07 robertpenberthy

@robertpenberthy and @gaoweisgp can you give the fix in https://github.com/saltstack/salt/pull/58818 a try

Ch3LL avatar Oct 26 '20 20:10 Ch3LL

@Ch3LL I went ahead and manually made the changes from your PR to a copy of the module.py state file from v3000.3 locally, then I sync the module to my master minion and I show that it did return a false result this time as expected. Here is the output from testing:

[rpenberthy@robert-salt-master ~]$ salt-call state.sls test
[ERROR   ] 'mount.is_mounted': False
local:
----------
          ID: test-new
    Function: module.run
      Result: False
     Comment: 'mount.is_mounted': False
     Started: 21:20:43.460933
    Duration: 29.626 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:  29.626 ms

robertpenberthy avatar Oct 26 '20 21:10 robertpenberthy

I also tested the legacy module.run format and it continued to work as it did before.

robertpenberthy avatar Oct 26 '20 21:10 robertpenberthy

thanks for confirming it works :)

Ch3LL avatar Oct 27 '20 10:10 Ch3LL