]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: add volume-immutable-purged-test
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Thu, 23 Dec 2021 16:13:23 +0000 (17:13 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:57 +0000 (13:56 +0200)
regress/all-vol-append-immutable-tests
regress/tests/volume-immutable-purged-test [new file with mode: 0755]
regress/tests/volume-immutable-test

index 7f2ca9764b46b5e6dde0c29199b70eb7e08cf1e3..966b6b795fab5092a8c76a147a4046eb8c104e7a 100755 (executable)
@@ -10,6 +10,7 @@ echo "Start Append Immutable Volume tests" >>test.out
 ./run tests/volume-append-test
 ./run tests/volume-append-many-vols-test
 ./run tests/volume-immutable-test
+./run tests/volume-immutable-purged-test
 
 echo "End Append Immutable Volume tests "
 echo "End Append Immutable Volume tests" >>test.out
diff --git a/regress/tests/volume-immutable-purged-test b/regress/tests/volume-immutable-purged-test
new file mode 100755 (executable)
index 0000000..1d42a78
--- /dev/null
@@ -0,0 +1,114 @@
+#!/bin/sh
+#
+# Copyright (C) 2000-2021 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# Test for bug #8566 and similar.
+# Test if for purged volumes the Volume Protection Time is respected and no error message is printed during trying
+# to use such volume.
+#
+TestName="volume-immutable-purged-test"
+JobName=append
+
+. scripts/functions
+
+require_linux
+
+scripts/cleanup
+scripts/copy-confs
+
+cleanup()
+{
+   #Stop the daemon if the test was interrupted in the middle of a run
+   sudo systemctl stop test-bacula-sd > /dev/null 2>&1
+   #Disable the service
+   sudo systemctl disable test-bacula-sd
+   #Clear volume attributes if needed
+   sudo chattr -ia tmp/*
+}
+
+trap 'cleanup' EXIT INT TERM
+
+# Create temporary bacula-sd.service file so that we can run SD as systemd service
+scripts/create_sed
+sed -f ${tmp}/sed_tmp ${cwd}/build/platforms/systemd/bacula-sd.service.in > ${tmp}/test-bacula-sd.service
+sudo systemctl enable ${tmp}/test-bacula-sd.service
+
+# Zap out any schedule in default conf file so that
+#  it doesn't start during our test
+outf="$tmp/sed_tmp"
+echo "s%  Schedule =%# Schedule =%g" >${outf}
+cp $scripts/bacula-dir.conf $tmp/1
+sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
+
+change_jobname BackupClient1 $JobName
+
+start_test
+
+# Set small MaxVolSize so that many volumes are created during backup
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumVolumeSize", "50M", "Device", "FileChgr1-Dev1")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumVolumeSize", "50M", "Device", "FileChgr1-Dev2")'
+
+# Set some protection directives
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "SetVolumeAppendOnly", "yes", "Device", "FileChgr1-Dev1")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "SetVolumeAppendOnly", "yes", "Device", "FileChgr1-Dev2")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "SetVolumeImmutable", "yes", "Device", "FileChgr1-Dev1")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "SetVolumeImmutable", "yes", "Device", "FileChgr1-Dev2")'
+
+# Run FD and DIR the usual way, SD has to be run with systemd
+${bin}/bacula-ctl-fd start
+if test $? -ne 0; then
+      print_debug "ERROR: Failed to start the FD!"
+         dstat=1
+fi
+sudo systemctl start test-bacula-sd
+if test $? -ne 0; then
+      print_debug "ERROR: Failed to start the SD!"
+      dstat=1
+fi
+${bin}/bacula-ctl-dir start
+if test $? -ne 0; then
+      print_debug "ERROR: Failed to start the DIR!"
+      dstat=1
+fi
+
+# No volume is created manually before running backup job so that Bacula has to create it by itself
+cat <<END_OF_DATA >$tmp/bconcmds
+@output /dev/null
+messages
+@$out $tmp/log1.out
+run job=$JobName yes
+wait
+messages
+@$out $tmp/log2.out
+list volumes
+purge volume=Vol-0001
+list volumes
+@$out $tmp/log3.out
+run job=$JobName level=Full yes
+wait
+messages
+list volumes
+quit
+END_OF_DATA
+
+run_bconsole
+
+backup_res=`cat $tmp/log1.out| grep 'Termination:' | grep 'Backup OK' | wc -l`
+if [ ${backup_res} -ne 1 ]; then
+   estat=1
+   print_debug "ERROR: JobId 1 did not succed, see ${tmp}/log2.out!"
+fi
+
+# Check if messages about skipping Immutable volumes was logged
+n=`cat $tmp/log3.out| grep "Volume name(s):" | grep "Vol-0003|Vol-0004|Vol-0005" | wc -l`
+if [ ${n} -eq 0 ]; then
+   estat=1
+   print_debug "ERROR: Wrong volumes used for backup, see ${tmp}/log3.out!"
+fi
+
+sudo systemctl stop test-bacula-sd
+${bin}/bacula-ctl-fd stop
+${bin}/bacula-ctl-dir stop
+
+end_test
index 0036cf64ae0f35e2c2032c9389f2a1787d2eead2..10ee8bc0e1e1d6a19f95629a7ec8c379156ee9fe 100755 (executable)
@@ -127,7 +127,7 @@ END_OF_DATA
 run_bconsole
 
 # Check if volume has not been relabeled before expiration time
-label_res=`cat $tmp/log2.out| grep "Immutable flag cannot be cleared for volume: Vol-0001, because Minimum Volume Protection Time hasn't expired yet" | wc -l`
+label_res=`cat $tmp/log2.out| grep "Cannot open Volume Vol-0001 for writing/truncating, because Minimum Volume Protection Time hasn't expired yet" | wc -l`
 if [ ${label_res} -ne 1 ]; then
    estat=1
    print_debug "ERROR: Failed to relabel volume, see ${tmp}/log2.out!"
@@ -137,7 +137,7 @@ fi
 label_res=`cat $tmp/log3.out| grep '3000 OK label' | grep 'RelabeledVol-0001' | wc -l`
 if [ ${label_res} -ne 1 ]; then
    estat=1
-   print_debug "ERROR: Failed to relabel volume, see ${tmp}/log3.out!"
+   print_debug "ERROR: Failed to relabel volume to 'RelabeledVol-0001, see ${tmp}/log3.out!"
 fi
 
 sudo systemctl stop test-bacula-sd