]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport regress/scripts/functions
authorGit Backport Process <git@bacula.org>
Fri, 4 Sep 2020 11:31:47 +0000 (13:31 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:56 +0000 (09:02 +0100)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Jul 21 10:28:13 2020 +0200

    regress: Add copyright to regress scripts

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Sun Jul 5 18:31:55 2020 -0300

    regress: hdfs: changed regress script to automatically install plugin and changed its default user to 'hadoop'

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Jun 30 10:19:16 2020 +0200

    regress: Add FORCE_DOT_STATUS check to reproduce #6472

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Jun 6 16:15:13 2020 +0200

    regress: Small trivial change to check_parts

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Mar 3 14:56:32 2020 +0100

    regress: Avoid to overwrite variables from ./scripts/functions

Author: Norbert Bizet <norbert.bizet@baculasystems.com>
Date:   Mon Dec 16 04:21:33 2019 -0500

    isolate glacier function in a separated dso

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue Oct 29 15:00:44 2019 +0100

    regress: fix dedup 12.2 stuff and rename resource Dedup into Dedupengine

    - rename Dedup resource and directive into Dedupengine
    - fix dedup-old-res-test, the start_test was modifying the dedup stuff
      after "local" modification
    - add dedup-2dde-test that run 2 dedup in //

Author: Alain Spineux <alain@baculasystems.com>
Date:   Thu Oct 24 15:14:12 2019 +0200

    regress: dedup move MaximumContainerSize from Storage resource to Dedup

Author: Alain Spineux <alain@baculasystems.com>
Date:   Wed Oct 16 19:28:20 2019 +0200

    regress: add a Dedup resource and make async.sh rebuild the SD plugins

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Sun Aug 4 17:57:41 2019 -0300

    cdp: Added script to make / execute Windows unit tests

Author: Norbert Bizet <norbert.bizet@baculasystems.com>
Date:   Mon Jun 24 08:33:58 2019 -0400

    regress: add target for clear regress cloud driver

Author: Norbert Bizet <norbert.bizet@baculasystems.com>
Date:   Thu Jun 6 03:47:34 2019 -0400

    cloud: Introduce a was_driver_simulator

    Use FakeAzureCloud cloud device in config (see cloud.conf.sample)

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Apr 10 08:41:13 2019 +0200

    regress: Skip SD Errors in restart-* jobs

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Feb 19 13:25:31 2019 +0100

    regress: Check for SD Errors in log1.out

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Feb 14 14:40:23 2019 +0100

    regress: Adapt check_jobmedia() for incomplete jobs

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Jan 25 17:57:31 2019 +0100

    regress: Check for orphan open files at the end of each regress

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Nov 19 10:01:41 2018 +0100

    regress: Try to create cloud buckets when starting the test

Author: Norbert Bizet <norbert.bizet@baculasystems.com>
Date:   Fri Nov 16 15:33:09 2018 +0100

    regress: Add multi cloud test

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Nov 16 16:36:11 2018 +0100

    regress: Use cloud.conf.sample if cloud.conf is not present

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Oct 31 12:35:09 2018 +0100

    regress: Install btools when FORCE_DEDUP=yes

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Jun 22 10:49:34 2018 +0200

    regress: Add functions to test encryption with regular tests

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Apr 26 14:05:41 2018 +0200

    regress: Check automatically JSON tools in stop_bacula

Author: Alain Spineux <alain@baculasystems.com>
Date:   Fri Apr 28 14:16:44 2017 +0200

    regress: script/functions make start_test() more flexible

    - the goal is to be able to "continue" a test after a stop
    - moved initialisation from to start_test() to reset_test()
    - start_test() call reset_test() then nothing change
    - build the test-dedup plugin when dedup is enable

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue Feb 21 16:48:33 2017 +0100

    regress: new function->require_query_dde to load pythons modules into "scripts"

    - call require_query_dde() from any script using query_dde
    - file lz4.so and pytc.so are loaded once
      into regress/scripts from https://www.baculasystems.com
    - add query_dde.py checkmodules command

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Feb 7 18:58:10 2017 +0100

    regress: Remove libtool warning message with FORCE_XXX options

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Feb 3 09:22:33 2017 +0100

    regress: Fix aligned tests to build the driver automatically

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Jan 14 13:29:45 2017 +0100

    regress: attempt to shorten start/end test output to 80 chars

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Oct 6 15:03:28 2016 +0200

    regress: Modify the regress scripts so that each developer can have a different Cloud resource with his/her own resources

Author: Alain Spineux <alain@baculasystems.com>
Date:   Wed Sep 28 15:43:52 2016 +0200

    regress: add MaxContainerSize directive to bacula-sd.conf

Author: Kern Sibbald <kern@sibbald.com>
Date:   Mon Sep 5 08:13:48 2016 +0200

    regress: fix verify-data-test to work with Cloud + separate Verify to have separate error status

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Jul 16 09:22:03 2016 +0200

    regress: PREBUILT implementation

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sun Jul 10 12:40:10 2016 +0200

    regress: add FORCE_CLOUD

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Jun 25 09:18:41 2016 +0200

    regress: add FORCE variant name to more output messages

Author: Kern Sibbald <kern@sibbald.com>
Date:   Tue Jun 21 11:24:46 2016 +0200

    regress: fix require_vtape to reject FORCE_ALIGNED and FORCE_DEDUP

Author: Alain Spineux <alain@baculasystems.com>
Date:   Mon Dec 14 12:37:29 2015 +0100

    regress add hangup-blowup-test

    - tests the setdebug blowup and hangup options
    - For some tests the SD or FD don't terminate or behave has expected,
      see "THIS IS NOT WORKING FIX IT" below
    - For blowup, this is often ok if the daemon is restarted. The dir
      nee to contact the "restarted" daemon to "terminate" the pending job.

Author: Alain Spineux <alain@baculasystems.com>
Date:   Thu Mar 5 16:02:30 2015 +0100

    regress: create the dde.conf file

    when in DEVELOPER, the existence of file dde.conf
    limit the original size of the DDE Index to 1M
    The Index can still grow over 1M or can be "optimized"

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Feb 23 13:45:42 2015 +0100

    regress: Fix bconsole-test with check_jobmedia

Author: Alain Spineux <alain@baculasystems.com>
Date:   Wed Jan 14 12:00:05 2015 +0100

    regress: add check_dedup_enable and check_dedup_forced to functions

    call check_dedup_enable at the beginning of every dedup only tests
    check_dedup_enable test FORCE_DEDUP and DEDUP_FS_OPTION and
    - "exit 0" if not set
    - "exit 1" if wrong values
    - continue if FORCE_DEDUP and DEDUP_FS_OPTION are set

    check_dedup_forced call check_dedup_enable, but also
    check that DDE will receive data (aka DEDUP_FS_OPTION != none)

    -regress/bta (backtrace all) don't paging anymore, and display all the back trace
    - dedup-full-test is skipped is sudo cannot  be used without password by the current user

Author: Alain Spineux <alain@baculasystems.com>
Date:   Thu Nov 6 11:24:02 2014 +0100

    regress: rename chunck into chunk

Author: Alain Spineux <alain@baculasystems.com>
Date:   Mon Oct 20 12:25:10 2014 +0200

    regress: support new "dedup usage" outpout and test option "reset"

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue Sep 30 14:13:14 2014 +0200

    regress: Display the "Variant" of the test in the title

    The "variant" compile DEDUP_*, FORCE_ALIGNED and FORCE_SDCALLS
    The "title" now looks like :
    === Starting dedup-mode-test  Dedup(bothsides,fdcache=yes) at 13:01:30 ===

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Sep 25 08:48:49 2014 +0200

    regress: avoid bad error reporting for restart2-job-test

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Sat Sep 20 12:38:58 2014 +0200

    regress: Do not report error for incomplete jobs in restart-*-test

Author: Alain Spineux <alain@baculasystems.com>
Date:   Wed Aug 27 11:04:48 2014 +0200

    regress: add dmsg() and dtitle() to scripts/functions

    dmsg "This message will be display only if debug is on"
    dtitle "This message will be rounded with === like below"

    ====================================================
    This message will be rounded with === like below
    ====================================================

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Aug 19 09:07:01 2014 +0200

    regress: Store dedup engine in working/dde

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Jun 14 17:55:47 2014 +0200

    Implement dummy_stmp

Author: Alain Spineux <alain@baculasystems.com>
Date:   Mon Jun 2 08:36:54 2014 +0200

    regress: add dedup-mode-test, test metrology accuracy and that dedup happens at the right place

    test default mode (bohsides, storage or node) only, use ./run to test all

Author: Alain Spineux <alain@baculasystems.com>
Date:   Thu May 22 17:04:40 2014 +0200

    regress: new 'run' script that handle more option for dedup

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon May 12 14:24:35 2014 +0200

    regress: Add dedup options to control dedup directives

Author: Alain Spineux <alain@baculasystems.com>
Date:   Mon Apr 7 15:08:12 2014 +0200

    Part 2 beginning dedup code

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Jul 20 18:55:54 2013 +0200

    Fix seg fault bug 7901 bsock released during cancel

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Apr 15 09:30:46 2013 +0200

    regress: Add FORCE_ALIGNED=yes option to use aligned format in normal tests

regress/scripts/functions [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 6063d1b..74ecab1
@@ -1,5 +1,6 @@
 #
-# Copyright (C) 2000-2017 Kern Sibbald
+#
+# Copyright (C) 2000-2020 Kern Sibbald
 # License: BSD 2-Clause; see file LICENSE-FOSS
 #
 # A set of useful functions to be sourced in each test
@@ -7,6 +8,10 @@
 
 . ./config
 
+if [ "$TestName" ]; then
+   export TestName
+fi
+
 check_encoding()
 {
    if ${bin}/bacula-dir -d50 -t -c ${conf}/bacula-dir.conf 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null ; then
@@ -15,6 +20,120 @@ check_encoding()
    fi
 }
 
+update_cloud()
+{
+   make -C build/src/stored install-cloud install-s3-cloud install-s3-glacier-cloud install-oci-cloud install-gs-cloud install-swift-cloud install-generic-cloud install-bcloud > /dev/null 2>&1
+   make -C build/scripts install-regress-drivers > /dev/null 2>&1
+   $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Plugin Directory", "$plugins", "Storage")'
+
+   CLOUD_NAME=${CLOUD_NAME:-RegressCloud}
+   # try to launch the emulators
+   if [ x$CLOUD_NAME = xFakeS3Cloud ]; then   #S3 Emulator
+      mkdir -p $tmp/cloud
+      fakes3 --root=$tmp/cloud --port=4567 &
+      aws s3api --endpoint-url='http://localhost:4567' create-bucket --bucket ${1:-regressbucket}
+      CLOUD_MAXIMUM_PART_SIZE=50MB
+   fi
+
+   if [ x$CLOUD_NAME = xScalabilityCloud ]; then   # like S3
+      aws s3api --endpoint-url='http://localhost:8000' create-bucket --bucket ${1:-regressbucket}
+   fi
+
+   if [ x$CLOUD_NAME = xAzuriteCloud ]; then  #WAS Emulator
+      azurite &
+   fi 
+
+   if [ x$CLOUD_NAME = xFakeAzureCloud ]; then  #WAS Emulator
+      make -C build/scripts install-generic-cloud-as-was > /dev/null 2>&1
+   fi 
+
+   #FIXME : if we find an existing Cloud, might be worth it to remove it here
+   grep $CLOUD_NAME $conf/bacula-sd.conf > /dev/null
+   if [ $? != 0 ]; then
+      cfile="$cwd/cloud.conf.sample"
+      if [ -f "$cwd/cloud.conf" ]; then
+          cfile="$cwd/cloud.conf"
+      fi
+      if grep $CLOUD_NAME $cfile > /dev/null; then
+         $bperl -e "extract_resource('$cfile', 'Cloud', '$CLOUD_NAME')" >> $conf/bacula-sd.conf
+      else 
+          echo "Missing cloud $CLOUD_NAME in $cfile. Contact R@D manager for more info."
+          exit 1
+      fi
+   fi
+
+   if [ x$CLOUD_NAME = xOracleCloud -a -f $HOME/.oci/config ]; then
+       oci  os bucket create --name ${1:-regressbucket}
+       $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '$HOME/.oci/config', 'Cloud', 'OracleCloud')"
+   fi
+
+   if [ x$CLOUD_NAME = xGoogleCloud -a -d $HOME/.gsutil ]; then
+       # Command line buckets are not working correctly, permissions are not set
+       gsutil list | grep ${1:-regressbucket}
+       $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '$HOME', 'Cloud', 'GoogleCloud')"
+   fi
+
+   #File driver
+   if [ x$CLOUD_NAME = xRegressCloud ]; then
+       $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '$tmp/cloud', 'Cloud', 'RegressCloud')"
+       mkdir -p $tmp/cloud
+   fi
+
+   # update Devices to use this Cloud
+   $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Device Type", "Cloud", "Device")'
+   $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Cloud", "'$CLOUD_NAME'", "Device")'
+
+   # overwrites from the config file (for personnal account use)
+   if [ "$CLOUD_HOSTNAME" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '\"$CLOUD_HOSTNAME\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_BUCKETNAME" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'BucketName', '\"$CLOUD_BUCKETNAME\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_ACCESSKEY" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'AccessKey', '\"$CLOUD_ACCESSKEY\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_SECRETKEY" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'SecretKey', '\"$CLOUD_SECRETKEY\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_REGION" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Region', '\"$CLOUD_REGION\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_PROTOCOL" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Protocol', '$CLOUD_PROTOCOL', 'Cloud')"
+   fi
+   if [ "$CLOUD_URISTYLE" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'UriStyle', '$CLOUD_URISTYLE', 'Cloud')"
+   fi
+   if [ "$CLOUD_BLOBENDPOINT" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'BlobEndpoint', '\"$CLOUD_BLOBENDPOINT\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_FILEENDPOINT" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'FileEndpoint', '\"$CLOUD_FILEENDPOINT\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_QUEUEENDPOINT" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'QueueEndpoint', '\"$CLOUD_QUEUEENDPOINT\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_TABLEENDPOINT" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'TableEndpoint', '\"$CLOUD_TABLEENDPOINT\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_ENDPOINTSUFFIX" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'EndpointSuffix', '\"$CLOUD_ENDPOINTSUFFIX\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_DRIVER" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Driver', '\"$CLOUD_DRIVER\"', 'Cloud')"
+   fi
+   if [ "$CLOUD_MAXIMUM_PART_SIZE" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'MaximumPartSize', '$CLOUD_MAXIMUM_PART_SIZE', 'Device')"
+   fi
+   if [ "$CLOUD_TRUNCATE_CACHE" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'TruncateCache', '$CLOUD_TRUNCATE_CACHE', 'Cloud')"
+   fi
+   if [ "$CLOUD_DRIVER_COMMAND" ]; then
+         $bperl -e "add_attribute('$conf/bacula-sd.conf', 'DriverCommand', '$CLOUD_DRIVER_COMMAND', 'Cloud')"
+   fi
+}
+
 start_test()
 {
    check_encoding
@@ -33,6 +152,9 @@ start_test()
       cp ${conf}/bacula-dir.conf ${tmp}/1
       sed -f ${outf} ${tmp}/1 > ${conf}/bacula-dir.conf
    fi
+   if [ x$FORCE_DOT_STATUS = xyes ]; then
+      $bperl -e "check_dot_status()" 2> /dev/null > $tmp/check_dot_status.out &
+   fi
    echo $TestName | grep aligned > /dev/null
    if [ $? -eq 0 -o x$FORCE_ALIGNED = xyes ]; then
       make -C build/src/stored install-aligned > /dev/null 2>&1
@@ -42,52 +164,37 @@ start_test()
       devicetype=`expr $devicetype + 1`
    fi
    if [ x$FORCE_CLOUD = xyes ]; then
-      make -C build/src/stored install-cloud > /dev/null 2>&1
-      grep DummyCloud $conf/bacula-sd.conf > /dev/null
-      if [ $? != 0 ]; then
-         $bperl -e 'extract_resource("$rscripts/test-bacula-sd.conf", "Cloud", "DummyCloud")' >> $conf/bacula-sd.conf
-      fi
-      $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Device Type", "Cloud", "Device")'
-      $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Cloud", "DummyCloud", "Device")'
+      update_cloud
+      variant_name="$CLOUD_NAME"
+      devicetype=`expr $devicetype + 1`
+   fi
+   if [ x$FORCE_DEDUP = xyes ]; then
+      make -C build/src/stored install-dedup > /dev/null 2>&1
+      make -C build/src/plugins/fd install-test-dedup >/dev/null 2>&1
+      make -C build/scripts install-btools >/dev/null 2>&1
+      DEDUP_FS_OPTION=${DEDUP_FS_OPTION:-bothsides}
+      mkdir ${working}/dde
+      DEDUP_MAXIMUM_CONTAINER_SIZE=${DEDUP_MAXIMUM_CONTAINER_SIZE:-10MB}
+      touch ${working}/dde/dde.conf # When dde.conf exists, DDE create a smaller Index
       $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Plugin Directory", "$plugins", "Storage")'
-      mkdir -p $tmp/cloud
-      if [ "$CLOUD_HOSTNAME" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '\"$CLOUD_HOSTNAME\"', 'Cloud')"
-      fi
-      if [ "$CLOUD_BUCKETNAME" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'BucketName', '\"$CLOUD_BUCKETNAME\"', 'Cloud')"
-      fi
-      if [ "$CLOUD_ACCESSKEY" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'AccessKey', '\"$CLOUD_ACCESSKEY\"', 'Cloud')"
-      fi
-      if [ "$CLOUD_SECRETKEY" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'SecretKey', '\"$CLOUD_SECRETKEY\"', 'Cloud')"
-      fi
-      if [ "$CLOUD_REGION" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Region', '\"$CLOUD_REGION\"', 'Cloud')"
-      fi
-      if [ "$CLOUD_PROTOCOL" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Protocol', '$CLOUD_PROTOCOL', 'Cloud')"
-      fi
-      if [ "$CLOUD_URISTYLE" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'UriStyle', '$CLOUD_URISTYLE', 'Cloud')"
-      fi
-      if [ "$CLOUD_DRIVER" ]; then
-          driver=`echo $CLOUD_DRIVER | tr 'A-Z' 'a-z'`
-          # FakeS3 is useful but keeps big parts in memory. So we must limit parts.
-          if [ "$driver" = "fakes3" ]; then
-             if [ "$CLOUD_MAXIMUM_PART_SIZE" = "" ]; then
-                CLOUD_MAXIMUM_PART_SIZE=50MB
-             fi
-             CLOUD_DRIVER=S3
-          fi
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Driver', '\"$CLOUD_DRIVER\"', 'Cloud')"
-      fi
-      if [ "$CLOUD_MAXIMUM_PART_SIZE" ]; then
-          $bperl -e "add_attribute('$conf/bacula-sd.conf', 'MaximumPartSize', '$CLOUD_MAXIMUM_PART_SIZE', 'Device')"
-      fi
+      $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Device Type", "Dedup", "Device")'
+      $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Dedupengine", "Dedupengine1", "Device")'
+      cat >> $conf/bacula-sd.conf <<EOF
+
+Dedupengine {
+  Name = Dedupengine1
+  DedupDirectory = "${working}/dde"
+  Driver = Legacy
+}
 
-      variant_name="Cloud"
+EOF
+      $bperl -e 'add_attribute("$conf/bacula-dir.conf", "Dedup", "'$DEDUP_FS_OPTION'", "Options")'
+      $bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumContainerSize", "'$DEDUP_MAXIMUM_CONTAINER_SIZE'", "Dedup")'
+      DEDUP_FD_CACHE=${DEDUP_FD_CACHE:-no}
+      if [ x$DEDUP_FD_CACHE = xyes ]; then
+            $bperl -e 'add_attribute("$conf/bacula-fd.conf", "DedupIndexDirectory", "$working/ddefd", "FileDaemon")'
+      fi
+      variant_name="Dedup($DEDUP_FS_OPTION,fdcache=$DEDUP_FD_CACHE)"
       devicetype=`expr $devicetype + 1`
    fi
    if [ x$FORCE_SDCALLS = xyes ]; then
@@ -163,12 +270,14 @@ reset_test()
    export TestName
    export zstat
    export estat
+   export ddestat
    estat=0
    zstat=0
    bstat=0
    rstat=0
    vstat=0
    dstat=0
+   ddestat=0
 }
 
 # Change setup so that we run with shared storage plugin
@@ -218,6 +327,11 @@ if test x$FORCE_CLOUD = xyes; then
    echo "$TestName test not compatible with FORCE_CLOUD."
    exit 0
 fi
+#  tape not comptible with dedup
+if test x$FORCE_DEDUP = xyes; then
+   echo "$TestName test not compatible with FORCE_DEDUP."
+   exit 0
+fi
 if test x${TAPE_DRIVE} = x/dev/null ; then
    echo "$TestName test needs a tape drive, but has none."
    exit 1
@@ -252,6 +366,11 @@ if test x$FORCE_CLOUD = xyes; then
    echo "$TestName test not compatible with FORCE_CLOUD."
    exit 0
 fi
+#  vtape not comptible with dedup
+if test x$FORCE_DEDUP = xyes; then
+   echo "$TestName test not compatible with FORCE_DEDUP."
+   exit 0
+fi
 if test x${USE_VTAPE} = x ; then
    echo "$TestName test needs the vtape driver."
    exit 0
@@ -270,6 +389,11 @@ if test x$FORCE_CLOUD = xyes; then
    echo "$TestName test not compatible with FORCE_CLOUD."
    exit 0
 fi
+#  vtape not comptible with dedup
+if test x$FORCE_DEDUP = xyes; then
+   echo "$TestName test not compatible with FORCE_DEDUP."
+   exit 0
+fi
 if test x${USE_VTAPE} = xyes ; then
    echo "$TestName test not compatible with FORCE_VTAPE."
    exit 0
@@ -429,6 +553,36 @@ bscan_libdbi()
 
 stop_bacula()
 {
+   if [ x$FORCE_DOT_STATUS = xyes ]; then
+      rm -f $tmp/check_dot_status.ctrl
+   fi
+   if [ "$CHECK_OPENFILE" != 0 ]; then
+      rm -f $tmp/stop.$$.out
+      cat << EOF > $tmp/stop.$$
+@output /dev/null
+message
+@output $tmp/stop.$$.out
+.api 2
+.status storage header
+quit
+EOF
+      cat  $tmp/stop.$$ | $bin/bconsole -c $conf/bconsole.conf -u 1
+      pid=`awk -F= '/pid=/ { print $2; exit; }' $tmp/stop.$$.out 2> /dev/null`
+      if [ "$pid" != "" ]; then
+         $bperl -e "check_openfile('/proc/$pid/fd')"
+         if [ $? -ne 0 ]; then
+            echo " "
+            echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
+            echo "     Files still open!!"
+            echo " " >>test.out
+            echo " " >>test.out
+            echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
+            echo "     Files still open!!" >>test.out
+            echo " "
+            exit 1
+         fi
+      fi
+   fi
    if [ "$CHECK_JOBMEDIA" != 0 ]; then
       $bperl -e 'check_jobmedia()'
       if [ $? -ne 0 ]; then
@@ -443,7 +597,35 @@ stop_bacula()
          exit 1
       fi
    fi
-   if [ "$FORCE_CLOUD" = yes ]; then
+   if [ "$CHECK_ENCRYPTION" != 0 -a "$FORCE_ENCRYPTION" = yes ]; then
+      $bperl -e 'check_encryption("$tmp/log1.out")'
+      if [ $? -ne 0 ]; then
+         echo " "
+         echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
+         echo "     Encryption problem"
+         echo " " >>test.out
+         echo " " >>test.out
+         echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
+         echo "     Encryption problem" >>test.out
+         echo " "
+         exit 1
+      fi
+   fi
+   if [ "$CHECK_JSON" != 0 ]; then
+      $bperl -e 'check_json_tools()'
+      if [ $? -ne 0 ]; then
+         echo " "
+         echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
+         echo "     JSON Data is incorrect"
+         echo " " >>test.out
+         echo " " >>test.out
+         echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
+         echo "     JSON Data is incorrect" >>test.out
+         echo " "
+         exit 1
+      fi
+   fi
+   if [ "x$FORCE_CLOUD" = xyes ]; then
       $bperl -e 'check_parts()'
       if [ $? -ne 0 ]; then
              print_debug "ERROR: FORCE_CLOUD check_parts"
@@ -507,6 +689,11 @@ change_jobname()
 check_two_logs()
 {
    bstat=${bstat:-99}   # We must find at least one job in log1.out
+   echo "$TestName" | grep restart.*-test > /dev/null
+   restartjob=0
+   if [ $? -eq 0 ]; then
+      restartjob=1
+   fi
    grep "^  Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
    if test $? -ne 0; then
       bstat=2
@@ -516,8 +703,7 @@ check_two_logs()
       bstat=2
    fi
    # Do not check for restart jobs in restart tests
-   echo "$TestName" | grep restart.*-test > /dev/null
-   if [ $? -ne 0 ]; then
+   if [ $restartjob = 0 ]; then
       grep "^  Termination: .*Backup failed" ${tmp}/log1.out 2>&1 >/dev/null
       if test $? -eq 0; then
          bstat=3
@@ -529,6 +715,12 @@ check_two_logs()
    if test $? -eq 0; then
       rstat=2
    fi
+   if [ $restartjob = 0 ]; then
+      grep "SD Errors: *[1-9]" ${tmp}/log1.out 2>&1 >/dev/null
+      if test $? -eq 0; then
+         bstat=3
+      fi
+   fi
    grep "^  Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
    if test $? -eq 0; then
       rstat=3
@@ -556,6 +748,21 @@ check_two_logs()
    fi
 }
 
+die_dde()
+{
+   code=$1
+   msg=$2
+   
+   print_debug $msg
+   stop_bacula
+   
+   if test "$code" -gt "$ddestat" ; then
+      ddestat=$code
+   fi
+   end_test
+   exit 1
+}
+
 die_test()
 {
    code=$1
@@ -571,6 +778,92 @@ die_test()
    exit 1
 }
 
+die_early()
+{
+   msg=$1
+   print_debug $msg
+   exit 2
+}
+
+#
+# must be called just after "functions" by tests that can run only when dedup is on
+#
+check_dedup_enable()
+{
+   if [ "$FORCE_DEDUP" != "yes" ] ; then 
+      print_debug "This test is dedicated to DEDUP, set variable FORCE_DEDUP to 'yes'"
+      exit 0
+   fi
+   if [ "$DEDUP_FS_OPTION" != "bothsides" -a "$DEDUP_FS_OPTION" != "storage" -a "$DEDUP_FS_OPTION" != "none" ] ; then
+      print_debug "variable DEDUP_FS_OPTION must be set to bothsides, storage or none"
+      exit 1
+   fi
+}
+
+
+#
+# be sure that dedup is on and DDE will receive data
+#
+check_dedup_forced()
+{
+   check_dedup_enable
+   if [ "$DEDUP_FS_OPTION" = "none" ] ; then
+      print_debug "This test expect to see the DDE grow then DEDUP_FS_OPTION cannot be none"
+      exit 0
+   fi
+}
+
+#
+# load all the modules required by query_dde, if not yet loaded
+#
+require_query_dde()
+{
+   QUERY_DDE_ADVANCED="yes" $rscripts/query_dde.py checkmodules
+   if [ $? -eq 0 ] ; then
+      return
+   fi
+   local query_dde_url=https://www.baculasystems.com/ml/ohweekah9WawuiB/depkgs-query-dde
+   local name
+   for name in lz4.so pytc.so argparse.py ; do
+      if [ ! -f $rscripts/$name ] ; then
+         if ! wget -O $rscripts/$name $query_dde_url/$name ; then
+            echo Failed to load $query_dde_url/$name
+            exit 1
+         fi
+      fi
+   done
+}
+
+check_dedupengine_health()
+{
+   local logfile=$1
+   if grep "dde_errors=[1-9]" $logfile >/dev/null; then
+      ddestat=99
+   fi
+   if grep "containers_errors=[1-9]" $logfile >/dev/null; then
+      ddestat=99
+   fi
+   if grep "vacuum_errors=[1-9]" $logfile >/dev/null; then
+      ddestat=99
+   fi
+}
+
+check_dde_status()
+{
+   local filename="$1"
+   local hash_count=$2
+   local chunk_used=$3
+   
+   grep "DDE:" ${filename} | grep "hash_count=${hash_count}" >/dev/null && \
+      grep "Containers:" ${filename} | grep "chunk_used=${chunk_used}" >/dev/null
+}
+
+is_dde_empty()
+{
+   filename="$1"
+   check_dde_status "$filename" 0 0
+}
+
 dtitle()
 {
    if test "$debug" -eq 1 ; then
@@ -674,6 +967,7 @@ check_restore_tmp_build_diff()
 # rstat is restore status
 # zstat is zombie job(s)
 # vstat is verify status
+# ddestat is dedupengine error
 #
 end_test()
 {
@@ -686,6 +980,13 @@ end_test()
    fi
    d=`./test_duration`
    t=`date +%R:%S`
+   if [ $ddestat != 0 ] ; then
+      echo " " | tee -a test.out
+      echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! " | tee -a test.out
+      echo "     Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat dde=$ddestat" | tee -a test.out
+      echo " "
+      exit 1
+   fi
    if [ $estat != 0 ] ; then
       echo " "
       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
@@ -751,6 +1052,7 @@ copy_test_confs()
 
 disable_plugins()
 {
+   local i
    for i in ${conf}/bacula-fd.conf; do
       sed 's/Plugin/#Plugin/' $i > $tmp/1
       cp -f $tmp/1 $i
@@ -862,6 +1164,32 @@ case $1 in
 esac
 }
 
+check_variable()
+{
+   if [ "x$1" = "x" ]
+   then
+       echo "Variable $2 not set."
+       exit -1
+   fi
+}
+
+check_path()
+{
+   if [ ! -d $1 ]
+   then
+       echo "Path $2 does not exist: $1"
+       exit -1
+   fi
+}
+
+check_file()
+{
+   if [ ! -f $1 ]
+   then
+       echo "File $2 does not exist: $1"
+       exit -1
+   fi
+}
 
 # Save current directory
 cwd=`pwd`
@@ -880,6 +1208,9 @@ db_password=${db_password:-""}
 working=${working:-"$cwd/working"}
 dumps=${dumps:-"$cwd/dumps"}
 bin=${bin:-"$cwd/bin"}
+FORCE_DEDUP=${PREVAIL_FORCE_DEDUP:-$FORCE_DEDUP}
+DEDUP_FS_OPTION=${PREVAIL_DEDUP_FS_OPTION:-$DEDUP_FS_OPTION}
+DEDUP_FD_CACHE=${PREVAIL_DEDUP_FD_CACHE:-$DEDUP_FD_CACHE}
 PERL5LIB=${PERL5LIB}:$cwd
 
 # Bacula scripts
@@ -900,6 +1231,9 @@ src=${src:-"$cwd/build"}
 # Temp source directory so we don't mess up $src
 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
 
+# Unit Tests source directory 
+unitsrc=${unitsrc:-"$cwd/src"}
+
 export bin
 export conf
 export working
@@ -910,9 +1244,12 @@ export tmp
 export src
 export tmpsrc
 export PERL5LIB
+export unitsrc
 
 bperl="perl -Mscripts::functions"
 export bperl
+btools="$scripts/btools.py"
+export btools
 
 mkdir -p ${tmp}
 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out