From d23fff895b271ad7c814b4e24e64847ee156a7ac Mon Sep 17 00:00:00 2001 From: Michal Rakowski Date: Tue, 1 Dec 2020 14:31:32 +0100 Subject: [PATCH] regress: Update bscan's restore/plugin objects tests to check for duplicates --- regress/tests/bscan-plugin-objects-test | 33 +++++++++++++++++++ regress/tests/bscan-restore-objects-test | 40 ++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/regress/tests/bscan-plugin-objects-test b/regress/tests/bscan-plugin-objects-test index 79c217cbb..02a6de6b0 100755 --- a/regress/tests/bscan-plugin-objects-test +++ b/regress/tests/bscan-plugin-objects-test @@ -38,11 +38,18 @@ status client=$CLIENT messages @$out ${cwd}/tmp/log2.out list objects +sql +@$out $tmp/objs_count +select count(*) from restoreobject; + quit END_OF_DATA run_bacula +# See how many plugin objects were created in the first place +objs_orig=`cat tmp/objs_count | grep '|' | cut -d'|' -f2 | tail -1` + vm_objects_orig=`cat ${cwd}/tmp/log2.out | grep 'VMWare' | wc -l` if [ ${vm_objects_orig} -ne 2 ]; then estat=1 @@ -118,5 +125,31 @@ if [ ${objects_lines} -ne ${db_objects_orig} ]; then print_debug "Wrong plugin objects count found in output: ${objects_lines}, expected ${db_objects_orig}" fi +# Check if running bscan once more won't create any duplicates +if test "$debug" -eq 1 ; then + $bin/bscan -w working $BSCANLIBDBI -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp +else + $bin/bscan -w working $BSCANLIBDBI -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp >tmp/log6.out 2>&1 +fi + +cat <${cwd}/tmp/bconcmds +sql +@$out $tmp/objs_count_double_bscan +select count(*) from restoreobject; + +quit +quit +END_OF_DATA + +run_bconsole + +# Check if there are no duplicates +objs_after_bscan=`cat tmp/objs_count_double_bscan | grep '|' | cut -d'|' -f2 | tail -1` +if [ $objs_after_bscan -ne ${objs_orig} ]; then + print_debug "ERROR: Running bscan twice produced some duplicates of plugin objects. \ + Original count: ${objs_orig}, after second bscan: ${objs_after_bscan}" + bstat=1 +fi + stop_bacula end_test diff --git a/regress/tests/bscan-restore-objects-test b/regress/tests/bscan-restore-objects-test index 33f2dc841..0b941203a 100755 --- a/regress/tests/bscan-restore-objects-test +++ b/regress/tests/bscan-restore-objects-test @@ -41,10 +41,18 @@ cat <${cwd}/tmp/bconcmds list jobs @$out $tmp/list llist pluginrestoreconf jobid=1 +sql +@$out $tmp/robjs_count +select count(*) from restoreobject; + +quit END_OF_DATA run_bconsole +# See how many restore objects were created in the first place +robjs_orig=`cat tmp/robjs_count | grep '|' | cut -d'|' -f2 | tail -1` + nb=`grep $file $tmp/list | wc -l` if [ $nb -ne 1 ]; then print_debug "ERROR: Should find the RestoreObject for $file in $tmp/list" @@ -66,6 +74,7 @@ messages purge volume=TestVolume001 @$out ${cwd}/tmp/log4.out list objects +quit END_OF_DATA run_bconsole @@ -75,6 +84,7 @@ cat <${cwd}/tmp/bconcmds list jobs @$out $tmp/list_after_purge llist pluginrestoreconf jobid=1 +quit END_OF_DATA run_bconsole @@ -114,6 +124,7 @@ fi cat <${cwd}/tmp/bconcmds @$out tmp/list_job_after_bscan list jobs +quit END_OF_DATA run_bconsole @@ -125,6 +136,7 @@ fi cat <${cwd}/tmp/bconcmds @$out $tmp/list_after_bscan llist pluginrestoreconf jobid=$newJobId +quit END_OF_DATA run_bconsole @@ -142,6 +154,34 @@ if [ $nb -ne 1 ]; then fi run_bconsole + +# Check for bug #7098 +# Check if running bscan once more won't create any duplicates +if test "$debug" -eq 1 ; then + $bin/bscan -w working $BSCANLIBDBI -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp +else + $bin/bscan -w working $BSCANLIBDBI -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp >tmp/log6.out 2>&1 +fi + +cat <${cwd}/tmp/bconcmds +sql +@$out $tmp/robjs_count_double_bscan +select count(*) from restoreobject; + +quit +quit +END_OF_DATA + +run_bconsole + +# Check if there are no duplicates +robjs_after_bscan=`cat tmp/robjs_count_double_bscan | grep '|' | cut -d'|' -f2 | tail -1` +if [ $robjs_after_bscan -ne ${robjs_orig} ]; then + print_debug "ERROR: Running bscan twice produced some duplicates of restore objects. \ + Original count: ${robjs_orig}, after second bscan: ${robjs_after_bscan}" + bstat=1 +fi + stop_bacula end_test -- 2.47.3