Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
added plugin test to bvfs-test
Browse files Browse the repository at this point in the history
added mechanism to enable and disable plugins
and adapted the plugin-test.
  • Loading branch information
joergsteffens committed Jan 13, 2018
1 parent f8984e1 commit ec4734d
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 46 deletions.
9 changes: 3 additions & 6 deletions configs/BASE/bareos-dir.d/director/bareos-dir.conf.in
Expand Up @@ -16,11 +16,8 @@ Director { # define myself
# remove comment in next line to load dynamic backends from specified directory
# Backend Directory = @backenddir@

# remove comment from "Plugin Directory" to load plugins from specified directory.
# if "Plugin Names" is defined, only the specified plugins will be loaded,
# otherwise all director plugins (*-dir.so) from the "Plugin Directory".
#
# Plugin Directory = @plugindir@
# Plugin Names = ""
# If plugins should get used, call
# enable_plugin PLUGINNAME
Plugin Directory = @plugindirtmp@
}

23 changes: 23 additions & 0 deletions configs/BASE/bareos-dir.d/fileset/bpipe-fileset.conf.in
@@ -0,0 +1,23 @@
FileSet {
Name = bpipe-fileset
Include {
Options {
signature = MD5
}

#
# test different target files for bpipe
#
Plugin = "bpipe:file=/bpipe-file-in-root.txt:reader=find @rscripts@:writer=sh -c 'cat >@tmpdir@/root-bpipefile.txt'"
Plugin = "bpipe:file=@bpipe@/bpipe-dir-as-root-test.txt:reader=find @rscripts@:writer=sh -c 'cat >@tmpdir@/bpipe.txt'"
Plugin = "bpipe:file=@bpipe@/subdir/bpipe-dir-as-root-with-subdir-test.txt:reader=find @rscripts@:writer=sh -c 'cat >@tmpdir@/bpipe-subdir.txt'"
Plugin = "bpipe:file=/@bpipe@/bpipe-dir-in-root-test.txt:reader=find @rscripts@:writer=sh -c 'cat >@tmpdir@/root-bpipe.txt'"
Plugin = "bpipe:file=/@bpipe@/subdir/bpipe-dir-in-subdir-in-root-test.txt:reader=find @rscripts@:writer=sh -c 'cat >@tmpdir@/root-bpipe-subdir.txt'"

#
# also backup normal file list
#
File = <@tmpdir@/file-list
}
}

