]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-13-NSPAWN: move disk images to /var/tmp
authorRichard Maw <richard.maw@codethink.co.uk>
Tue, 13 Feb 2024 12:48:26 +0000 (12:48 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 Apr 2024 20:10:02 +0000 (22:10 +0200)
/tmp may not be large enough to contain disk images
and will result in strange errors when it runs out of space.

test/TEST-13-NSPAWN/test.sh
test/test-functions
test/units/testsuite-13.machinectl.sh
test/units/testsuite-13.nspawn-oci.sh
test/units/testsuite-13.nspawn.sh
test/units/testsuite-13.nss-mymachines.sh

index 915f2db86bc7f67e3ffb760741c0d3b8454415ca..744e793ac2e8008401c338452331319a0db17fde 100755 (executable)
@@ -5,6 +5,8 @@ set -e
 TEST_DESCRIPTION="systemd-nspawn tests"
 IMAGE_NAME="nspawn"
 TEST_NO_NSPAWN=1
+IMAGE_ADDITIONAL_ROOT_SIZE=500
+TEST_FORCE_NEWIMAGE=1
 
 # shellcheck source=test/test-functions
 . "${TEST_BASE_DIR:?}/test-functions"
index 59242b3569f017f6d9c24b62063b0fd9a2e5dd3a..10ea6ef03a127f3f859fa44d62cdfd222789cf54 100644 (file)
@@ -476,8 +476,7 @@ run_qemu() {
 
     local CONSOLE=ttyS0
 
-    # Reset the boot counter, if present
-    rm -f "${initdir:?}/var/tmp/.systemd_reboot_count"
+    find "${initdir:?}/var/tmp" -mindepth 1 -delete
     rm -f "$initdir"/{testok,failed,skipped}
     # make sure the initdir is not mounted to avoid concurrent access
     cleanup_initdir
@@ -651,8 +650,7 @@ run_qemu() {
 # success), or 1 if nspawn is not available.
 run_nspawn() {
     [[ -d /run/systemd/system ]] || return 1
-    # Reset the boot counter, if present
-    rm -f "${initdir:?}/var/tmp/.systemd_reboot_count"
+    find "${initdir:?}/var/tmp" -mindepth 1 -delete
     rm -f "${initdir:?}"/{testok,failed,skipped}
 
     local nspawn_cmd=()
index c3bfde276873da70ca31150c530795db7c84fa48..6e2ad165bd2884d00a1297f41422831be2feaa30 100755 (executable)
@@ -23,9 +23,9 @@ trap at_exit EXIT
 systemctl service-log-level systemd-machined debug
 systemctl service-log-level systemd-importd debug
 
-# Mount tmpfs over /var/lib/machines to not pollute the image
+# Mount temporary directory over /var/lib/machines to not pollute the image
 mkdir -p /var/lib/machines
-mount -t tmpfs tmpfs /var/lib/machines
+mount --bind "$(mktemp --tmpdir=/var/tmp -d)" /var/lib/machines
 
 # Create a couple of containers we can refer to in tests
 for i in {0..4}; do
@@ -154,37 +154,37 @@ test ! -d /var/lib/machines/.hidden1
 
 # Prepare a simple raw container
 mkdir -p /tmp/mnt
-dd if=/dev/zero of=/tmp/container.raw bs=1M count=64
-mkfs.ext4 /tmp/container.raw
-mount -o loop /tmp/container.raw /tmp/mnt
+dd if=/dev/zero of=/var/tmp/container.raw bs=1M count=256
+mkfs.ext4 /var/tmp/container.raw
+mount -o loop /var/tmp/container.raw /tmp/mnt
 cp -r /var/lib/machines/container1/* /tmp/mnt
 umount /tmp/mnt
 # Try to import it, run it, export it, and re-import it
-machinectl import-raw /tmp/container.raw container-raw
+machinectl import-raw /var/tmp/container.raw container-raw
 [[ "$(machinectl show-image --property=Type --value container-raw)" == "raw" ]]
 machinectl start container-raw
-machinectl export-raw container-raw /tmp/container-export.raw
-machinectl import-raw /tmp/container-export.raw container-raw-reimport
+machinectl export-raw container-raw /var/tmp/container-export.raw
+machinectl import-raw /var/tmp/container-export.raw container-raw-reimport
 [[ "$(machinectl show-image --property=Type --value container-raw-reimport)" == "raw" ]]
-rm -f /tmp/container{,-export}.raw
+rm -f /var/tmp/container{,-export}.raw
 
 # Prepare a simple tar.gz container
-tar -pczf /tmp/container.tar.gz -C /var/lib/machines/container1 .
+tar -pczf /var/tmp/container.tar.gz -C /var/lib/machines/container1 .
 # Try to import it, run it, export it, and re-import it
-machinectl import-tar /tmp/container.tar.gz container-tar
-[[ "$(machinectl show-image --property=Type --value container-tar)" == "directory" ]]
+machinectl import-tar /var/tmp/container.tar.gz container-tar
+[[ "$(machinectl show-image --property=Type --value container-tar)" =~ directory|subvolume ]]
 machinectl start container-tar
-machinectl export-tar container-tar /tmp/container-export.tar.gz
-machinectl import-tar /tmp/container-export.tar.gz container-tar-reimport
-[[ "$(machinectl show-image --property=Type --value container-tar-reimport)" == "directory" ]]
-rm -f /tmp/container{,-export}.tar.gz
+machinectl export-tar container-tar /var/tmp/container-export.tar.gz
+machinectl import-tar /var/tmp/container-export.tar.gz container-tar-reimport
+[[ "$(machinectl show-image --property=Type --value container-tar-reimport)" =~ directory|subvolume ]]
+rm -f /var/tmp/container{,-export}.tar.gz
 
 # Try to import a container directory & run it
-cp -r /var/lib/machines/container1 /tmp/container.dir
-machinectl import-fs /tmp/container.dir container-dir
-[[ "$(machinectl show-image --property=Type --value container-dir)" == "directory" ]]
+cp -r /var/lib/machines/container1 /var/tmp/container.dir
+machinectl import-fs /var/tmp/container.dir container-dir
+[[ "$(machinectl show-image --property=Type --value container-dir)" =~ directory|subvolume ]]
 machinectl start container-dir
-rm -fr /tmp/container.dir
+rm -fr /var/tmp/container.dir
 
 timeout 10 bash -c "until machinectl clean --all; do sleep .5; done"
 
index 8fa0bc4290f7e22460780459e52f6a2e20fb9235..b8a76fa17226014f7f87025412f8aa59dffb5461 100755 (executable)
@@ -23,9 +23,9 @@ at_exit() {
 
 trap at_exit EXIT
 
-# Mount tmpfs over /var/lib/machines to not pollute the image
+# Mount temporary directory over /var/lib/machines to not pollute the image
 mkdir -p /var/lib/machines
-mount -t tmpfs tmpfs /var/lib/machines
+mount --bind "$(mktemp --tmpdir=/var/tmp -d)" /var/lib/machines
 
 # Setup a couple of dirs/devices for the OCI containers
 DEV="$(mktemp -u /dev/oci-dev-XXX)"
index 5b67cf8c7e12b8e27a9d83b9c3cc0b53b9a9458b..026ed23fcd9f2c2631e625f022993d10e32ae2b4 100755 (executable)
@@ -71,9 +71,9 @@ if unshare -U bash -c :; then
     IS_USERNS_SUPPORTED=yes
 fi
 
-# Mount tmpfs over /var/lib/machines to not pollute the image
+# Mount temporary directory over /var/lib/machines to not pollute the image
 mkdir -p /var/lib/machines
-mount -t tmpfs tmpfs /var/lib/machines
+mount --bind "$(mktemp --tmpdir=/var/tmp -d)" /var/lib/machines
 
 testcase_sanity() {
     local template root image uuid tmpdir
@@ -83,7 +83,7 @@ testcase_sanity() {
     create_dummy_container "$template"
     # Create a simple image from the just created container template
     image="$(mktemp /var/lib/machines/testsuite-13.image-XXX.img)"
-    dd if=/dev/zero of="$image" bs=1M count=64
+    dd if=/dev/zero of="$image" bs=1M count=256
     mkfs.ext4 "$image"
     mkdir -p /mnt
     mount -o loop "$image" /mnt
index 931b93f953fd1166635ea720ac67350183a7e108..817431b449ad38ae2cc43bddec4e557b0d3288e2 100755 (executable)
@@ -17,8 +17,9 @@ at_exit() {
 
 trap at_exit EXIT
 
+# Mount temporary directory over /var/lib/machines to not pollute the image
 mkdir -p /var/lib/machines
-mount -t tmpfs tmpfs /var/lib/machines
+mount --bind "$(mktemp --tmpdir=/var/tmp -d)" /var/lib/machines
 
 # Create a bunch of containers that:
 # 1) Have no IP addresses assigned