Skip to content

Commit

Permalink
systemtests: added python-sd-plugin-test
Browse files Browse the repository at this point in the history
The test checks if a python module logs events from the sd correctly.
  • Loading branch information
Tobias Plum committed Dec 18, 2019
1 parent 47d2be4 commit c0fa815
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 84 deletions.
Expand Up @@ -19,8 +19,8 @@ Director { # define myself
# if "Plugin Names" is defined, only the specified plugins will be loaded,
# otherwise all director plugins (*-dir.so) from the "Plugin Directory".
#
Plugin Directory = "@dir_plugin_binary_path@"
Plugin Names = "python"
# Plugin Directory = "@dir_plugin_binary_path@"
# Plugin Names = ""
Working Directory = "@working_dir@"
Pid Directory = "@piddir@"
DirPort = @dir_port@
Expand Down
@@ -1,6 +1,6 @@
Job {
Name = "backup-bareos-fd"
DIR Plugin Options ="python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin.log"
SD Plugin Options = "python:instance=0:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-sd-test:output=@tmp@/test-plugin.log"
JobDefs = "DefaultJob"
Client = "bareos-fd"
}
Expand Up @@ -6,8 +6,8 @@ Storage {
# if "Plugin Names" is defined, only the specified plugins will be loaded,
# otherwise all storage plugins (*-sd.so) from the "Plugin Directory".
#
# Plugin Directory = "@sd_plugin_binary_path@"
# Plugin Names = ""
Plugin Directory = "@sd_plugin_binary_path@"
Plugin Names = "python"
Working Directory = "@working_dir@"
Pid Directory = "@piddir@"
SD Port = @sd_port@
Expand Down

This file was deleted.

@@ -0,0 +1,115 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2019 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation, which is
# listed in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Author: Tobias Plum
#
from bareossd import *
from bareos_sd_consts import *


def load_bareos_plugin(context, plugindef):
events = []
events.append(bsdEventType["bsdEventJobStart"])
events.append(bsdEventType["bsdEventDeviceReserve"])
events.append(bsdEventType["bsdEventVolumeUnload"])
events.append(bsdEventType["bsdEventVolumeLoad"])
events.append(bsdEventType["bsdEventDeviceOpen"])
events.append(bsdEventType["bsdEventDeviceMount"])
events.append(bsdEventType["bsdEventLabelRead"])
events.append(bsdEventType["bsdEventLabelVerified"])
events.append(bsdEventType["bsdEventLabelWrite"])
events.append(
bsdEventType["bsdEventSetupRecordTranslation"]
)
events.append(
bsdEventType["bsdEventWriteRecordTranslation"]
)
events.append(bsdEventType["bsdEventDeviceUnmount"])
events.append(bsdEventType["bsdEventDeviceClose"])
events.append(bsdEventType["bsdEventJobEnd"])
RegisterEvents(context, events)
return bRCs["bRC_OK"]


def parse_plugin_definition(context, plugindef):
plugin_options = plugindef.split(":")
for current_option in plugin_options:
key, sep, val = current_option.partition("=")
if val == "":
continue
elif key == "output":
global outputfile
outputfile = val
continue
elif key == "instance":
continue
elif key == "module_path":
continue
elif key == "module_name":
continue
else:
return bRCs["bRC_Error"]
toFile(outputfile)

return bRCs["bRC_OK"]


def handle_plugin_event(context, event):
if event == bsdEventType["bsdEventJobStart"]:
toFile("bsdEventJobStart\n")
elif event == bsdEventType["bsdEventDeviceReserve"]:
toFile("bsdEventDeviceReserve\n")
elif event == bsdEventType["bsdEventVolumeUnload"]:
toFile("bsdEventVolumeUnload\n")
elif event == bsdEventType["bsdEventVolumeLoad"]:
toFile("bsdEventVolumeLoad\n")
elif event == bsdEventType["bsdEventDeviceOpen"]:
toFile("bsdEventDeviceOpen\n")
elif event == bsdEventType["bsdEventDeviceMount"]:
toFile("bsdEventDeviceMount\n")
elif event == bsdEventType["bsdEventLabelRead"]:
toFile("bsdEventLabelRead\n")
elif event == bsdEventType["bsdEventLabelVerified"]:
toFile("bsdEventLabelVerified\n")
elif event == bsdEventType["bsdEventLabelWrite"]:
toFile("bsdEventLabelWrite\n")
elif (
event
== bsdEventType["bsdEventSetupRecordTranslation"]
):
toFile("bsdEventSetupRecordTranslation\n")
elif (
event
== bsdEventType["bsdEventWriteRecordTranslation"]
):
toFile("bsdEventWriteRecordTranslation\n")
elif event == bsdEventType["bsdEventDeviceUnmount"]:
toFile("bsdEventDeviceUnmount\n")
elif event == bsdEventType["bsdEventDeviceClose"]:
toFile("bsdEventDeviceClose\n")
elif event == bsdEventType["bsdEventJobEnd"]:
toFile("bsdEventJobEnd\n")

return bRCs["bRC_OK"]


def toFile(text):
doc = open(outputfile, "a")
doc.write(text)
doc.close()
25 changes: 20 additions & 5 deletions systemtests/tests/python-sd-plugin-test/testrunner
@@ -1,12 +1,12 @@
#!/bin/sh
#
# This systemtest tests the plugin functionality
# of the Bareos DIR by using the module
# bareos-dir-test.py
# of the Bareos SD by using the module
# bareos-sd-test.py
#
# This test will backup some files. While the
# backup some events of the director will be
# logged from the python module.
# backup some events of the storage daemon
# will be logged from the python module.
# This testrunner will check if all events
# have been logged.
#
Expand Down Expand Up @@ -50,7 +50,22 @@ run_bareos
check_for_zombie_jobs storage=File
stop_bareos

for i in bDirEventJobStart bDirEventJobInit bDirEventJobRun bDirEventJobEnd; do
events=(bsdEventJobStart
bsdEventDeviceReserve
bsdEventVolumeUnload
bsdEventVolumeLoad
bsdEventDeviceOpen
bsdEventDeviceMount
bsdEventLabelRead
bsdEventLabelVerified
bsdEventLabelWrite
bsdEventSetupRecordTranslation
bsdEventWriteRecordTranslation
bsdEventDeviceUnmount
bsdEventDeviceClose
bsdEventJobEnd)

for i in ${events[@]}; do
if ! grep -q "$i" ${tmp}/test-plugin.log; then
set_error "Failed to find logged event $i"
fi
Expand Down

0 comments on commit c0fa815

Please sign in to comment.