[BUG] Unless requisite returns wrong result on cmd with non-existing cwd
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
The unless check does not fail when executed in a non-existing directory.
I'd expect either an error or the correct result of the unless check.
In the following example I get Comment: unless condition is true.
Setup
Classic Salt Master-Minion Setup.
Steps to Reproduce the behavior
State SLS file:
/tmp/bugreport:
file.directory
/tmp/doesnotexist:
file.absent
command_create_file:
cmd.run:
- name: test -s /tmp/bugreport/validation.key || echo 'randomkey' > /tmp/bugreport/validation.key
- cwd: /tmp/doesnotexist
#- cwd: /tmp
- unless: test -f /tmp/bugreport/validation.key
Output:
# salt 'papierdev.layer5.net' state.apply services.layer5-ng.bug
papierdev.layer5.net:
----------
ID: /tmp/bugreport
Function: file.directory
Result: True
Comment:
Started: 08:53:20.688123
Duration: 9.919 ms
Changes:
----------
/tmp/bugreport:
----------
directory:
new
----------
ID: /tmp/doesnotexist
Function: file.absent
Result: True
Comment: File /tmp/doesnotexist is not present
Started: 08:53:20.698183
Duration: 0.468 ms
Changes:
----------
ID: command_create_file
Function: cmd.run
Name: test -s /tmp/bugreport/validation.key || echo 'randomkey' > /tmp/bugreport/validation.key
Result: True
Comment: unless condition is true
Started: 08:53:20.699459
Duration: 1336.724 ms
Changes:
Summary for papierdev.layer5.net
------------
Succeeded: 3 (changed=1)
Failed: 0
------------
Total states run: 3
Total run time: 1.347 s
Expected behavior
After changing the cwd to /tmp it works as expected:
# salt 'papierdev.layer5.net' state.apply services.layer5-ng.bug
papierdev.layer5.net:
----------
ID: /tmp/bugreport
Function: file.directory
Result: True
Comment: The directory /tmp/bugreport is in the correct state
Started: 09:10:52.320037
Duration: 8.631 ms
Changes:
----------
ID: /tmp/doesnotexist
Function: file.absent
Result: True
Comment: File /tmp/doesnotexist is not present
Started: 09:10:52.328795
Duration: 0.461 ms
Changes:
----------
ID: command_create_file
Function: cmd.run
Name: test -s /tmp/bugreport/validation.key || echo 'randomkey' > /tmp/bugreport/validation.key
Result: True
Comment: Command "test -s /tmp/bugreport/validation.key || echo 'randomkey' > /tmp/bugreport/validation.key" run
Started: 09:10:52.329977
Duration: 1254.758 ms
Changes:
----------
pid:
3270072
retcode:
0
stderr:
stdout:
Summary for papierdev.layer5.net
------------
Succeeded: 3 (changed=1)
Failed: 0
------------
Total states run: 3
Total run time: 1.264 s
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)Salt Master:
Salt Version:
Salt: 3007.1
Python Version:
Python: 3.10.14 (main, Apr 3 2024, 21:30:09) [GCC 11.2.0]
Dependency Versions:
cffi: 1.16.0
cherrypy: unknown
dateutil: 2.8.2
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.4
libgit2: Not Installed
looseversion: 1.3.0
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.7
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 23.1
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.19.1
pygit2: Not Installed
python-gnupg: 0.5.2
PyYAML: 6.0.1
PyZMQ: 25.1.2
relenv: 0.16.0
smmap: Not Installed
timelib: 0.3.0
Tornado: 6.3.3
ZMQ: 4.3.4
Salt Package Information:
Package Type: onedir
System Versions:
dist: debian 12.8 bookworm
locale: utf-8
machine: x86_64
release: 6.1.0-26-amd64
system: Linux
version: Debian GNU/Linux 12.8 bookworm
Salt Minion:
# salt-minion --versions-report
Salt Version:
Salt: 3006.8
Python Version:
Python: 3.10.14 (main, Apr 3 2024, 21:33:04) [GCC 11.2.0]
Dependency Versions:
cffi: 1.14.6
cherrypy: 18.6.1
dateutil: 2.8.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.3
libgit2: Not Installed
looseversion: 1.0.2
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 22.0
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.19.1
pygit2: Not Installed
python-gnupg: 0.4.8
PyYAML: 6.0.1
PyZMQ: 23.2.0
relenv: 0.16.0
smmap: Not Installed
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: debian 12 bookworm
locale: utf-8
machine: aarch64
release: 6.1.0-21-arm64
system: Linux
version: Debian GNU/Linux 12 bookworm
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Salt's cmd.run state handling for the unless guard and cwd, using the provided SLS as the reproduction. Compare behavior with an existing and non-existing working directory, then add coverage for the reported case. Done means the nonexistent-cwd case returns an error or the correct unless result instead of falsely reporting that the condition is true.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100