salt icon indicating copy to clipboard operation
salt copied to clipboard

prereq in cmd.run to file.managed firing without changes on windows

Open Conisant opened this issue 12 years ago • 3 comments

When prereq is used to prevent a cmd.run to fire at every highstate, it is ignored when the target is a file managed and the minion is running on windows machine.

Short example to reproduce the problem:

SomeCommand:
  cmd.run:
    - name: echo blubb
    - prereq:
      - file: SomeFile

SomeFile:
  file.managed:
    - name: /tmp/top.sls 
    - source: salt://top.sls
    - makedirs: True

Expected behaviour: On the first run the "echo" of "SomeCommand" will run, but later on it does not run as "SomeFile" reported no changes.

Observed behaviour: On windows minions, regardless of the outcome of "SomeFile" it runs "SomeCommand" The output speaks for itself:

ubuntu:
----------
          ID: SomeCommand
    Function: cmd.run
        Name: echo blubb
      Result: True
     Comment: No changes detected
     Changes:   
----------
          ID: SomeFile
    Function: file.managed
        Name: /tmp/top.sls
      Result: True
     Comment: File /tmp/top.sls is in the correct state
     Changes:   

Summary
------------
Succeeded: 2
Failed:    0
------------
Total:     2
win7:
----------
          ID: SomeCommand
    Function: cmd.run
        Name: echo blubb
      Result: True
     Comment: Command "echo blubb" run
     Changes:   
              ----------
              pid:
                  4364
              retcode:
                  0
              stderr:

              stdout:
                  blubb
----------
          ID: SomeFile
    Function: file.managed
        Name: /tmp/top.sls
      Result: True
     Comment: File /tmp/top.sls is in the correct state
     Changes:   

Summary
------------
Succeeded: 2
Failed:    0
------------
Total:     2

Ubuntu behaves correctly, but win7 does not. Using an other target as file.managed for prereq works as well (at least pkg.installed showed the expected behavious). Both master and minions are on 2014.1.10 Win8 and Win7 were tried as minions and RHEL and Ubuntu were masters.

Master:
           Salt: 2014.1.10
         Python: 2.6.5 (r265:79063, Sep 26 2013, 18:51:09)
         Jinja2: 2.3.1
       M2Crypto: 0.20.1
 msgpack-python: 0.1.9.final
   msgpack-pure: Not Installed
       pycrypto: 2.0.1
         PyYAML: 3.09
          PyZMQ: 13.0.0
            ZMQ: 3.2.2
Minion:
           Salt: 2014.1.10
         Python: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
         Jinja2: 2.7.1
       M2Crypto: 0.21.1
 msgpack-python: 0.4.2
   msgpack-pure: Not Installed
       pycrypto: 2.6
         PyYAML: 3.11
          PyZMQ: 14.1.1
            ZMQ: 4.0.4

I hope this is all the information you require to reproduce the problem.

Btw: salt is great! Keep it up!

Conisant avatar Aug 14 '14 08:08 Conisant

Thanks for the detailed report! My bet is there's a bug in win_file around the test=True run that's used to detect whether prereq needs to run. It probably always reports that changes are going to be made in test=True mode. We'll get this fixed!

basepi avatar Aug 15 '14 20:08 basepi

ZD-1398

rickh563 avatar May 02 '17 15:05 rickh563

I've tested this with the following sls file and found that Salt is exhibiting the proper behavior on both Ubuntu and Windows:

root@elsapo:/srv/salt/testprereq# cat /srv/salt/testprereq/init.sls 
{%- if salt['grains.get']('os_family') == 'Windows' %}
{%- set thepath = 'c:\\' %}
{%- set thedate = salt['cmd.run']('date /T') %}
{%- else %}
{%- set thepath = '/tmp/' %}
{%- set thedate = salt['cmd.run']('date') %}
{%- endif %}


echo {{ thedate }} >> {{ thepath }}thedate.txt:
  cmd.run:
    - prereq:
      - file: newfile

newfile:
  file.managed:
    - name: {{ thepath }}newfile.txt
    - contents: |
        This is line one
        This is line two

Let's run it the first time and we see that both files are created the first time.

[boucha@elsapo ~]$ sudo salt \* state.sls testprereq
dasalt:
----------
          ID: echo Tue May  2 14:20:04 MDT 2017 >> /tmp/thedate.txt
    Function: cmd.run
      Result: True
     Comment: Command "echo Tue May  2 14:20:04 MDT 2017 >> /tmp/thedate.txt" run
     Started: 14:20:04.826488
    Duration: 4.743 ms
     Changes:   
              ----------
              pid:
                  15629
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: newfile
    Function: file.managed
        Name: /tmp/newfile.txt
      Result: True
     Comment: File /tmp/newfile.txt updated
     Started: 14:20:04.831755
    Duration: 1.256 ms
     Changes:   
              ----------
              diff:
                  New file

Summary for dasalt
------------
Succeeded: 2 (changed=2)
Failed:    0
------------
Total states run:     2
Total run time:   5.999 ms
wintest:
----------
          ID: echo Tue 05/02/2017 >> c:\thedate.txt
    Function: cmd.run
      Result: True
     Comment: Command "echo Tue 05/02/2017 >> c:\thedate.txt" run
     Started: 20:20:06.761000
    Duration: 15.0 ms
     Changes:   
              ----------
              pid:
                  2600
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: newfile
    Function: file.managed
        Name: c:\newfile.txt
      Result: True
     Comment: File c:\newfile.txt updated
     Started: 20:20:06.776000
    Duration: 16.0 ms
     Changes:   
              ----------
              diff:
                  New file

Summary for wintest
------------
Succeeded: 2 (changed=2)
Failed:    0
------------
Total states run:     2
Total run time:  31.000 ms

Run it a second time and we see that neither executes the second time as expected:

[boucha@elsapo ~]$ sudo salt \* state.sls testprereq
dasalt:
----------
          ID: echo Tue May  2 14:20:37 MDT 2017 >> /tmp/thedate.txt
    Function: cmd.run
      Result: True
     Comment: No changes detected
     Changes:   
----------
          ID: newfile
    Function: file.managed
        Name: /tmp/newfile.txt
      Result: True
     Comment: File /tmp/newfile.txt is in the correct state
     Started: 14:20:37.788940
    Duration: 0.792 ms
     Changes:   

Summary for dasalt
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time:   0.792 ms
wintest:
----------
          ID: echo Tue 05/02/2017 >> c:\thedate.txt
    Function: cmd.run
      Result: True
     Comment: No changes detected
     Changes:   
----------
          ID: newfile
    Function: file.managed
        Name: c:\newfile.txt
      Result: True
     Comment: File c:\newfile.txt is in the correct state
     Started: 20:20:39.714000
    Duration: 0.0 ms
     Changes:   

Summary for wintest
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time:   0.000 ms

Here's my versions:

[boucha@elsapo ~]$ sudo salt \* test.version
dasalt:
    2016.11.4
wintest:
    2016.11.4

I think the possible test=True bug mentioned by @basepi has been taken care of. I'm going to close this issue as fixed. Please comment here if we need to reopen and revisit this issue.

Thanks!

UtahDave avatar May 02 '17 20:05 UtahDave