Update module.py

using module.run to check if port 53 is opened on localhost, using module network.connect  
example state: 
~~~
network.connect:
  module.run: 
    - host: {{ salt['network.ipaddrs']()|join }}
    - port: 53
    - port: 1234
    - proto: udp

unexpected behavior: 
module.run will always succeed, 
even If network.connect returns result: False

example output (before the change): 
----------
          ID: network.connect
    Function: module.run
      Result: True
     Comment: Module function network.connect executed
     Started: 22:28:29.475623
    Duration: 0.001 ms
     Changes:   
              ----------
              ret:
                  ----------
                  comment:
                      Unable to connect to 10.0.0.50 (10.0.0.50) on tcp port 1234
                  result:
                      False

Proposal: 
Proposing to check changes_ret.result and return it as a result before trying to check changes_ret.retcode 

tested expected behavior: 
~~~
----------
          ID: network.connect
    Function: module.run
      Result: False
     Comment: Module function network.connect executed
     Started: 22:50:25.149832
    Duration: 9.964 ms
     Changes:   
              ----------
              ret:
                  ----------
                  comment:
                      Unable to connect to 10.0.0.50 (10.0.0.50) on tcp port 1234
                  result:
                      False

----------
          ID: network.connect
    Function: module.run
      Result: True
     Comment: Module function network.connect executed
     Started: 22:50:07.129629
    Duration: 0.205 ms
     Changes:   
              ----------
              ret:
                  ----------
                  comment:
                      Successfully connected to 10.0.0.50 (10.0.0.50) on tcp port 53
                  result:
                      True
This commit is contained in:
Sergey Paramonov 2015-12-05 23:05:35 -05:00 committed by rallytime
parent e33c1f456a
commit 1f8f4cb99b

View File

@ -232,8 +232,11 @@ def run(name, **kwargs):
ret['result'] = mret
else:
changes_ret = ret['changes'].get('ret', {})
if isinstance(changes_ret, dict) and changes_ret.get('retcode', 0) != 0:
ret['result'] = False
if isinstance(changes_ret, dict):
if isinstance(changes_ret.get('result', {}), bool):
ret['result'] = changes_ret.get('result', {})
elif changes_ret.get('retcode', 0) != 0:
ret['result'] = False
return ret
mod_watch = run # pylint: disable=C0103