1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-14 11:43:41 +01:00
obackup/dev/tests/run_tests.sh

884 lines
31 KiB
Bash
Raw Normal View History

2016-08-18 14:19:52 +02:00
#!/usr/bin/env bash
2016-12-31 00:00:32 +01:00
#TODO Encrypted Pull runs on F25 fail for decryption
## obackup basic tests suite 2016123001
2016-08-18 14:19:52 +02:00
2016-08-30 16:12:10 +02:00
OBACKUP_DIR="$(pwd)"
OBACKUP_DIR=${OBACKUP_DIR%%/dev*}
DEV_DIR="$OBACKUP_DIR/dev"
TESTS_DIR="$DEV_DIR/tests"
2016-09-02 13:22:24 +02:00
2016-12-23 19:25:26 +01:00
CONF_DIR="$TESTS_DIR/conf"
2016-09-02 13:13:53 +02:00
LOCAL_CONF="local.conf"
PULL_CONF="pull.conf"
PUSH_CONF="push.conf"
2016-12-28 22:15:44 +01:00
2016-09-09 12:36:30 +02:00
OLD_CONF="old.conf"
2016-12-23 22:36:46 +01:00
MAX_EXEC_CONF="max-exec-time.conf"
2016-10-23 19:00:03 +02:00
TMP_OLD_CONF="tmp.old.conf"
2016-08-18 14:19:52 +02:00
2016-10-23 19:00:03 +02:00
OBACKUP_EXECUTABLE="obackup.sh"
2016-11-30 13:59:01 +01:00
OBACKUP_DEV_EXECUTABLE="dev/n_obackup.sh"
2016-10-23 19:00:03 +02:00
OBACKUP_UPGRADE="upgrade-v1.x-2.1x.sh"
2016-11-30 13:59:01 +01:00
TMP_FILE="$DEV_DIR/tmp"
2016-08-30 18:12:59 +02:00
2016-08-30 16:12:10 +02:00
SOURCE_DIR="${HOME}/obackup-testdata"
TARGET_DIR="${HOME}/obackup-storage"
2016-08-18 14:19:52 +02:00
2016-12-28 22:15:44 +01:00
TARGET_DIR_SQL_LOCAL="$TARGET_DIR/sql-local"
TARGET_DIR_FILE_LOCAL="$TARGET_DIR/files-local"
TARGET_DIR_CRYPT_LOCAL="$TARGET_DIR/crypt-local"
2016-08-18 14:19:52 +02:00
2016-08-30 19:17:14 +02:00
TARGET_DIR_SQL_PULL="$TARGET_DIR/sql-pull"
TARGET_DIR_FILE_PULL="$TARGET_DIR/files-pull"
2016-12-28 22:15:44 +01:00
TARGET_DIR_CRYPT_PULL="$TARGET_DIR/crypt-pull"
2016-08-18 14:19:52 +02:00
2016-08-30 19:17:14 +02:00
TARGET_DIR_SQL_PUSH="$TARGET_DIR/sql-push"
TARGET_DIR_FILE_PUSH="$TARGET_DIR/files-push"
2016-12-28 22:15:44 +01:00
TARGET_DIR_CRYPT_PUSH="$TARGET_DIR/crypt-push"
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
2016-08-18 17:10:53 +02:00
SIMPLE_DIR="testData"
RECURSIVE_DIR="testDataRecursive"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
S_DIR_1="dir rect ory"
R_EXCLUDED_DIR="Excluded"
R_DIR_1="a"
R_DIR_2="b"
R_DIR_3="c d"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
S_FILE_1="some file"
R_FILE_1="file_1"
R_FILE_2="file 2"
R_FILE_3="file 3"
2016-09-02 13:13:53 +02:00
N_FILE_1="non recurse file"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
EXCLUDED_FILE="exclu.ded"
DATABASE_1="mysql.sql.xz"
DATABASE_2="performance_schema.sql.xz"
DATABASE_EXCLUDED="information_schema.sql.xz"
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
CRYPT_EXTENSION=".obackup.gpg"
ROTATE_1_EXTENSION=".obackup.1"
PASSFILE="passfile"
2016-12-23 22:12:07 +01:00
CRYPT_TESTFILE="testfile"
2016-09-02 13:13:53 +02:00
2016-12-23 19:25:26 +01:00
# Later populated variables
OBACKUP_VERSION=2.x
OBACKUP_MIN_VERSION=x
OBACKUP_IS_STABLE=maybe
# Setup an array with all function modes
#declare -Ag osyncParameters
function GetConfFileValue () {
local file="${1}"
local name="${2}"
local value
value=$(grep "^$name=" "$file")
if [ $? == 0 ]; then
value="${value##*=}"
echo "$value"
else
assertEquals "$name does not exist in [$file]." "1" "0"
fi
2016-09-02 13:13:53 +02:00
}
2016-12-23 19:25:26 +01:00
function SetConfFileValue () {
local file="${1}"
local name="${2}"
local value="${3}"
if grep "^$name=" "$file" > /dev/null; then
# Using -i.tmp for BSD compat
sed -i.tmp "s/^$name=.*/$name=$value/" "$file"
rm -f "$file.tmp"
assertEquals "Set $name to [$value]." "0" $?
else
assertEquals "$name does not exist in [$file]." "1" "0"
fi
}
function SetupSSH {
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${HOME}/.ssh/id_rsa_local"
if ! grep "$(cat ${HOME}/.ssh/id_rsa_local.pub)" "${HOME}/.ssh/authorized_keys"; then
cat "${HOME}/.ssh/id_rsa_local.pub" >> "${HOME}/.ssh/authorized_keys"
fi
chmod 600 "${HOME}/.ssh/authorized_keys"
# Add localhost to known hosts so self connect works
if [ -z "$(ssh-keygen -F localhost)" ]; then
ssh-keyscan -H localhost >> "${HOME}/.ssh/known_hosts"
fi
# Update remote conf files with SSH port
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/#' "$CONF_DIR/$PULL_CONF"
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/#' "$CONF_DIR/$PUSH_CONF"
}
function RemoveSSH {
local pubkey
if [ -f "${HOME}/.ssh/id_rsa_local" ]; then
pubkey=$(cat "${HOME}/.ssh/id_rsa_local.pub")
sed -i.bak "#$pubkey#d" "${HOME}/.ssh/authorized_keys"
rm -f "${HOME}/.ssh/{id_rsa_local.pub,id_rsa_local}"
fi
2016-09-02 13:13:53 +02:00
}
function SetupGPG {
2016-09-02 13:22:24 +02:00
if type gpg2 > /dev/null; then
2016-09-04 21:37:24 +02:00
CRYPT_TOOL=gpg2
2016-09-02 13:22:24 +02:00
elif type gpg > /dev/null; then
2016-09-04 21:37:24 +02:00
CRYPT_TOOL=gpg
2016-09-02 13:22:24 +02:00
else
echo "No gpg support"
fi
2016-12-31 00:00:32 +01:00
echo "Crypt tool=$CRYPT_TOOL"
2016-09-04 21:37:24 +02:00
if ! $CRYPT_TOOL --list-keys | grep "John Doe" > /dev/null; then
2016-09-02 13:13:53 +02:00
cat >gpgcommand <<EOF
%echo Generating a GPG Key
Key-Type: RSA
Key-Length: 4096
Name-Real: John Doe
Name-Comment: obackup-test-key
Name-Email: john@example.com
Expire-Date: 0
Passphrase: PassPhrase123
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
2016-09-02 16:33:49 +02:00
if type apt-get > /dev/null 2>&1; then
sudo apt-get install rng-tools
2016-09-02 16:33:49 +02:00
fi
2016-09-02 13:13:53 +02:00
# Setup fast entropy
2016-09-04 08:37:21 +02:00
if type rngd > /dev/null 2>&1; then
rngd -r /dev/urandom
2016-09-02 13:22:24 +02:00
else
2016-09-04 08:37:21 +02:00
echo "No rngd support"
2016-09-02 13:13:53 +02:00
fi
2016-09-04 21:37:24 +02:00
$CRYPT_TOOL --batch --gen-key gpgcommand
echo "Currently owned $CRYPT_TOOL keys"
echo $($CRYPT_TOOL --list-keys)
2016-09-02 13:13:53 +02:00
rm -f gpgcommand
fi
echo "PassPhrase123" > "$TESTS_DIR/$PASSFILE"
}
2016-08-18 14:19:52 +02:00
function oneTimeSetUp () {
2016-12-23 19:25:26 +01:00
START_TIME=$SECONDS
2016-08-18 14:19:52 +02:00
source "$DEV_DIR/ofunctions.sh"
2016-12-23 19:25:26 +01:00
GetLocalOS
echo "Detected OS: $LOCAL_OS"
# Set some travis related changes
if [ "$TRAVIS_RUN" == true ]; then
echo "Running with travis settings"
REMOTE_USER="travis"
2016-12-23 20:43:58 +01:00
RHOST_PING="no"
2016-12-23 19:25:26 +01:00
SetConfFileValue "$CONF_DIR/$PULL_CONF" "REMOTE_3RD_PARTY_HOSTS" ""
SetConfFileValue "$CONF_DIR/$PUSH_CONF" "REMOTE_3RD_PARTY_HOSTS" ""
2016-12-23 21:35:02 +01:00
# Config value didn't have S at the end in old files
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_3RD_PARTY_HOST" ""
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$PULL_CONF" "REMOTE_HOST_PING" "no"
SetConfFileValue "$CONF_DIR/$PUSH_CONF" "REMOTE_HOST_PING" "no"
2016-12-23 21:35:02 +01:00
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_HOST_PING" "no"
2016-12-23 19:25:26 +01:00
else
echo "Running with local settings"
REMOTE_USER="root"
2016-12-23 20:43:58 +01:00
RHOST_PING="yes"
2016-12-23 19:25:26 +01:00
SetConfFileValue "$CONF_DIR/$PULL_CONF" "REMOTE_3RD_PARTY_HOSTS" "\"www.kernel.org www.google.com\""
SetConfFileValue "$CONF_DIR/$PUSH_CONF" "REMOTE_3RD_PARTY_HOSTS" "\"www.kernel.org www.google.com\""
2016-12-23 21:35:02 +01:00
# Config value didn't have S at the end in old files
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_3RD_PARTY_HOST" "\"www.kernel.org www.google.com\""
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$PULL_CONF" "REMOTE_HOST_PING" "yes"
SetConfFileValue "$CONF_DIR/$PUSH_CONF" "REMOTE_HOST_PING" "yes"
2016-12-23 21:35:02 +01:00
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_HOST_PING" "yes"
2016-12-23 19:25:26 +01:00
fi
# Get default ssh port from env
if [ "$SSH_PORT" == "" ]; then
SSH_PORT=22
fi
2016-09-02 13:13:53 +02:00
SetupGPG
2016-12-28 22:15:44 +01:00
if [ "$SKIP_REMOTE" != "yes" ]; then
SetupSSH
fi
2016-12-23 19:25:26 +01:00
# Get OBACKUP version
OBACKUP_VERSION=$(GetConfFileValue "$OBACKUP_DIR/$OBACKUP_DEV_EXECUTABLE" "PROGRAM_VERSION")
OBACKUP_VERSION="${OBACKUP_VERSION##*=}"
OBACKUP_MIN_VERSION="${OBACKUP_VERSION:2:1}"
OBACKUP_IS_STABLE=$(GetConfFileValue "$OBACKUP_DIR/$OBACKUP_DEV_EXECUTABLE" "IS_STABLE")
echo "Running with $OBACKUP_VERSION ($OBACKUP_MIN_VERSION) STABLE=$OBACKUP_IS_STABLE"
}
function oneTimeTearDown () {
SetConfFileValue "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" "IS_STABLE" "$OBACKUP_IS_STABLE"
RemoveSSH
#TODO: uncomment this when dev is done
2016-12-23 22:12:07 +01:00
#rm -rf "$SOURCE_DIR"
#rm -rf "$TARGET_DIR"
2016-12-23 19:25:26 +01:00
rm -f "$TMP_FILE"
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "It took $ELAPSED_TIME seconds to run these tests."
2016-09-02 13:13:53 +02:00
}
2016-12-23 19:25:26 +01:00
2016-09-02 13:38:35 +02:00
function setUp () {
2016-09-02 13:13:53 +02:00
rm -rf "$SOURCE_DIR"
2016-09-04 21:11:05 +02:00
rm -rf "$TARGET_DIR"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
mkdir -p "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_EXCLUDED_DIR"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3"
touch "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
touch "$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE"
2016-09-02 13:13:53 +02:00
touch "$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
2016-08-18 17:10:53 +02:00
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
dd if=/dev/urandom of="$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" bs=1M count=2
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$EXCLUDED_FILE"
FilePresence=(
"$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
2016-09-02 13:13:53 +02:00
"$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
2016-08-18 17:10:53 +02:00
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3"
)
DatabasePresence=(
"$DATABASE_1"
"$DATABASE_2"
)
FileExcluded=(
"$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_EXCLUDED_FILE"
)
DatabaseExcluded=(
"$DATABASE_EXCLUDED"
)
DirectoriesExcluded=(
"$RECURSIVE_DIR/$R_EXCLUDED_DIR"
)
2016-08-18 14:19:52 +02:00
}
2016-08-30 16:26:30 +02:00
function test_Merge () {
cd "$DEV_DIR"
./merge.sh
assertEquals "Merging code" "0" $?
2016-12-23 19:25:26 +01:00
# Set obackup version to stable while testing to avoid warning message
SetConfFileValue "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" "IS_STABLE" "yes"
2016-08-30 16:26:30 +02:00
}
2016-08-18 17:10:53 +02:00
2016-12-31 00:00:32 +01:00
# Keep this function to check GPG behavior depending on OS. (GPG 2.1 / GPG 2.0x / GPG 1.4 don't behave the same way)
function test_GPG () {
2016-09-04 22:20:18 +02:00
echo "Encrypting file"
2016-12-23 22:12:07 +01:00
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TESTFILE$CRYPT_EXTENSION" --recipient "John Doe" --batch --yes --encrypt "$TESTS_DIR/$PASSFILE"
2016-09-04 21:37:24 +02:00
assertEquals "Encrypt file" "0" $?
2016-12-31 00:00:32 +01:00
# Detect if GnuPG >= 2.1 that does not allow automatic pin entry anymore
cryptToolVersion=$($CRYPT_TOOL --version | head -1 | awk '{print $3}')
cryptToolMajorVersion=${cryptToolVersion%%.*}
cryptToolSubVersion=${cryptToolVersion#*.}
cryptToolSubVersion=${cryptToolSubVersion%.*}
if [ $cryptToolMajorVersion -eq 2 ] && [ $cryptToolSubVersion -ge 1 ]; then
additionalParameters="--pinentry-mode loopback"
fi
if [ "$CRYPT_TOOL" == "gpg2" ]; then
options="--batch --yes"
elif [ "$CRYPT_TOOL" == "gpg" ]; then
options="--no-use-agent --batch"
fi
2016-09-04 22:20:18 +02:00
echo "Decrypt using passphrase file"
2016-12-31 00:00:32 +01:00
$CRYPT_TOOL $options --out "$TESTS_DIR/$CRYPT_TESTFILE" --batch --yes $additionalParameters --passphrase-file="$TESTS_DIR/$PASSFILE" --decrypt "$TESTS_DIR/$CRYPT_TESTFILE$CRYPT_EXTENSION"
2016-09-04 21:37:24 +02:00
assertEquals "Decrypt file using passfile" "0" $?
2016-09-04 22:20:18 +02:00
echo "Decrypt using passphrase"
2016-12-31 00:00:32 +01:00
$CRYPT_TOOL $options --out "$TESTS_DIR/$CRYPT_TESTFILE" --batch --yes $additionalParameters --passphrase PassPhrase123 --decrypt "$TESTS_DIR/$CRYPT_TESTFILE$CRYPT_EXTENSION"
2016-09-04 21:37:24 +02:00
assertEquals "Decrypt file using passphrase" "0" $?
2016-09-04 22:20:18 +02:00
echo "Decrypt using passphrase file with cat"
2016-12-31 00:00:32 +01:00
$CRYPT_TOOL $options --out "$TESTS_DIR/$CRYPT_TESTFILE" --batch --yes $additionalParameters --passphrase $(cat "$TESTS_DIR/$PASSFILE") --decrypt "$TESTS_DIR/$CRYPT_TESTFILE$CRYPT_EXTENSION"
2016-09-04 22:20:18 +02:00
assertEquals "Decrypt file using passphrase" "0" $?
2016-09-04 21:37:24 +02:00
}
2016-12-24 13:01:31 +01:00
function test_LocalRun () {
2016-12-28 22:15:44 +01:00
SetConfFileValue "$CONF_DIR/$LOCAL_CONF" "ENCRYPTION" "no"
2016-08-18 14:19:52 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_LOCAL/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_LOCAL/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_LOCAL/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
done
2016-08-18 14:19:52 +02:00
2016-12-28 22:15:44 +01:00
diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-local/$SOURCE_DIR" | grep -i Exclu
[ $(diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-local/$SOURCE_DIR" | grep -i Exclu | wc -l) -eq 2 ]
assertEquals "Diff should only output excluded files" "0" $?
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${DatabasePresence[@]}"; do
2016-09-02 13:13:53 +02:00
[ -f "$TARGET_DIR_SQL_LOCAL/$file$ROTATE_1_EXTENSION" ]
2016-08-18 17:10:53 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
2016-08-18 14:19:52 +02:00
}
2016-08-30 19:17:14 +02:00
2016-12-24 13:01:31 +01:00
function test_PullRun () {
2016-12-28 22:15:44 +01:00
if [ "$SKIP_REMOTE" == "yes" ]; then
return 0
fi
SetConfFileValue "$CONF_DIR/$PULL_CONF" "ENCRYPTION" "no"
2016-08-18 14:19:52 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PULL/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_PULL/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_PULL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
done
2016-08-18 14:19:52 +02:00
2016-12-28 22:15:44 +01:00
diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-pull/$SOURCE_DIR" | grep -i Exclu
[ $(diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-pull/$SOURCE_DIR" | grep -i Exclu | wc -l) -eq 2 ]
assertEquals "Diff should only output excluded files" "0" $?
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${DatabasePresence[@]}"; do
2016-09-02 13:13:53 +02:00
[ -f "$TARGET_DIR_SQL_PULL/$file$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file$ROTATE_1_EXTENSION]" "0" $?
2016-08-18 17:10:53 +02:00
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
2016-08-18 14:19:52 +02:00
}
2016-12-24 13:01:31 +01:00
function test_PushRun () {
2016-12-28 22:15:44 +01:00
if [ "$SKIP_REMOTE" == "yes" ]; then
return 0
fi
SetConfFileValue "$CONF_DIR/$PUSH_CONF" "ENCRYPTION" "no"
2016-08-18 14:19:52 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
done
2016-08-18 14:19:52 +02:00
2016-12-28 22:15:44 +01:00
diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-push/$SOURCE_DIR" | grep -i Exclu
[ $(diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-push/$SOURCE_DIR" | grep -i Exclu | wc -l) -eq 2 ]
assertEquals "Diff should only output excluded files" "0" $?
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${DatabasePresence[@]}"; do
2016-09-02 13:13:53 +02:00
[ -f "$TARGET_DIR_SQL_PUSH/$file$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file$ROTATE_1_EXTENSION]" "0" $?
2016-08-18 17:10:53 +02:00
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
}
2016-12-24 13:01:31 +01:00
function test_EncryptLocalRun () {
2016-12-28 22:15:44 +01:00
SetConfFileValue "$CONF_DIR/$LOCAL_CONF" "ENCRYPTION" "yes"
2016-09-02 13:13:53 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
2016-09-02 13:13:53 +02:00
for file in "${FilePresence[@]}"; do
2016-12-28 22:15:44 +01:00
[ -f "$TARGET_DIR_CRYPT_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_CRYPT_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
done
# TODO: Exclusion lists don't work with encrypted files yet
# for file in "${FileExcluded[@]}"; do
2016-12-28 22:15:44 +01:00
# [ -f "$TARGET_DIR_CRYPT_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_CRYPT_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
2016-09-02 13:13:53 +02:00
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
2016-12-28 22:15:44 +01:00
# [ -d "$TARGET_DIR_CRYPT_LOCAL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_CRYPT_LOCAL/$directory]" "1" $?
2016-09-02 13:13:53 +02:00
# done
2016-12-28 22:15:44 +01:00
diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-local/$SOURCE_DIR" | grep -i Exclu
[ $(diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-local/$SOURCE_DIR" | grep -i Exclu | wc -l) -eq 5 ]
assertEquals "Diff should only output excluded files" "0" $?
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
2016-09-02 13:13:53 +02:00
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
done
2016-12-28 22:15:44 +01:00
[ -d "$TARGET_DIR_CRYPT_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_CRYPT_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt sql storage in [$TARGET_DIR_SQL_LOCAL]" "0" $?
2016-09-02 13:13:53 +02:00
2016-12-28 22:15:44 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_CRYPT_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage in [$TARGET_DIR_CRYPT_LOCAL]" "0" $?
2016-09-02 13:13:53 +02:00
}
2016-12-24 13:01:31 +01:00
function test_EncryptPullRun () {
2016-12-28 22:15:44 +01:00
if [ "$SKIP_REMOTE" == "yes" ]; then
return 0
fi
2016-09-02 13:13:53 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-12-28 22:15:44 +01:00
SetConfFileValue "$CONF_DIR/$PULL_CONF" "ENCRYPTION" "yes"
2016-09-02 13:13:53 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
2016-09-02 13:13:53 +02:00
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
2016-12-28 22:15:44 +01:00
[ -f "$TARGET_DIR_CRYPT_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_CRYPT_PULL/$file$CRYPT_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
done
# for file in "${FileExcluded[@]}"; do
2016-12-28 22:15:44 +01:00
# [ -f "$TARGET_DIR_CRYPT_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_CRYPT_PULL/$file$CRYPT_EXTENSION]" "1" $?
2016-09-02 13:13:53 +02:00
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PULL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
# done
2016-12-28 22:15:44 +01:00
# Only excluded files should be listed here
diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-pull/$SOURCE_DIR" | grep -i Exclu
[ $(diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-pull/$SOURCE_DIR" | grep -i Exclu | wc -l) -eq 2 ]
assertEquals "Diff should only output excluded files" "0" $?
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
2016-09-02 13:13:53 +02:00
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
2016-09-03 14:18:03 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
done
2016-09-02 16:08:23 +02:00
[ -d "$TARGET_DIR_FILE_CRYPT/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_CRYPT/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt sql storage in [$TARGET_DIR_SQL_PULL]" "0" $?
2016-09-02 13:13:53 +02:00
2016-12-28 22:15:44 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_CRYPT_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage in [$TARGET_DIR_CRYPT_PULL]" "0" $?
2016-09-02 13:13:53 +02:00
}
2016-12-24 13:01:31 +01:00
function test_EncryptPushRun () {
2016-12-28 22:15:44 +01:00
if [ "$SKIP_REMOTE" == "yes" ]; then
return 0
fi
2016-09-02 13:13:53 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-12-28 22:15:44 +01:00
SetConfFileValue "$CONF_DIR/$PUSH_CONF" "ENCRYPTION" "yes"
2016-09-02 13:13:53 +02:00
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
2016-09-02 13:13:53 +02:00
assertEquals "Return code" "0" $?
2016-12-28 22:15:44 +01:00
# Same here, why do we check for crypt extension in file_push instead of file_crypt
2016-09-02 13:13:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
# done
2016-12-28 22:15:44 +01:00
diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-push/$SOURCE_DIR" | grep -i Exclu
[ $(diff -qr "$SOURCE_DIR" "$TARGET_DIR/files-push/$SOURCE_DIR" | grep -i Exclu | wc -l) -eq 5 ]
assertEquals "Diff should only output excluded files" "0" $?
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
cd "$OBACKUP_DIR"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
2016-09-02 13:13:53 +02:00
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-12-28 22:15:44 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PUSH" --passphrase-file="$TESTS_DIR/$PASSFILE" --verbose
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt sql storage in [$TARGET_DIR_SQL_PUSH]" "0" $?
2016-09-02 13:13:53 +02:00
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_PUSH" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt file storage in [$TARGET_DIR_FILE_PUSH]" "0" $?
2016-08-18 14:19:52 +02:00
}
2016-12-28 22:20:59 +01:00
function test_timed_execution () {
2016-12-23 22:25:15 +01:00
cd "$OBACKUP_DIR"
2016-12-23 22:29:02 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_DB_TASK" 1
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_TOTAL" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_TOTAL" 1000
2016-12-24 12:43:37 +01:00
SLEEP_TIME=2 REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$MAX_EXEC_CONF"
2016-12-23 21:46:43 +01:00
assertEquals "Soft max exec time db reached in obackup Return code" "2" $?
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_DB_TASK" 1000
2016-12-23 22:29:02 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_DB_TASK" 1
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_TOTAL" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_TOTAL" 1000
2016-12-24 12:43:37 +01:00
SLEEP_TIME=2 REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$MAX_EXEC_CONF"
2016-12-23 21:46:43 +01:00
assertEquals "Hard max exec time db reached in obackup Return code" "1" $?
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_DB_TASK" 1000
2016-12-23 22:29:02 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_FILE_TASK" 1
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_TOTAL" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_TOTAL" 1000
2016-12-24 12:43:37 +01:00
SLEEP_TIME=2 REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$MAX_EXEC_CONF"
2016-12-23 21:46:43 +01:00
assertEquals "Soft max exec time file reached in obackup Return code" "2" $?
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_FILE_TASK" 1000
2016-12-23 22:29:02 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_FILE_TASK" 1
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_TOTAL" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_TOTAL" 1000
2016-12-24 12:43:37 +01:00
SLEEP_TIME=2 REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$MAX_EXEC_CONF"
2016-12-23 21:46:43 +01:00
assertEquals "Hard max exec time file reached in obackup Return code" "1" $?
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_FILE_TASK" 1000
2016-12-23 22:29:02 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_TOTAL" 1
2016-12-23 21:46:43 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_TOTAL" 1000
2016-12-23 22:29:02 +01:00
SLEEP_TIME=1.5 REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$MAX_EXEC_CONF"
2016-12-23 21:46:43 +01:00
assertEquals "Soft max exec time total reached in obackup Return code" "2" $?
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_DB_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_FILE_TASK" 1000
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "SOFT_MAX_EXEC_TIME_TOTAL" 1000
2016-12-23 22:29:02 +01:00
SetConfFileValue "$CONF_DIR/$MAX_EXEC_CONF" "HARD_MAX_EXEC_TIME_TOTAL" 1
2016-12-23 21:46:43 +01:00
2016-12-24 12:43:37 +01:00
SLEEP_TIME=2 REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$MAX_EXEC_CONF"
2016-12-23 21:46:43 +01:00
assertEquals "Hard max exec time total reached in obackup Return code" "1" $?
2016-12-23 20:43:58 +01:00
}
2016-12-28 22:20:59 +01:00
function test_WaitForTaskCompletion () {
2016-11-30 13:59:01 +01:00
local pids
2016-08-18 22:38:28 +02:00
# Standard wait
2016-09-04 08:07:17 +02:00
sleep 1 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 2 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-11-30 13:59:01 +01:00
WaitForTaskCompletion $pids 0 0 $SLEEP_TIME $KEEP_LOGGING true true false ${FUNCNAME[0]}
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 1" "0" $?
2016-08-18 22:38:28 +02:00
# Standard wait with warning
2016-09-04 08:07:17 +02:00
sleep 2 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-11-30 13:59:01 +01:00
WaitForTaskCompletion $pids 3 0 $SLEEP_TIME $KEEP_LOGGING true true false ${FUNCNAME[0]}
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 2" "0" $?
2016-08-18 22:38:28 +02:00
# Both pids are killed
2016-09-04 08:07:17 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-11-30 13:59:01 +01:00
WaitForTaskCompletion $pids 0 2 $SLEEP_TIME $KEEP_LOGGING true true false ${FUNCNAME[0]}
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 3" "2" $?
2016-08-18 22:38:28 +02:00
# One of two pids are killed
2016-09-04 08:07:17 +02:00
sleep 2 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-08-18 17:10:53 +02:00
sleep 10 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-11-30 13:59:01 +01:00
WaitForTaskCompletion $pids 0 3 $SLEEP_TIME $KEEP_LOGGING true true false ${FUNCNAME[0]}
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 4" "1" $?
2016-08-18 22:38:28 +02:00
# Count since script begin, the following should output two warnings and both pids should get killed
2016-09-04 08:07:17 +02:00
sleep 20 &
2016-08-18 22:38:28 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 20 &
2016-08-18 22:38:28 +02:00
pids="$pids;$!"
2016-11-30 13:59:01 +01:00
WaitForTaskCompletion $pids 3 5 $SLEEP_TIME $KEEP_LOGGING false true false ${FUNCNAME[0]}
2016-08-18 22:38:28 +02:00
assertEquals "WaitForTaskCompletion test 5" "2" $?
2016-08-18 14:19:52 +02:00
}
2016-12-28 22:20:59 +01:00
function test_ParallelExec () {
2016-11-30 13:59:01 +01:00
local cmd
# Test if parallelExec works correctly in array mode
2016-08-30 21:50:04 +02:00
2016-09-02 13:13:53 +02:00
cmd="sleep 2;sleep 2;sleep 2;sleep 2"
2016-08-30 21:50:04 +02:00
ParallelExec 4 "$cmd"
assertEquals "ParallelExec test 1" "0" $?
2016-09-02 13:13:53 +02:00
cmd="sleep 2;du /none;sleep 2"
2016-08-30 21:50:04 +02:00
ParallelExec 2 "$cmd"
assertEquals "ParallelExec test 2" "1" $?
2016-09-02 13:13:53 +02:00
cmd="sleep 4;du /none;sleep 3;du /none;sleep 2"
2016-08-30 21:50:04 +02:00
ParallelExec 3 "$cmd"
assertEquals "ParallelExec test 3" "2" $?
2016-11-30 13:59:01 +01:00
# Test if parallelExec works correctly in file mode
echo "sleep 2" > "$TMP_FILE"
echo "sleep 2" >> "$TMP_FILE"
echo "sleep 2" >> "$TMP_FILE"
echo "sleep 2" >> "$TMP_FILE"
ParallelExec 4 "$TMP_FILE" true
assertEquals "ParallelExec test 4" "0" $?
echo "sleep 2" > "$TMP_FILE"
echo "du /nome" >> "$TMP_FILE"
echo "sleep 2" >> "$TMP_FILE"
ParallelExec 2 "$TMP_FILE" true
assertEquals "ParallelExec test 5" "1" $?
echo "sleep 4" > "$TMP_FILE"
echo "du /none" >> "$TMP_FILE"
echo "sleep 3" >> "$TMP_FILE"
echo "du /none" >> "$TMP_FILE"
echo "sleep 2" >> "$TMP_FILE"
ParallelExec 3 "$TMP_FILE" true
assertEquals "ParallelExec test 6" "2" $?
#function ParallelExec $numberOfProcesses $commandsArg $readFromFile $softTime $HardTime $sleepTime $keepLogging $counting $Spinner $noError $callerName
# Test if parallelExec works correctly in array mode with full time control
cmd="sleep 5;sleep 5;sleep 5;sleep 5;sleep 5"
ParallelExec 4 "$cmd" false 1 0 .05 3600 true true false ${FUNCNAME[0]}
assertEquals "ParallelExec full test 1" "0" $?
cmd="sleep 2;du /none;sleep 2;sleep 2;sleep 4"
ParallelExec 2 "$cmd" false 0 0 .1 2 true false false ${FUNCNAME[0]}
assertEquals "ParallelExec full test 2" "1" $?
cmd="sleep 4;du /none;sleep 3;du /none;sleep 2"
ParallelExec 3 "$cmd" false 1 2 .05 7000 true true false ${FUNCNAME[0]}
assertNotEquals "ParallelExec full test 3" "0" $?
2016-08-30 21:50:04 +02:00
}
2016-12-28 22:20:59 +01:00
function test_UpgradeConfPullRun () {
2016-09-09 12:36:30 +02:00
# Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR"
2016-10-23 19:00:03 +02:00
# Make a security copy of the old config file
cp "$CONF_DIR/$OLD_CONF" "$CONF_DIR/$TMP_OLD_CONF"
./$OBACKUP_UPGRADE "$CONF_DIR/$TMP_OLD_CONF"
2016-09-09 12:36:30 +02:00
assertEquals "Conf file upgrade" "0" $?
2016-12-23 21:29:02 +01:00
# Update remote conf files with SSH port
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/#' "$CONF_DIR/$TMP_OLD_CONF"
2016-12-23 20:43:58 +01:00
REMOTE_HOST_PING=$RHOST_PING ./$OBACKUP_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF"
2016-09-09 12:36:30 +02:00
assertEquals "Upgraded conf file execution test" "0" $?
2016-10-23 19:00:03 +02:00
rm -f "$CONF_DIR/$TMP_OLD_CONF"
rm -f "$CONF_DIR/$TMP_OLD_CONF.save"
2016-09-09 12:36:30 +02:00
}
2016-08-30 16:12:10 +02:00
. "$TESTS_DIR/shunit2/shunit2"
2016-09-03 14:18:03 +02:00