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

Joseph Herlant herlantj at gmail.com
Thu Sep 4 20:51:44 UTC 2014


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