Repository navigation
Closed
Labels
P4Priority 4bugbroken, incorrect, or confusing behaviorfixed-pls-verifyfix is linked, bug author to confirm fixseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone
Description
Description of Issue/Question
Use-case:
- Move a pre-packaged configuration of software package-x to package-x.conf.example
- Place my own package-x.conf there instead
Works correct for the first run, when package-x.conf.example doesn't exist yet.
Fails on consecutive runs, because package-x.conf.example already exists.
Using 'force=True' is not an option, because after the second state.apply, the packaged version would be lost.
Shouldn't the file.rename report a "success, renamed file already in correct state" instead of a failure when force is not used?
Misunderstanding? Or am I doing something non-idiomatic here and there's a better way?
Setup
# Backup distro provided config as example
/etc/package-x/package-x.conf.example:
file.rename:
- source: /etc/package-x/package-x.conf
# Push our own config up there
/etc/package-x/package-x.conf:
file.managed:
- source: salt://roles/package-x/package-x.conf
- user: root
- group: root
- mode: 644
Steps to Reproduce Issue
Initial run
salt:/srv/salt# salt $HOSTNAME state.apply roles/package-x
salt:
----------
ID: /etc/package-x/package-x.conf.example
Function: file.rename
Result: True
Comment: Moved "/etc/package-x/package-x.conf" to "/etc/package-x/package-x.conf.example"
Started: 15:34:37.288072
Duration: 0.507 ms
Changes:
----------
/etc/package-x/package-x.conf.example:
/etc/package-x/package-x.conf
----------
ID: /etc/package-x/package-x.conf
Function: file.managed
Result: True
Comment: File /etc/package-x/package-x.conf updated
Started: 15:34:37.288700
Duration: 22.224 ms
Changes:
----------
diff:
New file
mode:
0644
Summary for salt
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2
Total run time: 22.731 ms
-------------------------------------------
Summary
-------------------------------------------
# of minions targeted: 1
# of minions returned: 1
# of minions that did not return: 0
# of minions with errors: 0
-------------------------------------------
salt:/srv/salt#
next run
salt:/srv/salt# salt $HOSTNAME state.apply roles/package-x
salt:
----------
ID: /etc/package-x/package-x.conf.example
Function: file.rename
Result: False
Comment: The target file "/etc/package-x/package-x.conf.example" exists and will not be overwritten
Started: 15:35:23.268438
Duration: 0.567 ms
Changes:
----------
ID: /etc/package-x/package-x.conf
Function: file.managed
Result: True
Comment: File /etc/package-x/package-x.conf is in the correct state
Started: 15:35:23.269182
Duration: 17.892 ms
Changes:
Summary for salt
------------
Succeeded: 1
Failed: 1
------------
Total states run: 2
Total run time: 18.459 ms
-------------------------------------------
Summary
-------------------------------------------
# of minions targeted: 1
# of minions returned: 1
# of minions that did not return: 0
# of minions with errors: 1
-------------------------------------------
ERROR: Minions returned with non-zero exit code
salt:/srv/salt#
Versions Report
salt:/srv/salt# salt --versions-report
Salt Version:
Salt: 2018.3.2
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.5 (default, Jul 13 2018, 13:06:57)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: centos 7.5.1804 Core
locale: UTF-8
machine: x86_64
release: 4.18.7-1.el7.elrepo.x86_64
system: Linux
version: CentOS Linux 7.5.1804 Core
salt:/srv/salt#
Metadata
Metadata
Assignees
Labels
P4Priority 4bugbroken, incorrect, or confusing behaviorfixed-pls-verifyfix is linked, bug author to confirm fixseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around
Activity
DickerDackel commentedon Sep 22, 2018
Addendum: file.copy behaves as expected, an already existing version is not a failure but returns success:
So, using file.copy is a proper workaround, but still file.rename should behave consistently.
MTecknology commentedon Sep 23, 2018
So, without
- force: true, file.rename should report similar tofile.copywithThe target file "/foo" exists and will not be overwritten, yeah? I have to agree, this seems logical. I suspect it's an easy patch that I could try to look into, unless you'd like to take a stab at it.Ch3LL commentedon Sep 24, 2018
im not able to replicate this on 2018.3.2 with this state:
on the second run i see:
When you pasted your salt version it looks like that is the version on your master. What is your minion version?
DickerDackel commentedon Sep 24, 2018
As shown in the top commandline of my test case: I used the master's own '$HOSTNAME', so basically that was a localhost test.
Edit: What I wanted to say: Master Version == Minion Version, since that's been the same host.
Your test case is incomplete though.
You're only moving the file out of the way, but if you replace the initial filename with a new one in a following file.managed state, that should trigger the issue. See the file.managed state in my sls on top.
Ch3LL commentedon Sep 28, 2018
thanks for clarifying that. I used your exact state and can now replicate it and I agree this should be reporting success. will label as a bug thanks :) as @MTecknology stated this should be an easy fix if you want to give it a go
DickerDackel commentedon Sep 29, 2018
Sure, just wanted to make sure in advance, that my expectation was indeed correct.
I'll take a look.
DickerDackel commentedon Sep 30, 2018
I'm reading your "Contributing" documentation right now, but that fix is so trivial, that a git pull request feels massively overkill for me, so here's a context diff.
I think the return ret['comment'] is fine, so the only thing that's changed is the removal of the False return value (ret['result'] is initialized on top of the function with True).
damon-atkins commentedon Oct 1, 2018
Mmm this is a behavior change. Someone might rely on the fact it errors. Another option is to add a
failhardoption for your use case.MTecknology commentedon Oct 1, 2018
Yes, this is a behavior change, but this discussion shows that the previous behavior was unexpected. The use case presented here seems substantially more likely than a use case that expects a failure in this situation.
This change makes the behavior between
file.copyandfile.renamematch, as seen in the below unit tests.file.copy:
file.rename: