salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG] salt/modules/network.py: def connect() not return ret['retcode']

Open gaoweisgp opened this issue 6 years ago • 2 comments

Description A clear and concise description of what the bug is. Related code inside develop branch https://github.com/saltstack/salt/blob/develop/salt/modules/network.py#L1385

salt/modules/network.py: def connect() does not return ret['retcode']. This causes salt/states/module.py: def _get_result() to return True when the ret['result'] is False. https://github.com/saltstack/salt/blob/develop/salt/states/module.py#L650

In the following case, the changes_ret inside salt/states/module.py: def _get_result() is not doing much as the changes was still just been initialized in salt/states/module.py: def run() at https://github.com/saltstack/salt/blob/develop/salt/states/module.py#L423

Proposed solution option #1: Don't change salt/states/module.py. Ensure those status checking modules (like network.py: def connect()) return dictionary include ret['retcode'] value

Proposed solution option #2: Update salt/states/module.py: def _get_result() to handle module return dictionary with ret['result': True/False, 'comment': 'text string']

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

single salt master host with salt-master and salt-minion service up running

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

# cat junk.sls 
test-network-connect:
  module.run:
    - network.connect:
      - host: junk
      - port: 22

# salt-call state.sls junk
inside salt/states/module.py def _get_result, func_ret: 
{'result': False, 'comment': 'Unable to resolve host junk on tcp port 22'}

changes: 
{}


local:
----------
          ID: test-network-connect
    Function: module.run
      Result: True
     Comment: network.connect: Unable to resolve host junk on tcp port 22
     Started: 12:57:27.062913
    Duration: 50.00000074505806 ms
     Changes:   
              ----------
              network.connect:
                  ----------
                  comment:
                      Unable to resolve host junk on tcp port 22
                  result:
                      False

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

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

Expect the state summary to have Failed: 1

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.)

Based on the code base, this should exist from 2017 ~ 3001

PASTE HERE

Additional context Add any other context about the problem here.

Related unit test: https://github.com/saltstack/salt/blob/develop/tests/unit/modules/test_network.py#L245 few lines in this section could be changed to something like

'result': False}) ===> 'result': False, 'retcode': 0})

gaoweisgp avatar Jun 24 '20 13:06 gaoweisgp

@gaoweisgp thanks for the report, could you submit the patch to fix it, ping me if you need help for that.

krionbsd avatar Jun 25 '20 06:06 krionbsd

Fixed by #65842 / commit 0ccd0fbaebe (Dec 2024) and backported to 3006.x via #67115 (Apr 2025). Verified: with the reporter's repro, _get_result({'result': False, 'comment': '...'}) returns False on 3006.x, 3007.x, 3008.x, and master, and the state now reports result: False as expected. Closing.

dwoz avatar Jul 01 '26 10:07 dwoz