Skip to content

Commit

Permalink
systemtests: py[23]plug-dir threading issue
Browse files Browse the repository at this point in the history
This patch lets the test run multiple jobs in parallel and checks that
each plugin callback sees the correct plugin context.
  • Loading branch information
arogge committed Feb 18, 2022
1 parent 7e73ac0 commit 7aa3967
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
Expand Up @@ -4,4 +4,5 @@ Client {
Address = @hostname@
Password = "@fd_password@" # password for FileDaemon
FD PORT = @fd_port@
Maximum Concurrent Jobs = 10
}
@@ -1,6 +1,23 @@
Job {
Name = "backup-bareos-fd"
DIR Plugin Options ="@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin.log"
Name = "backup-bareos-fd1"
DIR Plugin Options ="@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin1.log"
JobDefs = "DefaultJob"
}

Job {
Name = "backup-bareos-fd2"
DIR Plugin Options ="@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin2.log"
JobDefs = "DefaultJob"
}

Job {
Name = "backup-bareos-fd3"
DIR Plugin Options ="@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin3.log"
JobDefs = "DefaultJob"
}

Job {
Name = "backup-bareos-fd4"
DIR Plugin Options ="@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin4.log"
JobDefs = "DefaultJob"
Client = "bareos-fd"
}
Expand Up @@ -5,4 +5,5 @@ Storage {
Device = FileStorage
Media Type = File
SD Port = @sd_port@
Maximum Concurrent Jobs = 10
}
@@ -1,5 +1,12 @@
Device {
Autochanger {
Name = FileStorage
Device = FileStorageDev
Changer Command = ""
Changer Device = /dev/null
}

Device {
Name = FileStorageDev
Media Type = File
Archive Device = storage
LabelMedia = yes; # lets Bareos label unlabeled media
Expand All @@ -8,4 +15,5 @@ Device {
RemovableMedia = no;
AlwaysOpen = no;
Description = "File device. A connecting Director must have the same Name and MediaType."
Count = 10
}
19 changes: 15 additions & 4 deletions systemtests/tests/py2plug-dir/python-modules/BareosDirTest.py
Expand Up @@ -22,6 +22,7 @@
import bareosdir
import BareosDirPluginBaseclass

from time import time
from sys import version_info


Expand Down Expand Up @@ -52,21 +53,31 @@ def parse_plugin_definition(self, plugindef):

def handle_plugin_event(self, event):
super(BareosDirTest, self).handle_plugin_event(event)
job_name = repr(bareosdir.GetValue(bareosdir.bDirVarJobName))
job_id = repr(bareosdir.GetValue(bareosdir.bDirVarJobId))
microtime = round(time() * 1000)
msg_f = "%s Job:" + job_name + " JobId: " + job_id + " Time: " + repr(microtime) + "\n"

if event == bareosdir.bDirEventJobStart:
self.toFile("bDirEventJobStart\n")
self.toFile(msg_f % "bDirEventJobStart")

elif event == bareosdir.bDirEventJobEnd:
self.toFile("bDirEventJobEnd\n")
self.toFile(msg_f % "bDirEventJobEnd")

elif event == bareosdir.bDirEventJobInit:
self.toFile("bDirEventJobInit\n")
self.toFile(msg_f % "bDirEventJobInit")

elif event == bareosdir.bDirEventJobRun:
self.toFile("bDirEventJobRun\n")
self.toFile(msg_f % "bDirEventJobRun")

return bareosdir.bRC_OK

def toFile(self, text):
bareosdir.DebugMessage(
100,
"Writing string '%s' to '%s'\n"
% (text, self.outputfile),
)
doc = open(self.outputfile, "a")
doc.write(text)
doc.close()
Expand Down
18 changes: 13 additions & 5 deletions systemtests/tests/py2plug-dir/testrunner
Expand Up @@ -16,11 +16,9 @@ set -u
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-bareos-fd
#shellcheck source=../environment.in
. ./environment

JobName=backup-bareos-fd
#shellcheck source=../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
Expand All @@ -39,9 +37,12 @@ cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=200 dir
setdebug level=200 trace=1 dir
label volume=TestVolume001 storage=File pool=Full
run job=$JobName yes
run job=backup-bareos-fd1 yes
run job=backup-bareos-fd2 yes
run job=backup-bareos-fd3 yes
run job=backup-bareos-fd4 yes
status director
status client
status storage=File
Expand All @@ -55,9 +56,16 @@ check_for_zombie_jobs storage=File
stop_bareos

for i in bDirEventJobStart bDirEventJobInit bDirEventJobRun bDirEventJobEnd; do
if ! grep -q "$i" ${tmp}/test-plugin.log; then
if ! grep -q "$i" ${tmp}/test-plugin1.log; then
set_error "Failed to find logged event $i"
fi
done

for i in 1 2 3 4; do
num="$(grep -c -F "Job:'backup-bareos-fd$i." "${tmp}/test-plugin$i.log")"
if [ $num -ne 4 ]; then
set_error "Mismatched job context on plugin event in backup-bareos-fd$i"
fi
done

end_test

0 comments on commit 7aa3967

Please sign in to comment.