Gregory Matthews writes:
Can someone answer the following question:
does the cfengine "tidy" promise cross file systems?
Hi Greg,
Per the documentation for the depth_search
body xdev
, Description: true/false exclude directories that are on different devices
and the attribute is False by default. So, I would not expect the agent to traverse file systems if xdev
is not explicitly used.
If a file system is mounted inside a directory that is subject to a "tidy" promise, is it recursed into?
It should unless xdev
is true, as in the case of depth_search recurse(d)
from the stdlib:
cf-locate -f -p "depth_search recurse\(d\)"
body depth_search recurse(d) # @brief Search files and direcories recursively, up to the specified depth # Directories on different devices are included. # # @param d The maximum search depth { depth => "$(d)"; xdev => "true"; }
But, it's good to test things:
bundle agent test_xdev_init { files: "/tmp/xdev-device-test-tree/subdir1/stuff/file" create => "true", comment => "a file to test with"; "/tmp/xdev-device-test-tree/subdir/xdev/." create => "true", comment => "We need a directory where we can mount a file system."; } bundle agent test_xdev_device { commands: "dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240" contain => in_shell, unless => fileexists( "/tmp/xdev-device" ), comment => "This file will contain a file system and be mounted to test xdev"; "mkfs.ext3 /tmp/xdev-device" contain => in_shell, comment => "Here we give the device a file system", classes => results( "bundle", "xdev_device_filesystem" ), if => fileexists( "/tmp/xdev-device" ), unless => fileexists( "/tmp/xdev-device.has_filesystem" ); files: xdev_device_filesystem_repaired:: "/tmp/xdev-device.has_filesystem" create => "true"; xdev_device_mount_repaired:: "/tmp/xdev-device.is_mounted" create => "true"; commands: "mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev" classes => results( "bundle", "xdev_device_mount" ), contain => in_shell, unless => fileexists( "/tmp/xdev-device.is_mounted" ); files: "/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev" create => "true", if => fileexists( "/tmp/xdev-device.is_mounted" ); } bundle agent test_xdev { files: "/tmp/xdev-device-test-tree/." depth_search => inf_no_xdev, file_select => plain, delete => tidy, if => fileexists( "/tmp/xdev-device.is_mounted" ); } body depth_search inf_no_xdev { depth => "inf"; xdev => "true"; } bundle agent __main__ { methods: "test_xdev_init"; "test_xdev_device"; "test_xdev"; }
exec 2>&1 test_xdev() { echo "Running test policy with CFEngine $(cf-agent -V | head -n 1)" echo "xdev configuration: " grep "xdev =>" /tmp/test-xdev.cf cf-agent -KIf /tmp/test-xdev.cf # Run wiht -v to see log messages like Skipping 'FILE' on differnt device when xdev is TRUE! test -f /tmp/xdev-device-mountpoint/./subdir/xdev/file-on-xdev && echo "File on another file system exists" test -f /tmp/xdev-device-mountpoint/./subdir/xdev/file-on-xdev || echo "File on another filesystem is abent" echo "Showing mount and file tree after policy run" mount | grep xdev find /tmp/xdev-device-test-tree echo "Cleanup" umount /tmp/xdev-device-test-tree/subdir/xdev/ rm -rf /tmp/xdev-device* echo "DONE\n\n" } sed -i 's/.*xdev =>.*/ #xdev => "false";/g' /tmp/test-xdev.cf test_xdev sed -i 's/.*xdev =>.*/ xdev => "false";/g' /tmp/test-xdev.cf test_xdev sed -i 's/.*xdev =>.*/ xdev => "true";/g' /tmp/test-xdev.cf test_xdev :
Running test policy with CFEngine CFEngine Core 3.17.0 xdev configuration: #xdev => "false"; info: Created directory for '/tmp/xdev-device-test-tree/subdir1/stuff/file' info: Created file '/tmp/xdev-device-test-tree/subdir1/stuff/file', mode 0600 info: files promise '/tmp/xdev-device-test-tree/subdir1/stuff/file' repaired info: Created directory '/tmp/xdev-device-test-tree/subdir/xdev/.' info: files promise '/tmp/xdev-device-test-tree/subdir/xdev' repaired info: Executing 'no timeout' ... 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' notice: Q: "...dd if=/dev/zero": 10240+0 records in Q: "...dd if=/dev/zero": 10240+0 records out Q: "...dd if=/dev/zero": 10485760 bytes (10 MB, 10 MiB) copied, 0.0225902 s, 464 MB/s info: Last 3 quoted lines were generated by promiser 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' info: Completed execution of 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' info: Executing 'no timeout' ... 'mkfs.ext3 /tmp/xdev-device' notice: Q: "...mkfs.ext3 /tmp/": mke2fs 1.45.5 (07-Jan-2020) Q: "...mkfs.ext3 /tmp/": Discarding device blocks: done Q: "...mkfs.ext3 /tmp/": Creating filesystem with 2560 4k blocks and 2560 inodes Q: "...mkfs.ext3 /tmp/": Allocating group tables: 0/1 done Q: "...mkfs.ext3 /tmp/": Writing inode tables: 0/1 done Q: "...mkfs.ext3 /tmp/": Creating journal (1024 blocks): done Q: "...mkfs.ext3 /tmp/": Writing superblocks and filesystem accounting information: 0/1 done info: Last 7 quoted lines were generated by promiser 'mkfs.ext3 /tmp/xdev-device' info: Completed execution of 'mkfs.ext3 /tmp/xdev-device' info: Executing 'no timeout' ... 'mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev' info: Completed execution of 'mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev' info: Created file '/tmp/xdev-device.has_filesystem', mode 0600 info: files promise '/tmp/xdev-device.has_filesystem' repaired info: Created file '/tmp/xdev-device.is_mounted', mode 0600 info: files promise '/tmp/xdev-device.is_mounted' repaired info: Created file '/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev', mode 0600 info: files promise '/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev' repaired info: Deleted file '/tmp/xdev-device-test-tree/./subdir/xdev/file-on-xdev' info: Deleted file '/tmp/xdev-device-test-tree/./subdir1/stuff/file' info: files promise '/tmp/xdev-device-test-tree/.' repaired File on another file system exists File on another filesystem is abent Showing mount and file tree after policy run /tmp/xdev-device on /tmp/xdev-device-test-tree/subdir/xdev type ext3 (rw,relatime) /tmp/xdev-device-test-tree /tmp/xdev-device-test-tree/subdir /tmp/xdev-device-test-tree/subdir/xdev /tmp/xdev-device-test-tree/subdir/xdev/lost+found /tmp/xdev-device-test-tree/subdir1 /tmp/xdev-device-test-tree/subdir1/stuff Cleanup DONE Running test policy with CFEngine CFEngine Core 3.17.0 xdev configuration: xdev => "false"; info: Created directory for '/tmp/xdev-device-test-tree/subdir1/stuff/file' info: Created file '/tmp/xdev-device-test-tree/subdir1/stuff/file', mode 0600 info: files promise '/tmp/xdev-device-test-tree/subdir1/stuff/file' repaired info: Created directory '/tmp/xdev-device-test-tree/subdir/xdev/.' info: files promise '/tmp/xdev-device-test-tree/subdir/xdev' repaired info: Executing 'no timeout' ... 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' notice: Q: "...dd if=/dev/zero": 10240+0 records in Q: "...dd if=/dev/zero": 10240+0 records out Q: "...dd if=/dev/zero": 10485760 bytes (10 MB, 10 MiB) copied, 0.0291186 s, 360 MB/s info: Last 3 quoted lines were generated by promiser 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' info: Completed execution of 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' info: Executing 'no timeout' ... 'mkfs.ext3 /tmp/xdev-device' notice: Q: "...mkfs.ext3 /tmp/": mke2fs 1.45.5 (07-Jan-2020) Q: "...mkfs.ext3 /tmp/": Discarding device blocks: done Q: "...mkfs.ext3 /tmp/": Creating filesystem with 2560 4k blocks and 2560 inodes Q: "...mkfs.ext3 /tmp/": Allocating group tables: 0/1 done Q: "...mkfs.ext3 /tmp/": Writing inode tables: 0/1 done Q: "...mkfs.ext3 /tmp/": Creating journal (1024 blocks): done Q: "...mkfs.ext3 /tmp/": Writing superblocks and filesystem accounting information: 0/1 done info: Last 7 quoted lines were generated by promiser 'mkfs.ext3 /tmp/xdev-device' info: Completed execution of 'mkfs.ext3 /tmp/xdev-device' info: Executing 'no timeout' ... 'mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev' info: Completed execution of 'mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev' info: Created file '/tmp/xdev-device.has_filesystem', mode 0600 info: files promise '/tmp/xdev-device.has_filesystem' repaired info: Created file '/tmp/xdev-device.is_mounted', mode 0600 info: files promise '/tmp/xdev-device.is_mounted' repaired info: Created file '/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev', mode 0600 info: files promise '/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev' repaired info: Deleted file '/tmp/xdev-device-test-tree/./subdir/xdev/file-on-xdev' info: Deleted file '/tmp/xdev-device-test-tree/./subdir1/stuff/file' info: files promise '/tmp/xdev-device-test-tree/.' repaired File on another file system exists File on another filesystem is abent Showing mount and file tree after policy run /tmp/xdev-device on /tmp/xdev-device-test-tree/subdir/xdev type ext3 (rw,relatime) /tmp/xdev-device-test-tree /tmp/xdev-device-test-tree/subdir /tmp/xdev-device-test-tree/subdir/xdev /tmp/xdev-device-test-tree/subdir/xdev/lost+found /tmp/xdev-device-test-tree/subdir1 /tmp/xdev-device-test-tree/subdir1/stuff Cleanup DONE Running test policy with CFEngine CFEngine Core 3.17.0 xdev configuration: xdev => "true"; info: Created directory for '/tmp/xdev-device-test-tree/subdir1/stuff/file' info: Created file '/tmp/xdev-device-test-tree/subdir1/stuff/file', mode 0600 info: files promise '/tmp/xdev-device-test-tree/subdir1/stuff/file' repaired info: Created directory '/tmp/xdev-device-test-tree/subdir/xdev/.' info: files promise '/tmp/xdev-device-test-tree/subdir/xdev' repaired info: Executing 'no timeout' ... 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' notice: Q: "...dd if=/dev/zero": 10240+0 records in Q: "...dd if=/dev/zero": 10240+0 records out Q: "...dd if=/dev/zero": 10485760 bytes (10 MB, 10 MiB) copied, 0.0216883 s, 483 MB/s info: Last 3 quoted lines were generated by promiser 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' info: Completed execution of 'dd if=/dev/zero of=/tmp/xdev-device bs=1024 count=10240' info: Executing 'no timeout' ... 'mkfs.ext3 /tmp/xdev-device' notice: Q: "...mkfs.ext3 /tmp/": mke2fs 1.45.5 (07-Jan-2020) Q: "...mkfs.ext3 /tmp/": Discarding device blocks: done Q: "...mkfs.ext3 /tmp/": Creating filesystem with 2560 4k blocks and 2560 inodes Q: "...mkfs.ext3 /tmp/": Allocating group tables: 0/1 done Q: "...mkfs.ext3 /tmp/": Writing inode tables: 0/1 done Q: "...mkfs.ext3 /tmp/": Creating journal (1024 blocks): done Q: "...mkfs.ext3 /tmp/": Writing superblocks and filesystem accounting information: 0/1 done info: Last 7 quoted lines were generated by promiser 'mkfs.ext3 /tmp/xdev-device' info: Completed execution of 'mkfs.ext3 /tmp/xdev-device' info: Executing 'no timeout' ... 'mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev' info: Completed execution of 'mount /tmp/xdev-device /tmp/xdev-device-test-tree/subdir/xdev' info: Created file '/tmp/xdev-device.has_filesystem', mode 0600 info: files promise '/tmp/xdev-device.has_filesystem' repaired info: Created file '/tmp/xdev-device.is_mounted', mode 0600 info: files promise '/tmp/xdev-device.is_mounted' repaired info: Created file '/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev', mode 0600 info: files promise '/tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev' repaired info: Deleted file '/tmp/xdev-device-test-tree/./subdir1/stuff/file' info: files promise '/tmp/xdev-device-test-tree/.' repaired File on another file system exists File on another filesystem is abent Showing mount and file tree after policy run /tmp/xdev-device on /tmp/xdev-device-test-tree/subdir/xdev type ext3 (rw,relatime) /tmp/xdev-device-test-tree /tmp/xdev-device-test-tree/subdir /tmp/xdev-device-test-tree/subdir/xdev /tmp/xdev-device-test-tree/subdir/xdev/file-on-xdev /tmp/xdev-device-test-tree/subdir/xdev/lost+found /tmp/xdev-device-test-tree/subdir1 /tmp/xdev-device-test-tree/subdir1/stuff Cleanup DONE
So, it seems to be working here
> Per the documentation for the depth_search body xdev, Description: true/false exclude directories that are on different devices and the attribute is False by default. So, I would not expect the agent to traverse file systems if xdev is not explicitly used.
That should say I would expect the agent to traverse the file system unless xdev is set to exclude files from other devices.
xdev
Description: true/false exclude directories that are on different devices
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/87k0sif7zf.fsf%40northern.tech.
--
Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/87k0sif7zf.fsf%40northern.tech.
Aleksey Tsalolikhin writes:
The body "tidy" is defined in the CFEngine Standard Library. You can find it here: https://github.com/cfengine/masterfiles/blob/9750119782ace17cd35c7a2d6b9b8b073ad318e1/lib/files.cf#L1819-L1825
xdev is not defined, so per
https://docs.cfengine.com/docs/3.15/reference-promise-types-files.html#xdev
Note, xdev
is not a valid attribute in a delete body, it's a depth_search
attribute.
exec 2>&1 echo "Valid attribtes for delete bodies (like tidy):" cf-promises --syntax-description json | jq ".bodyTypes.delete.attributes|keys[]" echo "Valid attribtes for depth_search bodies (like recurse):" cf-promises --syntax-description json | jq ".bodyTypes.depth_search.attributes|keys[]" :
Valid attribtes for delete bodies (like tidy): "dirlinks" "inherit_from" "meta" "rmdirs" Valid attribtes for depth_search bodies (like recurse): "depth" "exclude_dirs" "include_basedir" "include_dirs" "inherit_from" "meta" "rmdeadlinks" "traverse_links" "xdev"
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/1remmru2.fsf%40lifelogs.com.
Ted Zlatanov writes:
So this is also incorrect in other place in the stdlib?
For example `body depth_search recurse_with_base` has xdev=true and says it will include other devices.
Ted, thanks for pointing that out!
Indeed, recurse_with_base has xdev true and the inline docs say:
nil
The docs for depth_search recurse also say included.
nil
I believe it is safer to update the documentation than to alter the implementation.
I will update the inline docs for currently maintained branches momentarily.
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/1fd388b4-117d-e61d-6799-d621384c4ca0%40diamond.ac.uk.