use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(update_some_files create_many_files check_multiple_copies
- update_client $HOST $BASEPORT
+ update_client $HOST $BASEPORT add_to_backup_list check_volume_size
+ check_min_volume_size check_max_volume_size $estat $bstat $rstat $zstat
$cwd $bin $scripts $conf $rscripts $tmp $working
$db_name $db_user $db_password $src $tmpsrc);
use File::Copy qw/copy/;
-our ($cwd, $bin, $scripts, $conf, $rscripts, $tmp, $working,
+our ($cwd, $bin, $scripts, $conf, $rscripts, $tmp, $working, $estat, $bstat, $zstat, $rstat,
$db_name, $db_user, $db_password, $src, $tmpsrc, $HOST, $BASEPORT);
+END {
+ if ($estat || $rstat || $zstat || $bstat) {
+ exit 1;
+ }
+}
+
BEGIN {
# start by loading the ./config file
my ($envar, $enval);
$ENV{rscripts} = $rscripts = $ENV{rscripts} || "$cwd/scripts";
$ENV{HOST} = $HOST = $ENV{HOST} || "localhost";
$ENV{BASEPORT} = $BASEPORT = $ENV{BASEPORT} || "8101";
+
+ $estat = $rstat = $bstat = $zstat = 0;
+}
+
+sub check_min_volume_size
+{
+ my ($size, @vol) = @_;
+ my $ret=0;
+
+ foreach my $v (@vol) {
+ if (! -f "$tmp/$v") {
+ print "ERR: $tmp/$v not accessible\n";
+ $ret++;
+ next;
+ }
+ if (-s "$tmp/$v" < $size) {
+ print "ERR: $tmp/$v too small\n";
+ $ret++;
+ }
+ }
+ $estat+=$ret;
+ return $ret;
+}
+
+sub check_max_volume_size
+{
+ my ($size, @vol) = @_;
+ my $ret=0;
+
+ foreach my $v (@vol) {
+ if (! -f "$tmp/$v") {
+ print "ERR: $tmp/$v not accessible\n";
+ $ret++;
+ next;
+ }
+ if (-s "$tmp/$v" > $size) {
+ print "ERR: $tmp/$v too big\n";
+ $ret++;
+ }
+ }
+ $estat+=$ret;
+ return $ret;
+}
+
+sub add_to_backup_list
+{
+ open(FP, ">>$tmp/file-list") or die "Can't open $tmp/file-list for update $!";
+ print FP join("\n", @_);
+ close(FP);
}
# update client definition for the current test
#
#
TestName="action-on-purge-test"
-JobName=AOP
+JobName=FIFOTest
. scripts/functions
cwd=`pwd`
scripts/copy-test-confs
echo $src > $tmp/file-list
+
sed 's/Pool Type = Backup/Pool Type = Backup; ActionOnPurge = Truncate/' $conf/bacula-dir.conf > $tmp/1
cp $tmp/1 $conf/bacula-dir.conf
-change_jobname CompressedTest $JobName
start_test
cat >tmp/bconcmds <<END_OF_DATA
messages
@$out $tmp/log1.out
label storage=File volume=TestVolume001
-label storage=File volume=TestVolume002
+@########################################################
+@# Run a first job on TestVolume001
+@########################################################
run level=full job=$JobName yes
wait
messages
-@$out $tmp/log2.out
-restore where=${cwd}/tmp/bacula-restores select all storage=File done
-yes
-wait
-messages
+@#@$out $tmp/log2.out
+@#restore where=${cwd}/tmp/bacula-restores select all storage=File done
+@#yes
+@#wait
+@#messages
@#########################################################
@# Run a second job on TestVolume002
@#########################################################
@$out $tmp/log3.out
+label storage=File volume=TestVolume002
update volume=TestVolume001 volstatus=Used
messages
show pool
wait
messages
@#########################################################
-@# Test ActionOnPurge=Truncate Volume size should be small
+@# Run a 3th job on TestVolume003
@#########################################################
-purge volume=TestVolume001
+@$out $tmp/log3.out
+update volume=TestVolume002 volstatus=Used
+label storage=File volume=TestVolume003
+messages
+show pool
+@$out $tmp/log1.out
+run level=full job=$JobName yes
+wait
+messages
+@#########################################################
+@# Run a 4th job
@#########################################################
-@# Test ActionOnPurge=Truncate, then update it to None
-@# Volume size should be normal
+@$out $tmp/log5.out
+update volume=TestVolume003 volstatus=Used
+label storage=File volume=TestVolume004
+messages
+@$out $tmp/log1.out
+run level=full job=$JobName yes
+wait
+messages
+list volume
+@$out $tmp/log1.out
+update volume=TestVolume004 volstatus=Used
+label storage=File volume=TestVolume005
+run level=full job=$JobName yes
+wait
+messages
+@$out $tmp/log6.out
+@#########################################################
+@# tests
@#########################################################
update volume=TestVolume002 actiononpurge=none
+purge volume=TestVolume001
purge volume=TestVolume002
+purge volume=TestVolume003
+purge volume=TestVolume004
+list volume
+sql
+select VolumeName, VolStatus, ActionOnPurge FROM Media;
+
+setdebug level=100 director
+quit
+END_OF_DATA
+
+run_bacula
+check_for_zombie_jobs storage=File
+
+print_debug "Check all media"
+perl -Mscripts::functions -e 'foreach $i (1..5){check_min_volume_size(4096,"TestVolume00$i")}'
+
+if [ $? != 0 ]; then
+ print_debug `ls -l $tmp`
+ print_debug "Initialization problem"
+ estat=2
+fi
+
+echo "purge volume=TestVolume001 action storage=File" > $tmp/bconcmds
+run_bconsole
+
+perl -Mscripts::functions -e '
+check_min_volume_size(4096, "TestVolume002","TestVolume003","TestVolume004","TestVolume005");
+check_max_volume_size(4096, "TestVolume001")'
+
+if [ $? != 0 ]; then
+ print_debug `ls -l $tmp`
+ ls -l $tmp
+ estat=2
+fi
+
+echo "purge volume action storage=File" > $tmp/bconcmds
+run_bconsole
+
+perl -Mscripts::functions -e '
+check_min_volume_size(4096, "TestVolume002", "TestVolume005");
+check_max_volume_size(4096, "TestVolume001", "TestVolume003", "TestVolume004")'
+
+if [ $? != 0 ]; then
+ print_debug `ls -l $tmp`
+ ls -l $tmp
+ estat=2
+fi
+
+
+cat <<END_OF_DATA > $tmp/bconcmds
@#########################################################
@# Display catalog settings for Pool and Media
@#########################################################
@$out $tmp/log4.out
+setdebug level=0 director
sql
select VolumeName, ActionOnPurge FROM Media;
select Name, ActionOnPurge FROM Pool;
+wait
quit
END_OF_DATA
-run_bacula
-check_for_zombie_jobs storage=File
+run_bconsole
+
stop_bacula
+touch $tmp/log2.out
check_two_logs
-check_restore_diff
-
-perl -e "die 'Volume size too big' if (-s '$tmp/TestVolume001' > 4096)"
-if [ $? != 0 ]; then
- print_debug `ls -l $tmp/TestVolume001`
- bstat=2
-fi
-
-perl -e "die 'Volume size too small' if (-s '$tmp/TestVolume002' < 4096)"
-if [ $? != 0 ]; then
- print_debug `ls -l $tmp/TestVolume002`
- bstat=2
-fi
print_debug "Test if Pool record is ok"
r=`awk '/Default/ { print $4 }' $tmp/log4.out`
if [ "$r" != 1 ]; then
- print_debug "ActionOnPurge on Pool record should be 1"
- bstat=2
+ print_debug "ActionOnPurge on Pool record should be 1 ($r)"
+ estat=2
fi
print_debug "Test TestVolume001 if Media record is ok"
r=`awk '/TestVolume001/ { print $4 }' $tmp/log4.out`
if [ "$r" != 1 ]; then
print_debug "ActionOnPurge on Media record should be 1"
- bstat=2
+ estat=2
fi
print_debug "Test TestVolume002 if Media record is ok"
r=`awk '/TestVolume002/ { print $4 }' $tmp/log4.out`
if [ "$r" != 0 ]; then
print_debug "ActionOnPurge on Media record should be 0"
- bstat=2
+ estat=2
fi
end_test