Non existing file source leads to Traceback #832

Closed
syphernl opened this Issue Mar 4, 2012 · 10 comments

Comments

Projects
None yet
4 participants
Contributor

syphernl commented Mar 4, 2012

When trying to copy (and replace variables) a nonexistant file this leads to:
State: - file Name: /etc/apache2/sites-available/example.com.conf Function: managed Result: False Comment: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 237, in _jinja if open(sfn, 'rb').read().endswith('\n'): IOError: [Errno 2] No such file or directory: '' Changes:

This should check whether the file exists and otherwise gracefully fail, instead of generating traceback.

Owner

thatch45 commented Mar 4, 2012

Thanks frank, this is off of git head right?

Contributor

syphernl commented Mar 4, 2012

Yes, its from git head.

@dcolish dcolish added a commit to dcolish/salt that referenced this issue Mar 5, 2012

@dcolish dcolish Issue #832, check source state files exist before rendering.
Bonus removal of call to globals.
9f97cd1

@thatch45 thatch45 added a commit that referenced this issue Mar 5, 2012

@thatch45 thatch45 Merge pull request #839 from dcolish/develop
Issue #832, check source state files exist before rendering.
85365da
Member

dcolish commented Mar 8, 2012

@syphernl is this safe to close now?

Member

SEJeff commented Mar 9, 2012

@dcolish Ok so with the latest git, I tried to reproduce this issue. The good news is that there is no longer a traceback. The bad news is that it doesn't appear to print any sort of error message. Extra whitespace added for readability

root@desktopmonster:/srv/salt# salt-call state.highstate
[INFO    ] Loading fresh modules for state activity
[INFO    ] Loading fresh modules for state activity
[INFO    ] Executing state file.managed for /tmp/date.txt
[INFO    ] File changed:
New file
local:
----------
    State: - file
    Name:      /tmp/date.txt
    Function:  managed
        Result:    True
        Comment:   File /tmp/date.txt updated
        Changes:   diff: New file

root@desktopmonster:/srv/salt# cat /tmp/date.txt 
Thu Mar  8 17:30:21 PST 2012

root@desktopmonster:/srv/salt# ls
basic.sls  basic-two.sls  timestamp.txt  top.sls

root@desktopmonster:/srv/salt# rm timestamp.txt 

root@desktopmonster:/srv/salt# salt-call state.highstate
[INFO    ] Loading fresh modules for state activity
[INFO    ] Loading fresh modules for state activity
[INFO    ] Executing state file.managed for /tmp/date.txt
[INFO    ] No changes made for /tmp/date.txt
local:

root@desktopmonster:/srv/salt# rm /tmp/date.txt 

root@desktopmonster:/srv/salt# salt-call state.highstate
[INFO    ] Loading fresh modules for state activity
[INFO    ] Loading fresh modules for state activity
[INFO    ] Executing state file.managed for /tmp/date.txt
[INFO    ] No changes made for /tmp/date.txt
local:

root@desktopmonster:/srv/salt# cat top.sls 
base:
  '*':
    - basic
root@desktopmonster:/srv/salt# cat basic.sls 
/tmp/date.txt:
  file:
    - managed
    - source: salt://timestamp.txt

root@desktopmonster:/srv/salt# ls timestamp.txt
ls: cannot access timestamp.txt: No such file or directory
Member

dcolish commented Mar 9, 2012

Ok, it looks like we're swallowing the source file missing error. I'll have to trace through and see why.

Member

dcolish commented Mar 9, 2012

@SEJeff Is there anything in your minion log?

Member

dcolish commented Mar 9, 2012

Ok, one thing I noticed is that the code path I added the check to was for templated files only.

Member

SEJeff commented Mar 9, 2012

Yeah thats a fun gotcha. I'll test this out tonight or (more likely) tomorrow.

Owner

thatch45 commented Mar 9, 2012

Thanks Dan, this is all great stuff, and thanks for finding that comma!

Member

dcolish commented Mar 11, 2012

@thatch45 close me

thatch45 closed this Mar 11, 2012

@whiteinge whiteinge pushed a commit to whiteinge/salt that referenced this issue Nov 8, 2013

@techhat techhat Merge pull request #832 from pabelanger/temp/openstack_networks
Create networks sections for OpenStack provider
5df0d4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment