Skip to content

Commit

Permalink
reload-test: enhanced
Browse files Browse the repository at this point in the history
Should now also work on other Unix platforms, not only on Linux.
Also adding valid resources and checks if these are available after a
reload.
  • Loading branch information
joergsteffens committed Dec 30, 2016
1 parent 6e82544 commit d814707
Showing 1 changed file with 64 additions and 26 deletions.
90 changes: 64 additions & 26 deletions tests/reload-test
@@ -1,24 +1,41 @@
#!/bin/sh

#
# test the reload and test command.
#
# test the reload and test command
# Adds different (valid and invalid) statements to the Director configuration.
# Checks if invalid statements are detected by the test command
# and if reload can cope with them (not reloading the configuration).
# Also checks, if valid resources are available after reload.
#

TestName="reload-test"
. scripts/functions

require_linux
#require_linux
scripts/cleanup
scripts/copy-confs

# backup the configuration
cp $conf/bareos-dir.conf $tmp/1

bstat=0
rstat=0
zstat=0

detect_error()
check_config()
{
# checks, if "bareos-dir -t" detects the error in the configuration
$bin/bareos-dir -t $conf/bareos-dir.conf 2>&1 >> $tmp/testconf.log
if [ $? = 0 ]; then
return $?
}

detect_error()
{
# checks, if "bareos-dir -t" detects the error in the configuration
if check_config; then
estat=1
print_debug "Should detect error on bareos-dir.conf"
print_debug "There should be an error in bareos-dir.conf. However, bareos-dir -t does not detect it."
fi
}

Expand All @@ -36,18 +53,45 @@ EOF
print_debug "Bareos shouldn't die with a reload"
fi

ls -l /proc/$pid/fd | grep bareos-dir.conf
if [ $? = 0 ]; then
estat=1
print_debug "Should not have bareos-dir.conf open"
#ls -l /proc/$pid/fd | grep bareos-dir.conf
#if [ $? = 0 ]; then
# estat=1
# print_debug "Should not have bareos-dir.conf open"
#fi
}

is_client_existing()
{
NAME="$1"
echo ".clients" | $bin/bconsole -c $conf/bconsole.conf | grep "$NAME" >/dev/null
return $?
}

add_client_resource()
{
NAME="$1"

if [ -z "$NAME" ]; then
set_error "Failed: no client name given."
fi

cat >> $conf/bareos-dir.conf<<EOF
Client {
Name = "${NAME}-fd"
Address = 127.0.0.1
Password = "secret"
}
EOF
do_reload
if ! is_client_existing "$NAME"; then
set_error "Failed to add client $NAME."
fi
}

start_test

# should be ok
$bin/bareos-dir -t $conf/bareos-dir.conf
if [ $? != 0 ]; then
if ! check_config; then
estat=1
print_debug "Error on bareos-dir.conf"
fi
Expand All @@ -57,18 +101,8 @@ pid=`cat $working/bareos-dir.$BASEPORT.pid`

sleep 2

ls -l /proc/$pid/fd | grep bareos-dir.conf
if [ $? = 0 ]; then
estat=1
print_debug "Should not have bareos-dir.conf open"
fi

# should work well
do_reload

# backup the configuration
cp $conf/bareos-dir.conf $tmp/1


print_debug "Adding uncommented string to bareos-dir.conf"
cat >> $conf/bareos-dir.conf<<EOF
Expand All @@ -77,19 +111,21 @@ EOF
detect_error
do_reload

cp $tmp/1 $conf/bareos-dir.conf
add_client_resource "client1"

print_debug "Adding empty job res bareos-dir.conf"
cp $tmp/1 $conf/bareos-dir.conf
cat >> $conf/bareos-dir.conf<<EOF
Job {
}
EOF
detect_error
do_reload

cp $tmp/1 $conf/bareos-dir.conf
add_client_resource "client2"

print_debug "Adding two identical Jobs to bareos-dir.conf"
cp $tmp/1 $conf/bareos-dir.conf
cat >> $conf/bareos-dir.conf<<EOF
Job {
Name = "BackupClient1"
Expand All @@ -105,9 +141,10 @@ EOF
detect_error
do_reload

cp $tmp/1 $conf/bareos-dir.conf
add_client_resource "client3"

print_debug "Adding second director to bareos-dir.conf"
cp $tmp/1 $conf/bareos-dir.conf
cat >> $conf/bareos-dir.conf<<EOF
Director {
Name = second-dir
Expand All @@ -124,9 +161,10 @@ EOF
detect_error
do_reload



#cp $tmp/1 $conf/bareos-dir.conf
#add_client_resource "client4"

$bin/bareos-ctl-dir stop >/dev/null

end_test

0 comments on commit d814707

Please sign in to comment.