[Pkg-puppet-devel] Bug#529555: [Puppet] onlyif + unless precedence => No, an AND relationship. To close.

Jayen jayenashar at gmail.com
Thu Sep 4 23:23:09 UTC 2014


Thank you Joseph for your reply.  The issue is apparent in test case 4: 
no link and no file:

********************************************************************
$ rm -f /tmp/myfile
# ensures the target path does not exist
$ test -L /tmp/myfile
# ====> 1
$ stat -L /tmp/myfile
stat: cannot stat ‘/tmp/myfile’: No such file or directory
# ====> 1
$ puppet apply -e "exec { 'rm /tmp/myfile': onlyif => 'test -L
/tmp/myfile', unless => 'stat -L /tmp/myfile', path =>
'/usr/bin:/usr/sbin:/bin'; }"
Notice: Compiled catalog for eeyore.com in environment production in 
0.05 seconds
Error: /Stage[main]/Main/Exec[rm /tmp/myfile]: Could not evaluate: sh: 
line 1: /tmp/myfile: No such file or directory

Notice: Finished catalog run in 0.30 seconds
************************************************************************

It appears that puppet ran 'rm' even though the 'onlyif' condition is 
not met.  As you say, an AND relation is expected so the 'rm' should not 
have been executed.

Thanks,
Jayen

P.S. this issue only refers to symbolic links.  hard links are not 
detected with `test -L`

On 05/09/14 06:51, Joseph Herlant wrote:
> Control: tags 529555 = unreproducible
> Package: puppet
> Version: 3.6.1-1
>
> Hi Jayen,
>
> I just tested on a puppet 3.6.1-1 package, but I think the main issue
> comes from a misunderstanding of how things work there.
>
> As you said you were trying to remove a symbolic or hard link (`test
> -L /usr/share/man/man1/x-window-manager.1.gz` tests if it's a link) if
> it were broken (the underlying file did not exists, so `stat -L
> /usr/share/man/man1/x-window-manager.1.gz` wouldn't return 0).
>
> It's a AND relation, there's no precedence story.
> That means that the file would be removed if and only if:
> `test -L /usr/share/man/man1/x-window-manager.1.gz` return code = 0
> AND
> `stat -L /usr/share/man/man1/x-window-manager.1.gz` return code != 0.
>
> To make things more clear, you'l find bellow the possible combinations
> and tests that reproduce the behavior. It is no (or no more) issue
> there as you can see:
>
> *********************** Test case 1: symbolic link with existing file
> as target (so 'unless' condition is not met) ***********************
> echo 'A text' > /tmp/myfile.orig
> ln -s /tmp/myfile.orig /tmp/myfile
> test -L /tmp/myfile
> echo $?
> # =====> 0
> stat -L /tmp/myfile
> echo $?
> # =====> 0
> puppet apply -e "exec { 'rm /tmp/myfile': onlyif => 'test -L
> /tmp/myfile', unless => 'stat -L /tmp/myfile', path =>
> '/usr/bin:/usr/sbin:/bin'; }"
> ll /tmp/myfile
> # =====> Symbolic link is still here as it should be
> *********************** End of test case 1 ***********************
>
> *********************** Test case 2: symlink with a non-existing
> target => symlink should be removed as both 'onlyif' and 'unless'
> conditions are met ***********************
> rm /tmp/myfile.orig
> ln -s /tmp/myfile.orig /tmp/myfile
> test -L /tmp/myfile
> echo $?
> # =====> 0
> stat -L /tmp/myfile
> echo $?
> # =====> 1
> puppet apply -e "exec { 'rm /tmp/myfile': onlyif => 'test -L
> /tmp/myfile', unless => 'stat -L /tmp/myfile', path =>
> '/usr/bin:/usr/sbin:/bin'; }"
> ll /tmp/myfile
> # =====> Symbolic link has been dropped as it should be
> *********************** End of test case 2 ***********************
>
>
> *********************** Test case 3: file is not a link, just a real
> file => should not be removed as none of the 'onlyif' and 'unless'
> conditions are met ***********************
> echo 'A text' > /tmp/myfile
> test -L /tmp/myfile
> echo $?
> # =====> 1
> stat -L /tmp/myfile
> echo $?
> # =====> 0
> puppet apply -e "exec { 'rm /tmp/myfile': onlyif => 'test -L
> /tmp/myfile', unless => 'stat -L /tmp/myfile', path =>
> '/usr/bin:/usr/sbin:/bin'; }"
> ll /tmp/myfile
> # =====> File  is still here as it should be
> *********************** End of test case 3 ***********************
>
> The last combination would mean that it's not a (sym/hard) link and
> that the target does not exists, so the 'onlyif' condition won't be
> met. But I don't know how that can happen.
>
> If you're ok with this, please close the bug sending a mail to:
> 529555-done at bugs.debian.org (for more details about closing bugs,
> please see this: https://www.debian.org/Bugs/Developer#closing)
>
> Best,
> Joseph
>



More information about the Pkg-puppet-devel mailing list