question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cmd.run cwd should not be checked before preconditions

See original GitHub issue

Interesting catch-22 issue here. Say you have:

TaskA:
   cmd.run:
    - name: mkdir /tmp/a
    - unless:  which B

TaskB:
   cmd.run:
   - name: echo "hello" > /bin/B
   - unless: which B
   - cwd: /tmp/a
   - require: 
      - TaskA

The first time this provisions, it works fine. Then the machine reboots and /tmp is gone.
The next time it provisions, it will fail because the cwd for TaskB no longer exists, and wont be created because the ‘unless’ precondition of TaskA is now fulfilled. We’re stuck.

I know this seems a silly case, but you can conceivably see a number of chained build steps doing something like this.

I’ve had a stab at fixing this here at eeaston/salt@3273ae on the 2014.1 branch, but it’s a bit of an API change. The changes were to move the cwd existence checking until after the precondition checking, and also remove the cwd from the context of the ‘unless’ and ‘onlyif’ tests.

If you’d like me to continue on this I can (I’ll write some tests and stuff), but the removal of the cwd from the ‘unless’ and ‘onlyif’ checks will need to be documented. What say ye? Cheers, Ed

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sastorslcommented, Aug 16, 2016

I’m seeing something similar to this with cmd.run + cwd + onlyif

<state>:
  - cmd.run: <do-something-to> /my/full/path
  - cwd: /my/full
  - onlyif:
    - /usr/bin/test -d /my/full/path

I would expect that the state is skipped if the onlyif test fails, but instead I’m getting:

 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/site-packages/salt/state.py", line 1733, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1651, in wrapper
              return f(*args, **kwargs)
            File "/usr/lib/python2.7/site-packages/salt/states/cmd.py", line 821, in run
              cret = mod_run_check(cmd_kwargs, onlyif, unless, creates)
            File "/usr/lib/python2.7/site-packages/salt/states/cmd.py", line 332, in mod_run_check
              cmd = __salt__['cmd.retcode'](entry, ignore_retcode=True, python_shell=True, **cmd_kwargs)
            File "/usr/lib/python2.7/site-packages/salt/modules/cmdmod.py", line 1773, in retcode
              password=kwargs.get('password', None))
            File "/usr/lib/python2.7/site-packages/salt/modules/cmdmod.py", line 460, in _run
              .format(cwd)
          CommandExecutionError: Specified cwd '/my/full/path' either not absolute or does not exist

My version

$ salt --versions-report
Salt Version:
           Salt: 2016.3.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.2.2
       dateutil: 1.5
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.21.1
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.5 (default, Oct 11 2015, 17:47:16)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.7.0
           RAET: Not Installed
          smmap: 0.8.1
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: redhat 7.2 Maipo
        machine: x86_64
        release: 3.10.0-327.13.1.el7.x86_64
         system: Linux
        version: Red Hat Enterprise Linux Server 7.2 Maipo
0reactions
taylor-petersoncommented, Jun 5, 2016

I’'m having this same issue on 2016.03.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requisites and Other Global State Arguments
If any required state fails, then the state will fail due to requisites. In the following example, the service state will not be...
Read more >
Usage | Task - Taskfile
Note that a task executed with a failing precondition will not run unless --force is given.
Read more >
How To Use cd, pwd, and ls to Explore the File System on a ...
We can move around the file hierarchy by using the cd command. This command stands for change directories. This will not appear to...
Read more >
CWD—Changing the Working Directory - TCP/IP ... - Unisys
If the specified directory path includes a usercode component, the FTP Server does not check the USERDATAFILE to determine whether the usercode is...
Read more >
Introduction to Sencha Cmd
Sencha Cmd will not update your JSB file as was done by the deprecated SDK Tools v2. ... --cwd, -cw - Sets the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found