Expand Up @@ -7,5 +7,5 @@ Job {
Storage = File1
Pool = Default
Messages = Standard
Where = /tmp/bareos-restores
}
Where = @tmpdir@/bareos-restores
}
13 changes: 3 additions & 10 deletions configs/BASE/bareos-fd.d/client/myself.conf.in
Expand Up @@ -3,16 +3,9 @@ Client {
Fd Port = @fdport@
Maximum Concurrent Jobs = 20

# remove comment from "Plugin Directory" to load plugins from specified directory.
# if "Plugin Names" is defined, only the specified plugins will be loaded,
# otherwise all storage plugins (*-fd.so) from the "Plugin Directory".
#
# Plugin Directory = @plugindir@
# Plugin Names = ""

# if compatible is set to yes, we are compatible with bacula
# if set to no, new bareos features are enabled which is the default
# compatible = yes
# If plugins should get used, call
# enable_plugin PLUGINNAME
Plugin Directory = @plugindirtmp@

TLS Require = yes
TLS Certificate = "@confdir@/tls/client1.bareos.org-cert.pem"
Expand Down
9 changes: 3 additions & 6 deletions configs/BASE/bareos-sd.d/storage/bareos-sd.conf.in
Expand Up @@ -3,12 +3,9 @@ Storage {
Sd Port = @sdport@
Maximum Concurrent Jobs = 20

# remove comment from "Plugin Directory" to load plugins from specified directory.
# if "Plugin Names" is defined, only the specified plugins will be loaded,
# otherwise all storage plugins (*-sd.so) from the "Plugin Directory".
#
# Plugin Directory = @plugindir@
# Plugin Names = ""
# If plugins should get used, call
# enable_plugin PLUGINNAME
Plugin Directory = @plugindirtmp@

TLS Require = yes
TLS Certificate = "@confdir@/tls/bareos-sd1.bareos.org-cert.pem"
Expand Down
1 change: 1 addition & 0 deletions scripts/cleanup
Expand Up @@ -19,6 +19,7 @@ rm -rf ${working}/*.bsr ${working}/log*.sd
rm -rf ${working}/*.trace ${working}/*.traceback ${working}/*.bactrace
rm -rf ${working}/*.state
rm -rf ${working}/CLEANUPMARKER
rm -rf ${working}/plugins/*
find . -name "gigaslam.gif" -exec rm -f {} \;
# cleanup old config files
# don't delete mtx-changer.conf (and other files?)
Expand Down
5 changes: 4 additions & 1 deletion scripts/create_sed
Expand Up @@ -42,7 +42,10 @@ echo "s%@archivedir@%${tmp}%g" >>${out}
echo "s%@bindir@%${bin}%g" >>${out}
echo "s%@sbindir@%${bin}%g" >>${out}
echo "s%@scriptdir@%${scripts}%g" >>${out}
echo "s%@scripts@%${scripts}%g" >>${out}
echo "s%@rscripts@%${rscripts}%g" >>${out}
echo "s%@plugindir@%${plugindir}%g" >>${out}
echo "s%@plugindirtmp@%${plugindirtmp}%g" >>${out}
echo "s%@working_dir@%${working}%g" >>${out}
echo "s%@piddir@%${working}%g" >>${out}
echo "s%@job_email@%${EMAIL}%g" >>${out}
Expand All @@ -60,8 +63,8 @@ echo "s%@hostname@%${hostname}%g" >>${out}
echo "s%@hostname1@%${hostname1}%g" >>${out}
echo "s%@hostname2@%${hostname2}%g" >>${out}
echo "s%@hostname3@%${hostname3}%g" >>${out}
echo "s%@hostname1_files@%${hostname1_files}%g" >>${out}
echo "s%@hostname_files@%${hostname_files}%g" >>${out}
echo "s%@hostname1_files@%${hostname1_files}%g" >>${out}
echo "s%@hostname2_files@%${hostname2_files}%g" >>${out}
echo "s%@hostname3_files@%${hostname3_files}%g" >>${out}
echo "s%@hostname1_password@%${hostname1_password}%g" >>${out}
Expand Down
63 changes: 58 additions & 5 deletions scripts/functions
Expand Up @@ -39,6 +39,53 @@ copy_configs()
done
}

#
# activates a plugin by copying to $plugindirtmp.
# For this, daemons must have following setting:
# Plugin Directory = @plugindirtmp@
#
enable_plugin()
{
RC=0
PLUGIN="$1"

if [ -z "$PLUGIN" ]; then
set_error "enable_plugin: no plugin name given."
exit 1
fi

if ! cp $plugindir/${PLUGIN}.* $plugindirtmp/; then
set_error "enable_plugin: failed to enable ${PLUGIN} plugin."
RC=1
exit 1
fi

print_debug "plugin ${PLUGIN} enabled"

return $RC
}

disable_plugin()
{
RC=0
PLUGIN="$1"

if [ -z "$PLUGIN" ]; then
set_error "enable_plugin: no plugin name given."
exit 1
fi

if ! rm $plugindirtmp/${PLUGIN}.*; then
set_error "disable_plugin: failed to disable ${PLUGIN} plugin."
RC=1
exit 1
fi

print_debug "plugin ${PLUGIN} disabled"

return $RC
}

check_encoding()
{
${bin}/bareos-dir -d50 -t 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null
Expand Down Expand Up @@ -363,7 +410,7 @@ run_bareos()
if [ $DAEMON_STATUS -ne 0 ]; then
exit 1
fi

run_bconsole
return $?
}
Expand Down Expand Up @@ -835,12 +882,16 @@ db_password=${db_password:-""}
working=${working:-"$cwd/working"}
dumps=${dumps:-"$cwd/dumps"}
bin=${bin:-"$cwd/bin"}
tmp=${tmp:-"$cwd/tmp"}

# Bareos scripts
scripts=${scripts:-"$cwd/bin"}

# Bareos Plugin Directory
plugindir=${plugindir:-"$cwd/bin/plugins"}
# some tests (BASE) load only the plugins copied to plugindirtmp,
# to avoid that all plugins get loaded.
plugindirtmp=${plugindirtmp:-"$working/plugins"}

# Bareos conf files
conf=${conf:-"$cwd/bin"}
Expand All @@ -854,7 +905,6 @@ rscripts=${rscripts:-"$cwd/scripts"}
# Regress configs
rconfigs=${rconfigs:-"$cwd/configs"}

tmp=${tmp:-"$cwd/tmp"}

# Bareos source directory when copied here
# also build directory
Expand All @@ -868,13 +918,15 @@ export bin
export conf
export confdir
export configs
export working
export dumps
export scripts
export plugindir
export plugindirtmp
export rscripts
export tmp
export scripts
export src
export tmp
export tmpsrc
export working

export dirport=$BASEPORT
export fdport=$(($BASEPORT + 1))
Expand All @@ -889,6 +941,7 @@ export bperl

mkdir -p ${working}
mkdir -p ${tmp}
mkdir -p ${plugindirtmp}
touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out

CLIENT=${HOST}-fd
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-bareos-fd.conf.in
Expand Up @@ -21,7 +21,7 @@ FileDaemon { # this is me
FDPort = @fdport@ # where we listen for the director
WorkingDirectory = "@working_dir@"
Pid Directory = "@piddir@"
Plugin Directory = "@plugindir@"
Plugin Directory = "@plugindirtmp@"
Maximum Concurrent Jobs = 100
}

Expand Down
3 changes: 3 additions & 0 deletions tests/1-example-test
Expand Up @@ -52,6 +52,9 @@ copy_configs
# start the test
start_test

# activate plugin, e.g. bpipe-fd
#activate_plugin bpipe-fd

# ${tmp}/bconcmds lists the bconsole commands executed by "run_bareos"
cat <<END_OF_DATA >${tmp}/bconcmds
messages
Expand Down
47 changes: 43 additions & 4 deletions tests/bvfs-test
Expand Up @@ -41,14 +41,17 @@ setup_data data/small.tgz
# start the test
start_test

# activate bpipe-fd plugin
enable_plugin bpipe-fd

echo "Test Content 1" > ${BackupFileExtra}

# ${tmp}/bconcmds lists the bconsole commands executed by "run_bareos"
cat <<END_OF_DATA >${tmp}/bconcmds
messages
@$out ${tmp}/log-backup1.out w
label storage=File1 pool=Default volume=TestVolume001
run job=$JobName storage=File1 yes
run job=$JobName fileset=bpipe-fileset storage=File1 yes
wait
messages
quit
Expand All @@ -66,7 +69,7 @@ echo "Test Content 2" >> ${BackupFileExtra}

cat <<END_OF_DATA >${tmp}/bconcmds
@$out ${tmp}/log-backup2.out w
run job=$JobName storage=File1 yes
run job=$JobName fileset=bpipe-fileset storage=File1 yes
wait
messages
quit
Expand All @@ -88,6 +91,9 @@ cat <<END_OF_DATA >${tmp}/bconcmds
@$out ${tmp}/log-bvfs-get-root-path.out w
.bvfs_lsdir jobid=${BackupJobIds} path=
@$out ${tmp}/log-bvfs-get-root-path-offset.out w
.bvfs_lsdir jobid=${BackupJobIds} path= offset=1000 limit=1000
@$out ${tmp}/log-bvfs-lsdir-root.out w
.bvfs_lsdir jobid=${BackupJobIds} path=/
Expand All @@ -98,8 +104,14 @@ cat <<END_OF_DATA >${tmp}/bconcmds
@#.bvfs_lsfiles jobid=${BackupJobIds} pathid=1
.bvfs_lsfiles jobid=${BackupJobIds} path=${BackupDirectory}/
@$out ${tmp}/log-bvfs-lsfiles-BackupDirectory-limit1.out w
.bvfs_lsfiles jobid=${BackupJobIds} path=${BackupDirectory}/ offset 0 limit 1
@$out ${tmp}/log-bvfs-versions-extrafile.out w
.bvfs_versions jobid=0 client=${Client} path=${BackupDirectory}/ fname=extrafile.txt
@$out ${tmp}/log-bvfs-lsfiles-bpipe-directory.out w
.bvfs_lsfiles jobid=${BackupJobIds} path=@bpipe@/
END_OF_DATA

run_bconsole
Expand Down Expand Up @@ -171,12 +183,26 @@ fi
LOG=${tmp}/log-bvfs-get-root-path.out
check_log ${LOG}
# expect:
# 10 0 0 0 A A A A A A A A A A A A A A .
# 9 0 0 0 A A A A A A A A A A A A A A /
# 10 0 0 A A A A A A A A A A A A A A .
# 9 0 0 A A A A A A A A A A A A A A /
# 8 0 0 A A A A A A A A A A A A A A @bpipe@/
if ! grep -q "\W/$" ${LOG}; then
set_error "root directory not found (using '.bvfs_lsdir path=')."
fi

if ! grep -q "\W@bpipe@/$" ${LOG}; then
set_error "@bpipe@ plugin directory not found (using '.bvfs_lsdir path=')."
fi

LOG=${tmp}/log-bvfs-get-root-path-offset.out
check_log ${LOG}
# expect: empty file, as offset larger than number of dirs
dirs=`grep "^[0-9]\+\W" ${LOG} | wc -l`
if [ "$dirs" -gt 0 ]; then
set_error "result should be empty (using '.bvfs_lsdir path= offset=1000')."
fi


LOG=${tmp}/log-bvfs-lsdir-root.out
check_log ${LOG}
# expect:
Expand All @@ -203,13 +229,26 @@ if ! grep -q "\Wextrafile.txt" ${LOG}; then
set_error "file not found using .bvfs_lsfiles."
fi

LOG=${tmp}/log-bvfs-lsfiles-BackupDirectory-limit1.out
check_log ${LOG}
files=`grep "^[0-9]\+\W" ${LOG} | wc -l`
if [ "$files" != "1" ]; then
set_error "expected 1 file, found ${files}."
fi

LOG=${tmp}/log-bvfs-versions-extrafile.out
check_log ${LOG}
versions=`grep "^[0-9]\+\W" ${LOG} | wc -l`
if [ "$versions" != "2" ]; then
set_error "expected 2 versions of file ${BackupFileExtra}, found ${versions}."
fi

LOG=${tmp}/log-bvfs-lsfiles-bpipe-directory.out
check_log ${LOG}
if ! grep -q "\Wbpipe-dir-as-root-test.txt" ${LOG}; then
set_error "bpipe plugin result file not found using .bvfs_lsfiles."
fi

LOG=${tmp}/log-bvfs-restore.out
check_log ${LOG}
# check for differences between original files and restored files
Expand Down
16 changes: 5 additions & 11 deletions tests/plugin-test
Expand Up @@ -10,9 +10,8 @@ scripts/cleanup
scripts/copy-plugin-confs

# enable test-plugin
mv -f ${cwd}/bin/plugins/test-plugin-fd.sox ${cwd}/bin/plugins/test-plugin-fd.so

mv -f ${cwd}/bin/plugins/bpipe-fd.sox ${cwd}/bin/plugins/bpipe-fd.so
enable_plugin bpipe-fd
enable_plugin test-plugin-fd

file=encrypt-bug.jpg
echo "${cwd}/README" >${cwd}/tmp/file-list
Expand Down Expand Up @@ -67,12 +66,9 @@ stop_bareos
#
# Remove plugin so we can try the restore without the plugin
#
mv -f ${cwd}/bin/plugins/bpipe-fd.so ${cwd}/bin/plugins/bpipe-fd.sox
disable_plugin bpipe-fd

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out ${cwd}/tmp/log2.out
@# remove plugin
@exec "sh -c 'rm -f ${cwd}/bin/plugins/bpipe-fd.so'"
@#
@# now do a restore without the plugin
@#
Expand Down Expand Up @@ -110,7 +106,7 @@ stop_bareos
#
# Restore plugin
#
mv -f ${cwd}/bin/plugins/bpipe-fd.sox ${cwd}/bin/plugins/bpipe-fd.so
enable_plugin bpipe-fd

check_two_logs
#
Expand Down Expand Up @@ -159,7 +155,5 @@ perl -ne '

estat=$?

# disable test-plugin
mv -f ${cwd}/bin/plugins/test-plugin-fd.so ${cwd}/bin/plugins/test-plugin-fd.sox

end_test

0 comments on commit ec4734d

Please sign in to comment.