salt icon indicating copy to clipboard operation
salt copied to clipboard

file.directory clean and exclude_pat

Open je9000 opened this issue 13 years ago • 7 comments

I'm trying to empty a directory except for a single file placed there by salt. Using this:

etc/rsyslog.d/: file.directory: - clean: True - exclude_pat: 'E@.*10'

It's my understanding this should leave all files that contain "10", but when I run it it removes all files. I added some debugging to _check_include_exclude and it appears the path_str variable has its first character truncated, which causes the match to fail (ie, a file named 10-whatever is passed in as 0-whatever).

I'm not entirely sure I've debugged the problem correctly, but changing my regular expression or pattern to not include the first character I'm trying to match has resolved the issue.

I'm using version 0.16.4.

je9000 avatar Sep 18 '13 07:09 je9000

Looks like @jumping found the problem in his pull req above. Have no idea why that +1 was added, but it should solve your problem perfectly.

basepi avatar Sep 18 '13 16:09 basepi

This just broke excluding files and caused a serious fault in file routines that call clean with files to keep. I had to revert it. I think that the regex being used in the issue may be incorrect

thatch45 avatar Sep 19 '13 06:09 thatch45

We need to figure out why the +1 was added. Looks like it was probably a hack of some sort. Then we can figure out how to fix the problem properly. Reopening this issue.

basepi avatar Sep 19 '13 19:09 basepi

Oh, so I re-read your issue, and the regex that you put in that state is designed to catch anything that ends in 10. You would need to do E@.*10.* to get all matches with 10 anywhere in the match.

I'd be interested to see if this fixes your issue -- can test it? If it's still broken then we'll revisit the +1 issue and figure out how to solve the issue.

basepi avatar Sep 19 '13 19:09 basepi

You're right, that regular expression is incorrect, but I believe the issue still exists. I tried several different patterns (including globs and exact strings) and none worked, but it looks like I picked a bad example to open the issue with. Sorry.

I'm unable to reproduce it locally on my test VM, but on actual hardware with a salt master I see the truncated path_str behavior. Here's some more data:

From my .sls file:

/etc/rsyslog.d/: file.directory: - clean: True - exclude_pat: '10-remote.conf'

salt-call output:

State: - file
Name:      /etc/rsyslog.d/
Function:  directory
    Result:    True
    Comment:   Files cleaned from directory /etc/rsyslog.d/
    Changes:   removed: ['/etc/rsyslog.d/10-remote.conf']

My diff to test the path_str truncation: --- /usr/lib/python2.6/site-packages/salt/states/file.py.old 2013-09-19 20:11:20.051966481 +0000 +++ /usr/lib/python2.6/site-packages/salt/states/file.py 2013-09-19 20:11:13.725073059 +0000 @@ -464,6 +464,7 @@ include_pat matches AND exclude_pat does not match ''' ret = True # -- default true

  • log.warning("Inside _check_include_exclude, path_str is " + path_str + " and exclude_pat is " + exclude_pat);

Before pattern match, check if it is regexp (E@'') or glob(default)

if include_pat: if re.match('E@', include_pat):

And then the output from my modification:

[WARNING ] Inside _check_include_exclude, path_str is 0-remote.conf and exclude_pat is 10-remote.conf

Again I was unable to reproduce this on my test VM but the issue did hit my development servers and prod servers, but I can't explain why. Everything is using Salt 0.16.4, but the VM doesn't have a master server, it's all run off local files.

je9000 avatar Sep 19 '13 20:09 je9000

I think I might know where this is. Sometimes we add a pipe (|) to the path to signal to salt to escape any question mark arguments in the path name. My guess is that somewhere we're trying to remove the pipe when it's not actually there. We should be able to track it down without too much trouble.

basepi avatar Sep 19 '13 20:09 basepi

I can no longer replicate this on develop. Given a directory with '10clean', 'clean' and 'dirty' I have tested the following exclude_pat strings and all exclude properly: 'E@1.*lean' : Deletes clean and dirty 'clean': Preserves 'clean'. Deletes '10clean' and 'dirty' 'lean': Deletes all three files.

Because I can't replicate this scenario, I expect that it's been fixed. I'm going to close this issue as resolved. If it pops up again, feel free to leave a comment and we'll re-open it. Thanks.

cachedout avatar Jun 06 '14 22:06 cachedout