saltstack / saltstack/salt

onfail_in executes once function if the salt state define 2 functions

Open
#55,173 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Confirmed Requisite severity-high
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description of Issue

The behaviour is not the same if we omit state module in requisites with onfail_in and two functions in the same state.

Setup

test-1.sls

quit_on_error:
  event.send:
    - name: custom/error/event
    - data:
      - key1: value1
  cmd.run:
    - name: bash -c 'false'
    - failhard: True

step-1:
  cmd.run:
    - name: echo OK
    - onfail_in:
      - event: quit_on_error
      - cmd: quit_on_error

test-2.sls

quit_on_error:
  event.send:
    - name: custom/error/event
    - data:
      - key1: value1
  cmd.run:
    - name: bash -c 'false'
    - failhard: True

step-1:
  cmd.run:
    - name: echo OK
    - onfail_in:
      -  quit_on_error
Steps to Reproduce Issue
$ salt minion-1 state.apply test-1.sls

minion-1:
----------
          ID: step-1
    Function: cmd.run
        Name: echo OK
      Result: True
     Comment: Command "echo OK" run
     Started: 13:55:13.014104
    Duration: 14.797 ms
     Changes:   
              ----------
              pid:
                  2891
              retcode:
                  0
              stderr:
              stdout:
                  OK
----------
          ID: quit_on_error
    Function: event.send
        Name: custom/error/event
      Result: True
     Comment: State was not run because onfail req did not change
     Started: 13:55:13.029609
    Duration: 0.016 ms
     Changes:   
----------
          ID: quit_on_error
    Function: cmd.run
        Name: bash -c 'false'
      Result: True
     Comment: State was not run because onfail req did not change
     Started: 13:55:13.029859
    Duration: 0.015 ms
     Changes:   

Summary for minion-1
------------
Succeeded: 3 (changed=1)
Failed:    0
------------
Total states run:     3
Total run time:  14.828 ms

if we omit state module in onfail_in, the quit_on_error. cmd.run function is executed event the state with onfail_in exit with success

$ salt minion-1 state.apply test-2.sls

minion-1:
----------
          ID: step-1
    Function: cmd.run
        Name: echo OK
      Result: True
     Comment: Command "echo OK" run
     Started: 13:53:52.702099
    Duration: 15.399 ms
     Changes:   
              ----------
              pid:
                  2842
              retcode:
                  0
              stderr:
              stdout:
                  OK
----------
          ID: quit_on_error
    Function: event.send
        Name: custom/error/event
      Result: True
     Comment: State was not run because onfail req did not change
     Started: 13:53:52.718150
    Duration: 0.015 ms
     Changes:   
----------
          ID: quit_on_error
    Function: cmd.run
        Name: bash -c 'false'
      Result: False
     Comment: Command "bash -c 'false'" run
     Started: 13:53:52.718262
    Duration: 13.783 ms
     Changes:   
              ----------
              pid:
                  2843
              retcode:
                  1
              stderr:
              stdout:

Summary for minion-1
------------
Succeeded: 2 (changed=2)
Failed:    1
------------
Total states run:     3
Total run time:  29.197 ms
Versions Report

Salt Version:
Salt: 2019.2.1

Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: 2.8.0
docker-py: 1.10.6
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.10.3
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
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: 2.7.16 (default, May 11 2019, 02:15:00)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: 18.1.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 5.1.1
ZMQ: 4.3.2

System Versions:
dist:
locale: UTF-8
machine: x86_64
release: 5.1.18-200.fc29.x86_64
system: Linux
version: Not Installed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the discrepancy with the test-1.sls and test-2.sls examples using salt minion-1 state.apply. Compare how onfail_in resolves the two functions under the quit_on_error state, and consider the issue done when both forms produce the intended, consistent result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.