2016-09-05 20:21:25 +00:00
#!/usr/bin/env bash
2020-04-29 10:19:49 +00:00
# osync test suite 2020042901
2019-01-02 19:19:24 +00:00
2018-10-02 19:27:12 +00:00
# Allows the following environment variables
# TRAVIS_RUN=[true|false]
# SSH_PORT=22
# SKIP_REMOTE=[true|false]
2016-11-21 15:33:22 +00:00
## On Mac OSX, this needs to be run as root in order to use sudo without password
## From current terminal run sudo -s in order to get a new terminal as root
2016-11-24 12:26:10 +00:00
## On CYGWIN / MSYS, ACL and extended attributes aren't supported
2016-09-06 17:26:37 +00:00
# 4 tests:
# quicklocal
2017-02-08 14:03:18 +00:00
# quickremote (with ssh_filter.sh)
2016-09-06 17:26:37 +00:00
# conflocal
2017-02-08 14:03:18 +00:00
# confremote (with ssh_filter.sh)
2016-09-06 17:26:37 +00:00
2017-02-08 14:03:18 +00:00
# for each test
2016-11-17 11:15:24 +00:00
# files with spaces, subdirs
# largefileset (...large ?)
2019-07-05 21:00:03 +00:00
# quickremote test with controlmaster enabled
2016-11-17 11:15:24 +00:00
# exclusions
# conflict resolution initiator with backups / multiple backups
# conflict resolution target with backups / multiple backups
# deletion propagation, failed deletion repropagation, skip deletion
2016-12-04 17:57:39 +00:00
# symlink and broken symlink propagation and deletion
2016-11-17 11:15:24 +00:00
# replica lock checks
# file attribute tests
# local / remote locking resume tests
2018-06-30 17:46:11 +00:00
# conflict detection
2016-11-29 21:40:10 +00:00
# timed execution tests
2016-11-17 11:15:24 +00:00
# function test
# WaitForTaskCompletion
# ParallelExec
2016-11-17 22:40:17 +00:00
# daemon mode tests for both config files
2016-09-06 17:26:37 +00:00
2016-11-30 12:02:01 +00:00
# on BSD, remount UFS with ACL support using mount -o acls /
2016-11-20 20:47:56 +00:00
# setfacl needs double ':' to be compatible with both linux and BSD
# setfacl -m o::rwx file
2016-11-20 19:56:47 +00:00
2019-05-22 18:30:27 +00:00
# On Windows 10 bash, we need to create host SSH keys first with ssh-keygen -A
# Then start ssh with service ssh start
2019-05-20 19:56:01 +00:00
# TODO, use copies of config file on each test function
2018-10-02 19:27:12 +00:00
if [ " $SKIP_REMOTE " = "" ] ; then
SKIP_REMOTE = false
fi
2016-12-05 19:03:53 +00:00
# drupal servers are often unreachable for whetever reason or give 0 bytes files
#LARGE_FILESET_URL="http://ftp.drupal.org/files/projects/drupal-8.2.2.tar.gz"
2018-05-18 10:29:39 +00:00
LARGE_FILESET_URL = "http://www.netpower.fr/sites/default/files/osync-test-files.tar.gz"
2016-09-16 07:51:29 +00:00
2018-06-30 17:46:11 +00:00
# Fakeroot for install / uninstall and test of executables
2018-07-02 13:34:53 +00:00
FAKEROOT = " ${ HOME } /osync_test_install "
2018-06-30 17:46:11 +00:00
2016-09-05 20:21:25 +00:00
OSYNC_DIR = " $( pwd ) "
OSYNC_DIR = ${ OSYNC_DIR %%/dev* }
DEV_DIR = " $OSYNC_DIR /dev "
TESTS_DIR = " $DEV_DIR /tests "
2016-12-06 08:23:43 +00:00
CONF_DIR = " $TESTS_DIR /conf "
2016-10-23 17:17:25 +00:00
LOCAL_CONF = "local.conf"
REMOTE_CONF = "remote.conf"
OLD_CONF = "old.conf"
TMP_OLD_CONF = "tmp.old.conf"
2018-06-30 17:46:11 +00:00
OSYNC_EXECUTABLE = " $FAKEROOT /usr/local/bin/osync.sh "
2016-11-16 10:46:09 +00:00
OSYNC_DEV_EXECUTABLE = "dev/n_osync.sh"
2019-01-10 23:34:12 +00:00
OSYNC_UPGRADE = "upgrade-v1.0x-v1.3x.sh"
2016-09-06 17:26:37 +00:00
TMP_FILE = " $DEV_DIR /tmp "
2016-09-05 20:21:25 +00:00
2016-11-15 20:29:12 +00:00
OSYNC_TESTS_DIR = " ${ HOME } /osync-tests "
INITIATOR_DIR = " $OSYNC_TESTS_DIR /initiator "
TARGET_DIR = " $OSYNC_TESTS_DIR /target "
2016-09-16 15:19:04 +00:00
OSYNC_WORKDIR = ".osync_workdir"
OSYNC_STATE_DIR = " $OSYNC_WORKDIR /state "
2016-10-17 14:45:02 +00:00
OSYNC_DELETE_DIR = " $OSYNC_WORKDIR /deleted "
OSYNC_BACKUP_DIR = " $OSYNC_WORKDIR /backup "
2016-09-05 20:21:25 +00:00
2016-11-16 10:46:09 +00:00
# Later populated variables
OSYNC_VERSION = 1.x.y
OSYNC_MIN_VERSION = x
OSYNC_IS_STABLE = maybe
2016-09-05 20:21:25 +00:00
function SetupSSH {
2019-07-19 14:45:54 +00:00
echo -e 'y\n' | ssh-keygen -t rsa -b 2048 -N "" -f " ${ HOME } /.ssh/id_rsa_local_osync_tests "
SSH_AUTH_LINE = " from=\"*\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command=\" $FAKEROOT /usr/local/bin/ssh_filter.sh SomeAlphaNumericToken9\" $( cat ${ HOME } /.ssh/id_rsa_local_osync_tests.pub) "
if ! grep " $( cat ${ HOME } /.ssh/id_rsa_local_osync_tests.pub) " " ${ HOME } /.ssh/authorized_keys " ; then
echo " $SSH_AUTH_LINE " >> " ${ HOME } /.ssh/authorized_keys "
#echo "from=\"*\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command=\"$FAKEROOT/usr/local/bin/ssh_filter.sh SomeAlphaNumericToken9\" $(cat ${HOME}/.ssh/id_rsa_local_osync_tests.pub)" >> "${HOME}/.ssh/authorized_keys"
2016-11-20 17:18:07 +00:00
fi
2016-09-05 20:21:25 +00:00
chmod 600 " ${ HOME } /.ssh/authorized_keys "
# Add localhost to known hosts so self connect works
2016-11-20 17:18:07 +00:00
if [ -z " $( ssh-keygen -F localhost) " ] ; then
ssh-keyscan -H localhost >> " ${ HOME } /.ssh/known_hosts "
2016-09-05 20:21:25 +00:00
fi
2016-12-05 19:03:53 +00:00
# Update remote conf files with SSH port
2016-12-06 08:23:43 +00:00
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/${HOME}/osync-tests/target#ssh://' $REMOTE_USER '@localhost:' $SSH_PORT '/${HOME}/osync-tests/target#' " $CONF_DIR / $REMOTE_CONF "
2016-09-05 20:21:25 +00:00
}
2016-11-19 13:21:42 +00:00
function RemoveSSH {
2019-07-19 14:45:54 +00:00
if [ -f " ${ HOME } /.ssh/id_rsa_local_osync_tests " ] ; then
echo "Restoring SSH authorized_keys file"
sed -i.bak " s|.* $( cat " ${ HOME } /.ssh/id_rsa_local_osync_tests.pub " ) ||g " " ${ HOME } /.ssh/authorized_keys "
rm -f " ${ HOME } /.ssh/{id_rsa_local_osync_tests.pub,id_rsa_local_osync_tests} "
2016-11-19 13:21:42 +00:00
fi
}
2016-09-16 07:51:29 +00:00
function DownloadLargeFileSet( ) {
local destinationPath = " ${ 1 } "
cd " $OSYNC_DIR "
2016-11-20 17:04:32 +00:00
if type wget > /dev/null 2>& 1; then
wget -q --no-check-certificate " $LARGE_FILESET_URL " > /dev/null
assertEquals " Download [ $LARGE_FILESET_URL ] with wget. " "0" $?
elif type curl > /dev/null 2>& 1; then
curl -O -L " $LARGE_FILESET_URL " > /dev/null 2>& 1
assertEquals " Download [ $LARGE_FILESET_URL ] with curl. " "0" $?
fi
2016-09-16 07:51:29 +00:00
2016-11-20 17:04:32 +00:00
tar xf " $( basename $LARGE_FILESET_URL ) " -C " $destinationPath "
2016-09-16 07:51:29 +00:00
assertEquals " Extract $( basename $LARGE_FILESET_URL ) " "0" $?
2016-10-17 14:45:02 +00:00
rm -f " $( basename $LARGE_FILESET_URL ) "
2016-09-16 07:51:29 +00:00
}
function CreateOldFile ( ) {
2016-11-13 13:12:51 +00:00
local drive
2016-09-16 07:51:29 +00:00
local filePath = " ${ 1 } "
2016-12-12 22:58:42 +00:00
local type = " ${ 2 :- false } "
if [ $type = = true ] ; then
mkdir -p " $filePath "
else
mkdir -p " $( dirname $filePath ) "
touch " $filePath "
fi
2016-09-16 07:51:29 +00:00
2016-11-13 13:12:51 +00:00
assertEquals " touch [ $filePath ] " "0" $?
# Get current drive
2016-12-11 19:54:40 +00:00
drive = $( df " $OSYNC_DIR " | tail -1 | awk '{print $1}' )
2016-11-13 13:12:51 +00:00
# modify ctime on ext4 so osync thinks it has to delete the old files
2016-11-13 15:23:04 +00:00
debugfs -w -R 'set_inode_field "' $filePath '" ctime 201001010101' $drive
2016-09-16 07:51:29 +00:00
assertEquals " CreateOldFile [ $filePath ] " "0" $?
2016-11-13 13:12:51 +00:00
# force update of inodes (ctimes)
echo 3 > /proc/sys/vm/drop_caches
2016-09-16 07:51:29 +00:00
assertEquals "Drop caches" "0" $?
}
function PrepareLocalDirs ( ) {
2018-10-07 12:43:31 +00:00
if [ -d " $OSYNC_TESTS_DIR " ] ; then
rm -rf " $OSYNC_TESTS_DIR "
2016-09-05 20:21:25 +00:00
fi
2018-10-07 12:43:31 +00:00
mkdir " $OSYNC_TESTS_DIR "
mkdir " $INITIATOR_DIR "
mkdir " $TARGET_DIR "
2016-09-05 20:21:25 +00:00
}
2016-09-05 20:25:25 +00:00
function oneTimeSetUp ( ) {
2016-11-17 22:48:06 +00:00
START_TIME = $SECONDS
2018-06-30 17:46:11 +00:00
mkdir --parents " $FAKEROOT "
2016-09-05 20:25:25 +00:00
source " $DEV_DIR /ofunctions.sh "
2017-04-08 20:05:22 +00:00
# Fix default umask because of ACL test that expects 0022 when creating test files
umask 0022
2016-11-20 19:56:47 +00:00
GetLocalOS
2016-12-05 19:06:00 +00:00
echo " Detected OS: $LOCAL_OS "
2016-12-06 08:23:43 +00:00
# Set some travis related changes
if [ " $TRAVIS_RUN " = = true ] ; then
echo "Running with travis settings"
REMOTE_USER = "travis"
2019-01-10 23:34:12 +00:00
RHOST_PING = false
2016-12-06 08:23:43 +00:00
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "REMOTE_3RD_PARTY_HOSTS" ""
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "REMOTE_HOST_PING" false
2016-12-23 20:37:06 +00:00
SetConfFileValue " $CONF_DIR / $OLD_CONF " "REMOTE_3RD_PARTY_HOSTS" ""
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $OLD_CONF " "REMOTE_HOST_PING" false
2016-12-06 08:23:43 +00:00
else
echo "Running with local settings"
REMOTE_USER = "root"
2019-01-10 23:34:12 +00:00
RHOST_PING = true
2016-12-06 13:00:48 +00:00
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "REMOTE_3RD_PARTY_HOSTS" "\"www.kernel.org www.google.com\""
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "REMOTE_HOST_PING" true
2016-12-23 20:37:06 +00:00
SetConfFileValue " $CONF_DIR / $OLD_CONF " "REMOTE_3RD_PARTY_HOSTS" "\"www.kernel.org www.google.com\""
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $OLD_CONF " "REMOTE_HOST_PING" true
2016-12-06 08:23:43 +00:00
fi
# Get default ssh port from env
if [ " $SSH_PORT " = = "" ] ; then
SSH_PORT = 22
fi
2016-11-22 18:24:51 +00:00
# Setup modes per test
readonly __quickLocal = 0
readonly __quickRemote = 1
readonly __confLocal = 2
readonly __confRemote = 3
osyncParameters = ( )
2018-10-14 17:14:22 +00:00
osyncParameters[ $__quickLocal ] = " --initiator= $INITIATOR_DIR --target= $TARGET_DIR --instance-id=quicklocal "
2019-01-02 19:54:57 +00:00
osyncParameters[ $__confLocal ] = " $CONF_DIR / $LOCAL_CONF "
2016-11-22 18:24:51 +00:00
osyncDaemonParameters = ( )
readonly __local
readonly __remote
osyncDaemonParameters[ $__local ] = " $CONF_DIR / $LOCAL_CONF --on-changes "
2018-06-30 17:46:11 +00:00
# Do not check remote config on msys or cygwin since we don't have a local SSH server
2018-10-02 19:27:12 +00:00
if [ " $LOCAL_OS " != "msys" ] && [ " $LOCAL_OS " != "Cygwin" ] && [ $SKIP_REMOTE != true ] ; then
2019-07-23 08:39:40 +00:00
osyncParameters[ $__quickRemote ] = " --initiator= $INITIATOR_DIR --target=ssh://localhost: $SSH_PORT / $TARGET_DIR --rsakey= ${ HOME } /.ssh/id_rsa_local_osync_tests --instance-id=quickremote --remote-token=SomeAlphaNumericToken9 "
2019-01-02 19:54:57 +00:00
osyncParameters[ $__confRemote ] = " $CONF_DIR / $REMOTE_CONF "
2016-11-22 18:24:51 +00:00
osyncDaemonParameters[ $__remote ] = " $CONF_DIR / $REMOTE_CONF --on-changes "
SetupSSH
fi
2016-11-20 19:56:47 +00:00
#TODO: Assuming that macos has the same syntax than bsd here
2017-02-08 13:54:03 +00:00
if [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
2017-02-08 13:53:18 +00:00
SUDO_CMD = ""
elif [ " $LOCAL_OS " = = "BSD" ] || [ " $LOCAL_OS " = = "MacOSX" ] ; then
2016-11-21 09:04:00 +00:00
SUDO_CMD = ""
2016-11-20 19:56:47 +00:00
IMMUTABLE_ON_CMD = "chflags schg"
IMMUTABLE_OFF_CMD = "chflags noschg"
else
IMMUTABLE_ON_CMD = "chattr +i"
IMMUTABLE_OFF_CMD = "chattr -i"
2016-11-21 09:04:00 +00:00
SUDO_CMD = "sudo"
2016-11-20 19:56:47 +00:00
fi
2016-11-15 21:56:02 +00:00
# Get osync version
2016-11-16 10:46:09 +00:00
OSYNC_VERSION = $( GetConfFileValue " $OSYNC_DIR / $OSYNC_DEV_EXECUTABLE " "PROGRAM_VERSION" )
2016-11-15 21:56:02 +00:00
OSYNC_VERSION = " ${ OSYNC_VERSION ##*= } "
OSYNC_MIN_VERSION = " ${ OSYNC_VERSION : 2 : 1 } "
2016-11-16 10:46:09 +00:00
OSYNC_IS_STABLE = $( GetConfFileValue " $OSYNC_DIR / $OSYNC_DEV_EXECUTABLE " "IS_STABLE" )
echo " Running with $OSYNC_VERSION ( $OSYNC_MIN_VERSION ) STABLE= $OSYNC_IS_STABLE "
2016-12-04 17:57:39 +00:00
# Be sure to set default values for config files which can be incoherent if tests gets aborted
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "SKIP_DELETION" ""
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "SKIP_DELETION" ""
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "COPY_SYMLINKS" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "COPY_SYMLINKS" false
2016-12-04 17:57:39 +00:00
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "CONFLICT_BACKUP_MULTIPLE" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "CONFLICT_BACKUP_MULTIPLE" false
2016-12-04 17:57:39 +00:00
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "FORCE_STRANGER_LOCK_RESUME" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "FORCE_STRANGER_LOCK_RESUME" false
2016-12-04 17:57:39 +00:00
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "SOFT_MAX_EXEC_TIME" "7200"
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "HARD_MAX_EXEC_TIME" "10600"
2016-09-05 20:25:25 +00:00
}
function oneTimeTearDown ( ) {
2018-07-02 12:44:16 +00:00
2016-11-16 10:46:09 +00:00
# Set osync version stable flag back to origin
2018-07-02 12:44:16 +00:00
#SetConfFileValue "$OSYNC_DIR/osync.sh" "IS_STABLE" "$OSYNC_IS_STABLE"
2016-11-16 10:46:09 +00:00
2018-10-02 19:27:12 +00:00
if [ " $SKIP_REMOTE " != true ] ; then
RemoveSSH
fi
2016-11-19 13:21:42 +00:00
2016-11-16 10:46:09 +00:00
#TODO: uncomment this when dev is done
2016-11-20 16:22:03 +00:00
#rm -rf "$OSYNC_TESTS_DIR"
2016-12-08 19:36:13 +00:00
rm -f " $TMP_FILE "
2016-11-17 22:48:06 +00:00
2017-02-08 13:06:43 +00:00
cd " $OSYNC_DIR "
2018-06-30 17:46:11 +00:00
echo ""
echo " Uninstalling osync from $FAKEROOT "
$SUDO_CMD ./install.sh --remove --no-stats --prefix= " $FAKEROOT "
2017-02-08 13:06:43 +00:00
assertEquals "Uninstall failed" "0" $?
2019-05-22 18:30:27 +00:00
ELAPSED_TIME = $(( SECONDS-START_TIME))
2016-11-17 22:48:06 +00:00
echo " It took $ELAPSED_TIME seconds to run these tests. "
2016-09-05 20:25:25 +00:00
}
2016-10-23 17:17:25 +00:00
function setUp ( ) {
2016-12-11 19:54:40 +00:00
rm -rf " $INITIATOR_DIR "
rm -rf " $TARGET_DIR "
2016-10-23 17:17:25 +00:00
}
2016-11-15 20:29:12 +00:00
# This test has to be done everytime in order for osync executable to be fresh
2019-07-19 14:46:42 +00:00
function test_Merge ( ) {
2016-09-05 20:21:25 +00:00
cd " $DEV_DIR "
2017-06-19 14:01:47 +00:00
./merge.sh osync
2016-09-05 20:21:25 +00:00
assertEquals "Merging code" "0" $?
2016-11-16 10:46:09 +00:00
2018-10-07 10:25:53 +00:00
#WIP use debug code
alias cp = cp
cp " $DEV_DIR /debug_osync.sh " " $OSYNC_DIR /osync.sh "
2017-02-08 13:06:43 +00:00
cd " $OSYNC_DIR "
2018-07-02 08:12:16 +00:00
2018-07-02 13:12:02 +00:00
echo ""
echo " Installing osync to $FAKEROOT "
$SUDO_CMD ./install.sh --no-stats --prefix= " $FAKEROOT "
2018-07-02 08:12:16 +00:00
# Set osync version to stable while testing to avoid warning message
2018-07-02 12:44:16 +00:00
# Don't use SetConfFileValue here since for whatever reason Travis does not like creating a sed temporary file in $FAKEROOT
2018-07-02 13:15:39 +00:00
2018-07-02 13:37:35 +00:00
if [ " $TRAVIS_RUN " = = true ] ; then
2019-01-10 23:34:12 +00:00
$SUDO_CMD sed -i.tmp 's/^IS_STABLE=.*/IS_STABLE=true/' " $OSYNC_EXECUTABLE "
2018-07-02 13:37:35 +00:00
else
2019-01-10 23:34:12 +00:00
sed -i.tmp 's/^IS_STABLE=.*/IS_STABLE=true/' " $OSYNC_EXECUTABLE "
2018-07-02 13:37:35 +00:00
fi
2019-01-10 23:34:12 +00:00
#SetConfFileValue "$OSYNC_EXECUTABLE" "IS_STABLE" true
2018-07-02 08:12:16 +00:00
2018-07-02 13:12:02 +00:00
2017-02-08 13:06:43 +00:00
assertEquals "Install failed" "0" $?
2016-09-05 20:21:25 +00:00
}
2019-07-19 14:46:42 +00:00
function test_LargeFileSet ( ) {
2016-09-16 07:51:29 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DownloadLargeFileSet " $INITIATOR_DIR "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-09-16 07:51:29 +00:00
assertEquals " LargeFileSet test with parameters [ $i ]. " "0" $?
2016-11-13 19:22:52 +00:00
[ -d " $INITIATOR_DIR / $OSYNC_STATE_DIR " ]
assertEquals "Initiator state dir exists" "0" $?
[ -d " $TARGET_DIR / $OSYNC_STATE_DIR " ]
assertEquals "Target state dir exists" "0" $?
2016-09-16 07:51:29 +00:00
done
}
2019-07-19 14:46:42 +00:00
function test_controlMaster ( ) {
2019-07-05 21:00:03 +00:00
cd " $OSYNC_DIR "
PrepareLocalDirs
2019-07-19 14:45:54 +00:00
echo " Running with parameters ${ osyncParameters [ $__quickRemote ] } --ssh-controlmaster "
REMOTE_HOST_PING = $REMOTE_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__quickRemote ] } --ssh-controlmaster
2019-07-05 21:00:03 +00:00
assertEquals "Running quick remote test with controlmaster enabled." "0" $?
}
2019-07-19 14:46:42 +00:00
function test_Exclusions ( ) {
2016-11-13 13:12:51 +00:00
# Will sync except php files
# RSYNC_EXCLUDE_PATTERN="*.php" is set at runtime for quicksync and in config files for other runs
2016-09-16 07:51:29 +00:00
local numberOfPHPFiles
local numberOfExcludedFiles
2016-09-16 08:16:18 +00:00
local numberOfInitiatorFiles
local numberOfTargetFiles
2016-09-16 07:51:29 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DownloadLargeFileSet " $INITIATOR_DIR "
2016-09-16 15:19:04 +00:00
numberOfPHPFiles = $( find " $INITIATOR_DIR " ! -wholename " $INITIATOR_DIR / $OSYNC_WORKDIR * " -name "*.php" | wc -l)
2016-09-16 07:51:29 +00:00
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING RSYNC_EXCLUDE_PATTERN = "*.php" $OSYNC_EXECUTABLE $i
2016-09-16 07:51:29 +00:00
assertEquals " Exclusions with parameters [ $i ]. " "0" $?
2016-09-16 15:19:04 +00:00
numberOfInitiatorFiles = $( find " $INITIATOR_DIR " ! -wholename " $INITIATOR_DIR / $OSYNC_WORKDIR * " | wc -l)
numberOfTargetFiles = $( find " $TARGET_DIR " ! -wholename " $TARGET_DIR / $OSYNC_WORKDIR * " | wc -l)
2016-09-16 08:16:18 +00:00
numberOfExcludedFiles = $(( numberOfInitiatorFiles-numberOfTargetFiles))
2016-09-16 07:51:29 +00:00
assertEquals " Number of php files: $numberOfPHPFiles - Number of excluded files: $numberOfExcludedFiles " $numberOfPHPFiles $numberOfExcludedFiles
done
}
2019-07-19 14:46:42 +00:00
function test_Deletetion ( ) {
2019-05-18 11:39:32 +00:00
local iFile1 = " $INITIATOR_DIR /i fic "
2020-04-29 10:19:49 +00:00
local iFile2 = " $INITIATOR_DIR /i foc (something) "
2019-05-18 11:39:32 +00:00
local tFile1 = " $TARGET_DIR /t fic "
2020-04-29 10:19:49 +00:00
local tFile2 = " $TARGET_DIR /t foc [nothing] "
2016-10-17 14:45:02 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
touch " $iFile1 "
touch " $iFile2 "
touch " $tFile1 "
touch " $tFile2 "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-10-17 14:45:02 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
rm -f " $iFile1 "
rm -f " $tFile1 "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-10-17 14:45:02 +00:00
assertEquals " Second deletion run with parameters [ $i ]. " "0" $?
2016-11-13 19:22:52 +00:00
[ -f " $TARGET_DIR / $OSYNC_DELETE_DIR / $( basename $iFile1 ) " ]
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $( basename $iFile1 ) ] has been soft deleted on target " "0" $?
2016-10-17 14:45:02 +00:00
[ -f " $iFile1 " ]
assertEquals " File [ $iFile1 ] is still in initiator " "1" $?
2016-11-15 21:56:02 +00:00
# The variable substitution is not the best comprehensible code
2016-10-17 14:45:02 +00:00
[ -f " ${ iFile1 / $INITIATOR_DIR /TARGET_DIR } " ]
assertEquals " File [ ${ iFile1 / $INITIATOR_DIR /TARGET_DIR } ] is still in target " "1" $?
2016-11-13 19:22:52 +00:00
[ -f " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $( basename $tFile1 ) " ]
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $( basename $tFile1 ) ] has been soft deleted on initiator " "0" $?
2016-10-17 14:45:02 +00:00
[ -f " $tFile1 " ]
assertEquals " File [ $tFile1 ] is still in target " "1" $?
2016-11-15 21:56:02 +00:00
2016-10-17 14:45:02 +00:00
[ -f " ${ tFile1 / $TARGET_DIR /INITIATOR_DIR } " ]
assertEquals " File [ ${ tFile1 / $TARGET_DIR /INITIATOR_DIR } ] is still in initiator " "1" $?
done
}
2019-07-19 14:46:42 +00:00
function test_deletion_failure ( ) {
2016-12-12 18:27:34 +00:00
if [ " $LOCAL_OS " = = "WinNT10" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
2016-11-22 16:40:47 +00:00
echo "Skipping deletion failure test as Win10 does not have chattr support."
return 0
fi
2016-11-15 20:42:49 +00:00
2016-11-15 20:29:12 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DirA = "some directory with spaces"
DirB = "another directoy/and sub directory"
mkdir -p " $INITIATOR_DIR / $DirA "
mkdir -p " $TARGET_DIR / $DirB "
FileA = " $DirA /File A "
FileB = " $DirB /File B "
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-15 20:29:12 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
rm -f " $INITIATOR_DIR / $FileA "
rm -f " $TARGET_DIR / $FileB "
# Prevent files from being deleted
2016-11-21 09:25:08 +00:00
$SUDO_CMD $IMMUTABLE_ON_CMD " $TARGET_DIR / $FileA "
$SUDO_CMD $IMMUTABLE_ON_CMD " $INITIATOR_DIR / $FileB "
2016-11-15 20:29:12 +00:00
# This shuold fail with exitcode 1
2019-01-02 19:54:57 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-15 20:29:12 +00:00
assertEquals " Second deletion run with parameters [ $i ]. " "1" $?
2016-12-04 17:57:39 +00:00
# standard file tests
2016-11-15 20:29:12 +00:00
[ -f " $TARGET_DIR / $FileA " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileA ] is still present in replica dir. " "0" $?
2016-11-15 20:29:12 +00:00
[ ! -f " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileA " ]
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileA ] is not present in deletion dir. " "0" $?
[ -f " $INITIATOR_DIR / $FileB " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileB ] is still present in replica dir. " "0" $?
2016-11-15 20:29:12 +00:00
[ ! -f " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileB " ]
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileB ] is not present in deletion dir. " "0" $?
# Allow files from being deleted
2016-11-21 09:25:08 +00:00
$SUDO_CMD $IMMUTABLE_OFF_CMD " $TARGET_DIR / $FileA "
$SUDO_CMD $IMMUTABLE_OFF_CMD " $INITIATOR_DIR / $FileB "
2016-11-15 20:29:12 +00:00
2018-10-17 21:33:52 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i --verbose
2016-11-15 20:29:12 +00:00
assertEquals " Third deletion run with parameters [ $i ]. " "0" $?
[ ! -f " $TARGET_DIR / $FileA " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileA ] is still present in replica dir. " "0" $?
2016-11-15 20:29:12 +00:00
[ -f " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileA " ]
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileA ] is not present in deletion dir. " "0" $?
[ ! -f " $INITIATOR_DIR / $FileB " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileB ] is still present in replica dir. " "0" $?
2016-11-15 20:29:12 +00:00
[ -f " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileB " ]
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileB ] is not present in deletion dir. " "0" $?
done
}
2019-07-19 14:46:42 +00:00
function test_skip_deletion ( ) {
2016-11-16 14:48:33 +00:00
local modes
if [ " $OSYNC_MIN_VERSION " = = "1" ] ; then
echo "Skipping SkipDeletion test because it wasn't implemented in osync v1.1."
return 0
fi
2016-12-05 10:23:48 +00:00
# TRAVIS SPECIFIC - time limitation
if [ " $TRAVIS_RUN " != true ] ; then
modes = ( 'initiator' 'target' 'initiator,target' )
else
modes = ( 'target' )
fi
2016-11-16 14:48:33 +00:00
for mode in " ${ modes [@] } " ; do
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "SKIP_DELETION" " $mode "
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "SKIP_DELETION" " $mode "
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DirA = "another/one/bites/ de_dust"
DirB = "phantom of /the opera"
mkdir -p " $INITIATOR_DIR / $DirA "
mkdir -p " $TARGET_DIR / $DirB "
FileA = " $DirA /Iron Rhapsody "
FileB = " $DirB /Bohemian Maiden "
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
# First run
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING SKIP_DELETION = " $mode " $OSYNC_EXECUTABLE $i
2016-11-16 14:48:33 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
rm -f " $INITIATOR_DIR / $FileA "
rm -f " $TARGET_DIR / $FileB "
# Second run
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING SKIP_DELETION = " $mode " $OSYNC_EXECUTABLE $i
2016-11-16 14:48:33 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
if [ " $mode " = = "initiator" ] ; then
[ -f " $TARGET_DIR / $FileA " ]
assertEquals " File [ $TARGET_DIR / $FileA ] still exists in mode $mode . " "1" $?
[ -f " $INITIATOR_DIR / $FileB " ]
assertEquals " File [ $INITIATOR_DIR / $FileB still exists in mode $mode . " "0" $?
elif [ " $mode " = = "target" ] ; then
[ -f " $TARGET_DIR / $FileA " ]
assertEquals " File [ $TARGET_DIR / $FileA ] still exists in mode $mode . " "0" $?
[ -f " $INITIATOR_DIR / $FileB " ]
assertEquals " File [ $INITIATOR_DIR / $FileB still exists in mode $mode . " "1" $?
elif [ " $mode " = = "initiator,target" ] ; then
[ -f " $TARGET_DIR / $FileA " ]
assertEquals " File [ $TARGET_DIR / $FileA ] still exists in mode $mode . " "0" $?
[ -f " $INITIATOR_DIR / $FileB " ]
assertEquals " File [ $INITIATOR_DIR / $FileB still exists in mode $mode . " "0" $?
else
assertEquals "Bogus skip deletion mode" "0" "1"
fi
done
done
# Set original values back
2016-11-21 12:42:10 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "SKIP_DELETION" ""
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "SKIP_DELETION" ""
2016-11-15 20:42:49 +00:00
}
2016-11-15 20:29:12 +00:00
2019-07-19 14:46:42 +00:00
function test_handle_symlinks ( ) {
2016-12-04 17:57:39 +00:00
if [ " $OSYNC_MIN_VERSION " = = "1" ] ; then
echo "Skipping symlink tests as osync v1.1x didn't handle this."
return 0
fi
2016-12-09 18:25:23 +00:00
if [ " $LOCAL_OS " = = "msys" ] ; then
echo "Skipping symlink tests because msys handles them strangely or not at all."
return 0
fi
2016-12-04 17:57:39 +00:00
# Check with and without copySymlinks
2019-01-10 23:34:12 +00:00
copySymlinks = false
2016-12-04 17:57:39 +00:00
echo " Running with COPY_SYMLINKS= $copySymlinks "
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "COPY_SYMLINKS" " $copySymlinks "
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "COPY_SYMLINKS" " $copySymlinks "
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DirA = "some directory with spaces"
DirB = "another directoy/and sub directory"
mkdir -p " $INITIATOR_DIR / $DirA "
mkdir -p " $TARGET_DIR / $DirB "
FileA = " $DirA /File A "
FileB = " $DirB /File B "
FileAL = " $DirA /File A symlink "
FileBL = " $DirB /File B symlink "
# Create symlinks
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
ln -s " $INITIATOR_DIR / $FileA " " $INITIATOR_DIR / $FileAL "
ln -s " $TARGET_DIR / $FileB " " $TARGET_DIR / $FileBL "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-04 17:57:39 +00:00
assertEquals " First symlink run with parameters [ $i ]. " "0" $?
# Delete symlinks
rm -f " $INITIATOR_DIR / $FileAL "
rm -f " $TARGET_DIR / $FileBL "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-04 17:57:39 +00:00
assertEquals " Second symlink deletion run with parameters [ $i ]. " "0" $?
# symlink deletion propagation
2016-12-05 11:22:59 +00:00
[ ! -L " $TARGET_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileAL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -L " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL ] is not present in deletion dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ ! -L " $INITIATOR_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileBL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -L " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL ] is not present in deletion dir. " "0" $?
# Create broken symlinks and propagate them
ln -s " $INITIATOR_DIR / $FileA " " $INITIATOR_DIR / $FileAL "
ln -s " $TARGET_DIR / $FileB " " $TARGET_DIR / $FileBL "
rm -f " $INITIATOR_DIR / $FileA "
rm -f " $TARGET_DIR / $FileB "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-05 11:22:59 +00:00
assertEquals " Third broken symlink run with parameters [ $i ]. " "0" $?
2016-12-04 17:57:39 +00:00
2016-12-05 11:22:59 +00:00
[ -L " $TARGET_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileAL ] is present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -L " $INITIATOR_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileBL ] is present in replica dir. " "0" $?
# Check broken symlink deletion propagation
rm -f " $INITIATOR_DIR / $FileAL "
rm -f " $TARGET_DIR / $FileBL "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-05 11:22:59 +00:00
assertEquals " Fourth symlink deletion run with parameters [ $i ]. " "0" $?
2016-12-04 17:57:39 +00:00
2016-12-05 11:22:59 +00:00
[ ! -L " $TARGET_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileAL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -L " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL ] is not present in deletion dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ ! -L " $INITIATOR_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileBL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -L " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL ] is not present in deletion dir. " "0" $?
done
2016-12-05 10:23:48 +00:00
# TRAVIS SPECIFIC - time limitation
if [ " $TRAVIS_RUN " != true ] ; then
return 0
fi
2016-12-04 17:57:39 +00:00
# Check with and without copySymlinks
2019-01-10 23:34:12 +00:00
copySymlinks = true
2016-12-04 17:57:39 +00:00
echo " Running with COPY_SYMLINKS= $copySymlinks "
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "COPY_SYMLINKS" " $copySymlinks "
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "COPY_SYMLINKS" " $copySymlinks "
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DirA = "some directory with spaces"
DirB = "another directoy/and sub directory"
mkdir -p " $INITIATOR_DIR / $DirA "
mkdir -p " $TARGET_DIR / $DirB "
FileA = " $DirA /File A "
FileB = " $DirB /File B "
FileAL = " $DirA /File A symlink "
FileBL = " $DirB /File B symlink "
# Create symlinks
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
ln -s " $INITIATOR_DIR / $FileA " " $INITIATOR_DIR / $FileAL "
ln -s " $TARGET_DIR / $FileB " " $TARGET_DIR / $FileBL "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-04 17:57:39 +00:00
assertEquals " First symlink run with parameters [ $i ]. " "0" $?
# Delete symlinks
rm -f " $INITIATOR_DIR / $FileAL "
rm -f " $TARGET_DIR / $FileBL "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-04 17:57:39 +00:00
assertEquals " Second symlink deletion run with parameters [ $i ]. " "0" $?
# symlink deletion propagation
2016-12-05 11:22:59 +00:00
[ ! -f " $TARGET_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileAL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -f " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL ] is not present in deletion dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ ! -f " $INITIATOR_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileBL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -f " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL ] is not present in deletion dir. " "0" $?
# Create broken symlinks and propagate them
ln -s " $INITIATOR_DIR / $FileA " " $INITIATOR_DIR / $FileAL "
ln -s " $TARGET_DIR / $FileB " " $TARGET_DIR / $FileBL "
rm -f " $INITIATOR_DIR / $FileA "
rm -f " $TARGET_DIR / $FileB "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-05 11:22:59 +00:00
assertEquals " Third broken symlink run with parameters should fail [ $i ]. " "1" $?
2016-12-04 17:57:39 +00:00
2016-12-05 11:22:59 +00:00
[ ! -f " $TARGET_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileAL ] is present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ ! -f " $INITIATOR_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileBL ] is present in replica dir. " "0" $?
# Check broken symlink deletion propagation
rm -f " $INITIATOR_DIR / $FileAL "
rm -f " $TARGET_DIR / $FileBL "
2018-06-30 17:46:11 +00:00
COPY_SYMLINKS = $copySymlinks REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-13 17:35:34 +00:00
assertEquals " Fourth symlink deletion run should resume with parameters [ $i ]. " "0" $?
2016-12-04 17:57:39 +00:00
2016-12-05 11:22:59 +00:00
[ ! -f " $TARGET_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $FileAL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -f " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileAL ] is not present in deletion dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ ! -f " $INITIATOR_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $FileBL ] is still present in replica dir. " "0" $?
2016-12-05 11:22:59 +00:00
[ -f " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL " ]
2016-12-04 17:57:39 +00:00
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileBL ] is not present in deletion dir. " "0" $?
done
}
2019-07-19 14:46:42 +00:00
function test_softdeletion_cleanup ( ) {
2016-11-18 12:34:49 +00:00
#declare -A files
2016-11-13 13:12:51 +00:00
2016-11-18 12:34:49 +00:00
files = ( )
files[ 0] = " $INITIATOR_DIR / $OSYNC_DELETE_DIR /someDeletedFileInitiator "
files[ 1] = " $TARGET_DIR / $OSYNC_DELETE_DIR /someDeletedFileTarget "
files[ 2] = " $INITIATOR_DIR / $OSYNC_BACKUP_DIR /someBackedUpFileInitiator "
files[ 3] = " $TARGET_DIR / $OSYNC_BACKUP_DIR /someBackedUpFileTarget "
2016-11-13 15:23:04 +00:00
2016-12-12 22:58:42 +00:00
DirA = " $INITIATOR_DIR / $OSYNC_DELETE_DIR /somedir "
DirB = " $TARGET_DIR / $OSYNC_DELETE_DIR /someotherdir "
2016-11-13 13:12:51 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
# First run
2018-06-30 17:46:11 +00:00
#REMOTE_HOST_PING=$RHOST_PING $OSYNC_EXECUTABLE $i
2016-12-12 22:58:42 +00:00
#assertEquals "First deletion run with parameters [$i]." "0" $?
2016-11-13 13:12:51 +00:00
# Get current drive
drive = $( df " $OSYNC_DIR " | tail -1 | awk '{print $1}' )
# Create some deleted & backed up files, some new and some old
for file in " ${ files [@] } " ; do
2016-11-15 20:29:12 +00:00
# Create directories first if they do not exist (deletion dir is created by osync, backup dir is created by rsync only when needed)
2016-11-13 13:12:51 +00:00
if [ ! -d " $( dirname $file ) " ] ; then
2016-11-21 14:12:52 +00:00
mkdir -p " $( dirname $file ) "
2016-11-13 13:12:51 +00:00
fi
touch " $file .new "
2016-11-13 14:11:06 +00:00
2016-12-09 18:26:58 +00:00
if [ " $TRAVIS_RUN " = = true ] || [ " $LOCAL_OS " = = "BSD" ] || [ " $LOCAL_OS " = = "MacOSX" ] || [ " $LOCAL_OS " = = "WinNT10" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
2016-11-22 18:24:51 +00:00
echo "Skipping changing ctime on file because travis / bsd / macos / Win10 / msys / cygwin does not support debugfs"
2016-11-21 18:13:15 +00:00
else
CreateOldFile " $file .old "
2016-11-13 14:11:06 +00:00
fi
2016-11-13 13:12:51 +00:00
done
2016-12-12 22:58:42 +00:00
if [ " $TRAVIS_RUN " = = true ] || [ " $LOCAL_OS " = = "BSD" ] || [ " $LOCAL_OS " = = "MacOSX" ] || [ " $LOCAL_OS " = = "WinNT10" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
echo "Skipping changing ctime on dir too"
else
CreateOldFile " $DirA " true
CreateOldFile " $DirB " true
fi
2016-11-13 13:12:51 +00:00
2016-11-13 19:22:52 +00:00
# Second run
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-13 13:12:51 +00:00
# Check file presence
for file in " ${ files [@] } " ; do
[ -f " $file .new " ]
assertEquals " New softdeleted / backed up file [ $file .new] exists. " "0" $?
2016-11-13 15:23:04 +00:00
2016-12-09 18:22:14 +00:00
if [ " $TRAVIS_RUN " = = true ] || [ " $LOCAL_OS " = = "BSD" ] || [ " $LOCAL_OS " = = "MacOSX" ] || [ " $LOCAL_OS " = = "WinNT10" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
2016-11-13 15:23:04 +00:00
[ ! -f " $file .old " ]
2016-11-21 18:13:15 +00:00
assertEquals " Old softdeleted / backed up file [ $file .old] is deleted permanently. " "0" $?
2016-11-13 14:11:06 +00:00
else
2016-11-13 15:23:04 +00:00
[ ! -f " $file .old " ]
2016-11-21 18:13:15 +00:00
assertEquals " Old softdeleted / backed up file [ $file .old] is deleted permanently. " "1" $?
2016-11-13 14:11:06 +00:00
fi
2016-11-13 13:12:51 +00:00
done
2016-12-12 22:58:42 +00:00
if [ " $TRAVIS_RUN " = = true ] || [ " $LOCAL_OS " = = "BSD" ] || [ " $LOCAL_OS " = = "MacOSX" ] || [ " $LOCAL_OS " = = "WinNT10" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
[ ! -d " $DirA " ]
assertEquals " Old softdeleted / backed up directory [ $dirA ] is deleted permanently. " "0" $?
[ ! -d " $DirB " ]
assertEquals " Old softdeleted / backed up directory [ $dirB ] is deleted permanently. " "0" $?
else
[ ! -d " $DirA " ]
assertEquals " Old softdeleted / backed up directory [ $DirA ] is deleted permanently. " "1" $?
[ ! -d " $DirB " ]
assertEquals " Old softdeleted / backed up directory [ $DirB ] is deleted permanently. " "1" $?
fi
2016-11-13 13:12:51 +00:00
done
}
2019-07-19 14:46:42 +00:00
function test_FileAttributePropagation ( ) {
2016-10-23 17:17:25 +00:00
2016-11-13 19:38:16 +00:00
if [ " $TRAVIS_RUN " = = true ] ; then
2016-11-15 20:42:49 +00:00
echo "Skipping FileAttributePropagation tests as travis does not support getfacl / setfacl."
2016-11-13 19:32:18 +00:00
return 0
fi
2016-12-12 18:27:34 +00:00
if [ " $LOCAL_OS " = = "MacOSX" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
2016-12-08 09:53:47 +00:00
echo " Skipping FileAttributePropagation tests because [ $LOCAL_OS ] does not support ACL. "
2016-11-21 15:33:22 +00:00
return 0
fi
2019-05-20 19:56:01 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "PRESERVE_ACL" true
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "PRESERVE_XATTR" true
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "PRESERVE_ACL" true
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "PRESERVE_XATTR" true
2016-11-13 19:22:52 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
2016-10-23 17:17:25 +00:00
2016-11-15 18:31:52 +00:00
DirA = "dir a"
DirB = "dir b"
2016-11-20 16:22:03 +00:00
DirC = "dir c"
DirD = "dir d"
2016-11-15 18:31:52 +00:00
mkdir " $INITIATOR_DIR / $DirA "
mkdir " $TARGET_DIR / $DirB "
2016-11-20 16:22:03 +00:00
mkdir " $INITIATOR_DIR / $DirC "
mkdir " $TARGET_DIR / $DirD "
2016-11-15 18:31:52 +00:00
FileA = " $DirA /FileA "
FileB = " $DirB /FileB "
2016-09-05 20:21:25 +00:00
2016-11-13 19:22:52 +00:00
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
2016-09-05 20:21:25 +00:00
2016-11-13 19:22:52 +00:00
# First run
2018-06-30 17:46:11 +00:00
PRESERVE_ACL = yes PRESERVE_XATTR = yes REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-13 19:22:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
2016-09-05 20:21:25 +00:00
2016-11-13 19:22:52 +00:00
sleep 1
2016-09-05 20:21:25 +00:00
2016-11-18 12:34:49 +00:00
getfacl " $INITIATOR_DIR / $FileA " | grep "other::r--" > /dev/null
2016-11-13 19:22:52 +00:00
assertEquals "Check getting ACL on initiator." "0" $?
2016-11-18 12:34:49 +00:00
getfacl " $TARGET_DIR / $FileB " | grep "other::r--" > /dev/null
2016-11-13 19:22:52 +00:00
assertEquals "Check getting ACL on target." "0" $?
2016-10-23 17:17:25 +00:00
2016-11-20 16:22:03 +00:00
getfacl " $INITIATOR_DIR / $DirC " | grep "other::r-x" > /dev/null
assertEquals "Check getting ACL on initiator subdirectory." "0" $?
getfacl " $TARGET_DIR / $DirD " | grep "other::r-x" > /dev/null
assertEquals "Check getting ACL on target subdirectory." "0" $?
2016-11-20 20:47:56 +00:00
setfacl -m o::r-x " $INITIATOR_DIR / $FileA "
2016-11-13 19:22:52 +00:00
assertEquals "Set ACL on initiator" "0" $?
2016-11-20 20:47:56 +00:00
setfacl -m o::-w- " $TARGET_DIR / $FileB "
2016-11-13 19:22:52 +00:00
assertEquals "Set ACL on target" "0" $?
2016-10-23 17:17:25 +00:00
2016-11-20 20:47:56 +00:00
setfacl -m o::rwx " $INITIATOR_DIR / $DirC "
2016-11-20 16:22:03 +00:00
assertEquals "Set ACL on initiator directory" "0" $?
2016-11-20 20:47:56 +00:00
setfacl -m o::-wx " $TARGET_DIR / $DirD "
2016-11-20 16:22:03 +00:00
assertEquals "Set ACL on target directory" "0" $?
2016-11-13 19:22:52 +00:00
# Second run
2018-06-30 17:46:11 +00:00
PRESERVE_ACL = yes PRESERVE_XATTR = yes REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-13 19:22:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
2016-09-05 20:21:25 +00:00
2016-11-18 12:34:49 +00:00
getfacl " $TARGET_DIR / $FileA " | grep "other::r-x" > /dev/null
2016-11-13 19:22:52 +00:00
assertEquals "ACLs matched original value on target." "0" $?
2016-09-05 20:21:25 +00:00
2016-11-18 12:34:49 +00:00
getfacl " $INITIATOR_DIR / $FileB " | grep "other::-w-" > /dev/null
2016-11-13 19:22:52 +00:00
assertEquals "ACLs matched original value on initiator." "0" $?
2016-11-20 16:22:03 +00:00
getfacl " $TARGET_DIR / $DirC " | grep "other::rwx" > /dev/null
assertEquals "ACLs matched original value on target subdirectory." "0" $?
getfacl " $INITIATOR_DIR / $DirD " | grep "other::-wx" > /dev/null
assertEquals "ACLs matched original value on initiator subdirectory." "0" $?
2016-11-13 19:22:52 +00:00
done
2019-05-20 19:56:01 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "PRESERVE_ACL" false
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "PRESERVE_XATTR" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "PRESERVE_ACL" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "PRESERVE_XATTR" false
2016-09-05 20:21:25 +00:00
}
2019-07-19 14:46:42 +00:00
function test_ConflictBackups ( ) {
2016-11-15 18:31:52 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
DirA = "some dir"
DirB = "some other dir"
mkdir -p " $INITIATOR_DIR / $DirA "
mkdir -p " $TARGET_DIR / $DirB "
FileA = " $DirA /FileA "
FileB = " $DirB /File B "
echo " $FileA " > " $INITIATOR_DIR / $FileA "
echo " $FileB " > " $TARGET_DIR / $FileB "
# First run
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-15 18:31:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
echo " $FileA + " > " $TARGET_DIR / $FileA "
echo " $FileB + " > " $INITIATOR_DIR / $FileB "
# Second run
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-15 18:31:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
[ -f " $INITIATOR_DIR / $OSYNC_BACKUP_DIR / $FileA " ]
assertEquals " Backup file is present in [ $INITIATOR_DIR / $OSYNC_BACKUP_DIR / $FileA ]. " "0" $?
[ -f " $TARGET_DIR / $OSYNC_BACKUP_DIR / $FileB " ]
assertEquals " Backup file is present in [ $TARGET_DIR / $OSYNC_BACKUP_DIR / $FileB ]. " "0" $?
done
}
2019-07-19 14:46:42 +00:00
function test_MultipleConflictBackups ( ) {
2016-11-15 18:31:52 +00:00
2016-11-15 21:56:02 +00:00
local additionalParameters
2016-11-15 18:31:52 +00:00
# modify config files
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "CONFLICT_BACKUP_MULTIPLE" true
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "CONFLICT_BACKUP_MULTIPLE" true
2016-11-15 18:31:52 +00:00
2016-11-15 21:56:02 +00:00
if [ " $OSYNC_MIN_VERSION " != "1" ] ; then
additionalParameters = "--errors-only --summary --no-prefix"
fi
2016-11-15 18:31:52 +00:00
for i in " ${ osyncParameters [@] } " ; do
2017-02-07 16:43:30 +00:00
echo " Running with parameters [ $i ]. "
2016-12-12 20:46:44 +00:00
2016-11-15 18:31:52 +00:00
cd " $OSYNC_DIR "
PrepareLocalDirs
FileA = "FileA"
FileB = "FileB"
echo " $FileA " > " $INITIATOR_DIR / $FileA "
echo " $FileB " > " $TARGET_DIR / $FileB "
# First run
2019-01-11 22:56:48 +00:00
CONFLICT_BACKUP_MULTIPLE = true REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i $additionalParameters
2016-11-15 18:31:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
echo " $FileA + " > " $TARGET_DIR / $FileA "
echo " $FileB + " > " $INITIATOR_DIR / $FileB "
# Second run
2019-01-11 22:56:48 +00:00
CONFLICT_BACKUP_MULTIPLE = true REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i $additionalParameters
2016-11-15 18:31:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
echo " $FileA - " > " $TARGET_DIR / $FileA "
echo " $FileB - " > " $INITIATOR_DIR / $FileB "
# Third run
2019-01-11 22:56:48 +00:00
CONFLICT_BACKUP_MULTIPLE = true REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i $additionalParameters
2016-11-15 18:31:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
echo " $FileA * " > " $TARGET_DIR / $FileA "
echo " $FileB * " > " $INITIATOR_DIR / $FileB "
# Fouth run
2019-01-11 22:56:48 +00:00
CONFLICT_BACKUP_MULTIPLE = true REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i $additionalParameters
2016-11-15 18:31:52 +00:00
assertEquals " First deletion run with parameters [ $i ]. " "0" $?
# This test may fail only on 31th December at 23:59 :)
[ $( find " $INITIATOR_DIR / $OSYNC_BACKUP_DIR / " -type f -name " FileA. $( date '+%Y' ) * " | wc -l) -eq 3 ]
assertEquals " 3 Backup files are present in [ $INITIATOR_DIR / $OSYNC_BACKUP_DIR /]. " "0" $?
[ $( find " $TARGET_DIR / $OSYNC_BACKUP_DIR / " -type f -name " FileB. $( date '+%Y' ) * " | wc -l) -eq 3 ]
assertEquals " 3 Backup files are present in [ $TARGET_DIR / $OSYNC_BACKUP_DIR /]. " "0" $?
done
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "CONFLICT_BACKUP_MULTIPLE" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "CONFLICT_BACKUP_MULTIPLE" false
2016-11-15 18:31:52 +00:00
}
2019-07-19 14:46:42 +00:00
function test_Locking ( ) {
2016-11-17 11:15:24 +00:00
# local not running = resume
# remote same instance_id = resume
# remote different instance_id = stop
# remote dfiffent instance_id + FORCE_STRANGER_LOCK_RESUME = resume
# Initiator lock present should always be resumed if pid does not run
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
mkdir -p " $INITIATOR_DIR / $OSYNC_WORKDIR "
echo 65536 > " $INITIATOR_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-17 11:15:24 +00:00
assertEquals "Should be able to resume when initiator has lock without running pid." "0" $?
echo $$ > " $INITIATOR_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-17 11:15:24 +00:00
assertEquals "Should never be able to resume when initiator has lock with running pid." "1" $?
done
# Target lock present should be resumed if instance ID is the same as current one
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@quicklocal > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__quickLocal ] }
2016-11-17 11:15:24 +00:00
assertEquals "Should be able to resume locked target with same instance_id in quickLocal mode." "0" $?
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@local > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__confLocal ] }
2016-11-17 11:15:24 +00:00
assertEquals "Should be able to resume locked target with same instance_id in confLocal mode." "0" $?
2016-12-12 18:27:34 +00:00
if [ " $LOCAL_OS " != "msys" ] && [ " $LOCAL_OS " != "Cygwin" ] ; then
2016-12-08 11:09:52 +00:00
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@quickremote > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2016-11-17 11:15:24 +00:00
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__quickRemote ] }
2016-12-08 11:09:52 +00:00
assertEquals "Should be able to resume locked target with same instance_id in quickRemote mode." "0" $?
2016-11-17 11:15:24 +00:00
2016-12-08 11:09:52 +00:00
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@remote > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2016-11-17 11:15:24 +00:00
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__confRemote ] }
2016-12-08 11:09:52 +00:00
assertEquals "Should be able to resume locked target with same instance_id in confRemote mode." "0" $?
fi
2016-11-17 11:15:24 +00:00
# Remote Target lock present should not be resumed if instance ID is NOT the same as current one, local target lock is resumed
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@bogusinstance > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__quickLocal ] }
2016-11-17 11:15:24 +00:00
assertEquals "Should be able to resume locked local target with bogus instance id in quickLocal mode." "0" $?
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@bogusinstance > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__confLocal ] }
2016-11-17 11:15:24 +00:00
assertEquals "Should be able to resume locked local target with bogus instance_id in confLocal mode." "0" $?
2016-12-12 18:27:34 +00:00
if [ " $LOCAL_OS " != "msys" ] && [ " $LOCAL_OS " != "Cygwin" ] ; then
2016-12-08 11:09:52 +00:00
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@bogusinstance > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2016-11-17 11:15:24 +00:00
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__quickRemote ] }
2016-12-08 11:09:52 +00:00
assertEquals "Should not be able to resume remote locked target with bogus instance_id in quickRemote mode." "1" $?
2016-11-17 11:15:24 +00:00
2016-12-08 11:09:52 +00:00
PrepareLocalDirs
mkdir -p " $TARGET_DIR / $OSYNC_WORKDIR "
echo 65536@bogusinstance > " $TARGET_DIR / $OSYNC_WORKDIR /lock "
2016-11-17 11:15:24 +00:00
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__confRemote ] }
2016-12-08 11:09:52 +00:00
assertEquals "Should not be able to resume remote locked target with bogus instance_id in confRemote mode." "1" $?
fi
2016-11-17 11:15:24 +00:00
# Target lock present should be resumed if instance ID is NOT the same as current one but FORCE_STRANGER_UNLOCK=yes
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "FORCE_STRANGER_LOCK_RESUME" true
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "FORCE_STRANGER_LOCK_RESUME" true
2016-11-17 11:15:24 +00:00
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
mkdir -p " $INITIATOR_DIR / $OSYNC_WORKDIR "
echo 65536@bogusinstance > " $INITIATOR_DIR / $OSYNC_WORKDIR /lock "
2018-06-30 17:46:11 +00:00
FORCE_STRANGER_UNLOCK = yes REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i
2016-11-17 11:15:24 +00:00
assertEquals "Should be able to resume when target has lock with different instance id but FORCE_STRANGER_UNLOCK=yes." "0" $?
done
2019-01-10 23:34:12 +00:00
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "FORCE_STRANGER_LOCK_RESUME" false
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "FORCE_STRANGER_LOCK_RESUME" false
2016-11-17 11:15:24 +00:00
}
2016-11-15 18:31:52 +00:00
2019-07-19 14:46:42 +00:00
function test_ConflictDetetion ( ) {
2019-05-20 20:50:01 +00:00
# Tests compatible with v1.4+
2019-01-02 19:19:24 +00:00
2019-05-20 20:50:01 +00:00
if [ $OSYNC_MIN_VERSION -lt 4 ] ; then
echo " Skipping conflict detection test because osync min version is $OSYNC_MIN_VERSION (must be 4 at least). "
2018-06-30 17:46:11 +00:00
return 0
fi
2018-07-02 21:25:49 +00:00
for i in " ${ osyncParameters [@] } " ; do
2018-06-30 17:46:11 +00:00
cd " $OSYNC_DIR "
PrepareLocalDirs
FileA = "some file"
FileB = "some other file"
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
2018-07-01 08:55:07 +00:00
touch " $INITIATOR_DIR / $FileB "
touch " $TARGET_DIR / $FileA "
2018-06-30 17:46:11 +00:00
# Initializing treeList
2019-01-02 19:19:24 +00:00
REMOTE_HOST_PING = $RHOST_PING _PARANOIA_DEBUG = no $OSYNC_EXECUTABLE $i --initialize
2018-06-30 17:46:11 +00:00
assertEquals " Initialization run with parameters [ $i ]. " "0" $?
2018-10-07 15:50:37 +00:00
2018-06-30 17:46:11 +00:00
# Now modifying files on both sides
2019-01-02 19:19:24 +00:00
2018-06-30 17:46:11 +00:00
echo "A" > " $INITIATOR_DIR / $FileA "
echo "B" > " $TARGET_DIR / $FileB "
2018-07-01 08:55:07 +00:00
echo "BB" > " $INITIATOR_DIR / $FileB "
2018-07-02 20:40:23 +00:00
echo "AA" > " $TARGET_DIR / $FileA "
2018-06-30 17:46:11 +00:00
# Now run should return conflicts
2019-01-02 19:19:24 +00:00
2018-10-17 21:33:52 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE $i --log-conflicts > " $FAKEROOT /output2.log " 2>& 1
2019-01-02 19:19:24 +00:00
assertEquals " Second run that should detect conflicts with parameters [ $i ]. " "0" $?
2018-10-07 15:50:37 +00:00
cat " $FAKEROOT /output2.log "
2018-10-04 22:51:20 +00:00
2018-10-07 10:25:53 +00:00
#WIP TODO change output.log from output2.log for debug reasons
grep " $INITIATOR_DIR / $FileA << >> $TARGET_DIR / $FileA " " $FAKEROOT /output2.log "
2018-07-01 08:55:07 +00:00
assertEquals " FileA conflict detect with parameters [ $i ]. " "0" $?
2019-01-02 19:19:24 +00:00
2018-10-07 10:25:53 +00:00
grep " $INITIATOR_DIR / $FileB << >> $TARGET_DIR / $FileB " " $FAKEROOT /output2.log "
2018-07-01 08:55:07 +00:00
assertEquals " FileB conflict detect with parameters [ $i ]. " "0" $?
2018-06-30 17:46:11 +00:00
2018-10-07 10:25:53 +00:00
#TODO: Missing test for conflict prevalance (once we have FORCE_CONFLICT_PREVALANCE
2018-06-30 17:46:11 +00:00
done
2019-01-02 19:19:24 +00:00
return 0
2018-06-30 17:46:11 +00:00
}
2019-07-19 14:46:42 +00:00
function test_WaitForTaskCompletion ( ) {
2016-11-30 12:02:01 +00:00
local pids
# Tests compatible with v1.1 syntax
2016-11-30 12:50:49 +00:00
# These tests aren't really effective because in any case, output from WaitFor functions is always 0, which was a bad behavior in v1.1
2016-11-15 23:47:27 +00:00
if [ " $OSYNC_MIN_VERSION " = = "1" ] ; then
2016-11-30 12:50:49 +00:00
echo "Using v1.1 WaitForTaskCompletion test"
2017-04-08 20:10:01 +00:00
# Needed in order to get PROCESS_test_CMD value
2016-11-30 12:50:49 +00:00
InitLocalOSSettings
2016-11-30 12:02:01 +00:00
# Standard wait
sleep 2 &
2016-11-30 12:50:49 +00:00
pid = $!
WaitForTaskCompletion $pid 0 0 ${ FUNCNAME [0] }
2016-11-30 12:02:01 +00:00
assertEquals "WaitForTaskCompletion v1.1 test 1" "0" $?
# Standard wait with warning
sleep 5 &
WaitForTaskCompletion $! 3 0 ${ FUNCNAME [0] }
2016-11-30 12:50:49 +00:00
assertEquals "WaitForTaskCompletion v1.1 test 2" "0" $?
2016-11-30 12:02:01 +00:00
# Pid is killed
sleep 5 &
WaitForTaskCompletion $! 0 2 ${ FUNCNAME [0] }
2016-11-30 12:50:49 +00:00
assertEquals "WaitForTaskCompletion v1.1 test 3" "1" $?
2016-11-30 12:02:01 +00:00
# Standard wait
sleep 2 &
WaitForCompletion $! 0 0 ${ FUNCNAME [0] }
2016-11-30 12:50:49 +00:00
assertEquals "WaitForCompletion test 1" "0" $?
2016-11-30 12:02:01 +00:00
# Standard wait with warning
sleep 5 &
WaitForCompletion $! 3 0 ${ FUNCNAME [0] }
2016-11-30 12:50:49 +00:00
assertEquals "WaitForCompletion test 2" "0" $?
2016-11-30 12:02:01 +00:00
# Pid is killed
sleep 5 &
WaitForCompletion $! 0 2 ${ FUNCNAME [0] }
2016-11-30 12:50:49 +00:00
assertEquals "WaitForCompletion test 3" "1" $?
2016-11-30 12:02:01 +00:00
2016-11-15 22:20:20 +00:00
return 0
fi
2016-11-30 12:02:01 +00:00
# Tests if wait for task completion works correctly with v1.2+
2016-09-05 20:21:25 +00:00
# Standard wait
sleep 1 &
pids = " $! "
sleep 2 &
pids = " $pids ; $! "
2016-11-24 12:26:10 +00:00
WaitForTaskCompletion $pids 0 0 $SLEEP_TIME $KEEP_LOGGING true true false ${ FUNCNAME [0] }
2016-09-05 20:21:25 +00:00
assertEquals "WaitForTaskCompletion test 1" "0" $?
# Standard wait with warning
sleep 2 &
pids = " $! "
sleep 5 &
pids = " $pids ; $! "
2016-11-24 12:26:10 +00:00
WaitForTaskCompletion $pids 3 0 $SLEEP_TIME $KEEP_LOGGING true true false ${ FUNCNAME [0] }
2016-09-05 20:21:25 +00:00
assertEquals "WaitForTaskCompletion test 2" "0" $?
# Both pids are killed
sleep 5 &
pids = " $! "
sleep 5 &
pids = " $pids ; $! "
2016-11-24 12:26:10 +00:00
WaitForTaskCompletion $pids 0 2 $SLEEP_TIME $KEEP_LOGGING true true false ${ FUNCNAME [0] }
2016-09-05 20:21:25 +00:00
assertEquals "WaitForTaskCompletion test 3" "2" $?
# One of two pids are killed
sleep 2 &
pids = " $! "
sleep 10 &
pids = " $pids ; $! "
2016-11-24 12:26:10 +00:00
WaitForTaskCompletion $pids 0 3 $SLEEP_TIME $KEEP_LOGGING true true false ${ FUNCNAME [0] }
2016-09-05 20:21:25 +00:00
assertEquals "WaitForTaskCompletion test 4" "1" $?
# Count since script begin, the following should output two warnings and both pids should get killed
sleep 20 &
pids = " $! "
sleep 20 &
pids = " $pids ; $! "
2016-11-24 12:26:10 +00:00
WaitForTaskCompletion $pids 3 5 $SLEEP_TIME $KEEP_LOGGING false true false ${ FUNCNAME [0] }
2016-09-05 20:21:25 +00:00
assertEquals "WaitForTaskCompletion test 5" "2" $?
}
2019-07-19 14:46:42 +00:00
function test_ParallelExec ( ) {
2016-11-15 23:47:27 +00:00
if [ " $OSYNC_MIN_VERSION " = = "1" ] ; then
2016-11-24 12:26:10 +00:00
echo "Skipping ParallelExec test because osync v1.1 ofunctions don't have this function."
2016-11-15 22:20:20 +00:00
return 0
fi
2016-09-06 17:26:37 +00:00
local cmd
# Test if parallelExec works correctly in array mode
2016-09-05 20:21:25 +00:00
cmd = "sleep 2;sleep 2;sleep 2;sleep 2"
ParallelExec 4 " $cmd "
assertEquals "ParallelExec test 1" "0" $?
cmd = "sleep 2;du /none;sleep 2"
ParallelExec 2 " $cmd "
assertEquals "ParallelExec test 2" "1" $?
cmd = "sleep 4;du /none;sleep 3;du /none;sleep 2"
ParallelExec 3 " $cmd "
assertEquals "ParallelExec test 3" "2" $?
2016-09-06 17:26:37 +00: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 "
2016-09-08 20:57:57 +00:00
ParallelExec 4 " $TMP_FILE " true
2016-09-06 17:26:37 +00:00
assertEquals "ParallelExec test 4" "0" $?
echo "sleep 2" > " $TMP_FILE "
echo "du /nome" >> " $TMP_FILE "
echo "sleep 2" >> " $TMP_FILE "
2016-09-08 20:57:57 +00:00
ParallelExec 2 " $TMP_FILE " true
2016-09-06 17:26:37 +00:00
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 "
2016-09-08 20:57:57 +00:00
ParallelExec 3 " $TMP_FILE " true
2016-09-06 17:26:37 +00:00
assertEquals "ParallelExec test 6" "2" $?
2016-11-24 12:26:10 +00:00
#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-09-05 20:21:25 +00:00
}
2019-07-19 14:46:42 +00:00
function test_timedExecution ( ) {
2016-11-29 19:28:15 +00:00
local arguments
# Clever usage of indexes and exit codes
# osync exits with 0 when no problem detected
# exits with 1 when error detected (triggered by reaching HARD_MAX_EXEC_TIME)
# exits with 2 when warning only detected (triggered by reaching SOFT_MAX_EXEC_TIME)
softTimes = ( )
softTimes[ 0] = 7200 # original values (to be executed at last in order to leave config file in original state)
hardTimes[ 0] = 10600
2016-11-30 12:50:49 +00:00
softTimes[ 1] = 0
2016-11-29 19:28:15 +00:00
hardTimes[ 1] = 3
softTimes[ 2] = 2
hardTimes[ 2] = 10600
for x in 2 1 0; do
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "SOFT_MAX_EXEC_TIME" ${ softTimes [ $x ] }
SetConfFileValue " $CONF_DIR / $LOCAL_CONF " "HARD_MAX_EXEC_TIME" ${ hardTimes [ $x ] }
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "SOFT_MAX_EXEC_TIME" ${ softTimes [ $x ] }
SetConfFileValue " $CONF_DIR / $REMOTE_CONF " "HARD_MAX_EXEC_TIME" ${ hardTimes [ $x ] }
for i in " ${ osyncParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
echo " Test with args [ $i $arguments ]. "
2018-06-30 17:46:11 +00:00
SLEEP_TIME = 1 SOFT_MAX_EXEC_TIME = ${ softTimes [ $x ] } HARD_MAX_EXEC_TIME = ${ hardTimes [ $x ] } $OSYNC_EXECUTABLE $i
2016-11-30 12:50:49 +00:00
retval = $?
if [ " $OSYNC_MIN_VERSION " -gt 1 ] ; then
2016-12-11 19:54:40 +00:00
assertEquals " Timed Execution test with timed SOFT_MAX_EXEC_TIME= ${ softTimes [ $x ] } and HARD_MAX_EXEC_TIME= ${ hardTimes [ $x ] } . " $x $retval
2016-11-30 12:50:49 +00:00
else
# osync v1.1 had different exit codes, 240 was warning, anything else than 0 was error
if [ $x -eq 2 ] ; then
2016-12-11 19:54:40 +00:00
assertEquals " Timed Execution test with timed SOFT_MAX_EXEC_TIME= ${ softTimes [ $x ] } and HARD_MAX_EXEC_TIME= ${ hardTimes [ $x ] } . " 240 $retval
2016-11-30 12:50:49 +00:00
elif [ $x -eq 1 ] ; then
2016-12-11 19:54:40 +00:00
assertNotEquals " Timed Execution test with timed SOFT_MAX_EXEC_TIME= ${ softTimes [ $x ] } and HARD_MAX_EXEC_TIME= ${ hardTimes [ $x ] } . " 0 $retval
2016-11-30 12:50:49 +00:00
else
2016-12-11 19:54:40 +00:00
assertEquals " Timed Execution test with timed SOFT_MAX_EXEC_TIME= ${ softTimes [ $x ] } and HARD_MAX_EXEC_TIME= ${ hardTimes [ $x ] } . " 0 $retval
2016-11-30 12:50:49 +00:00
fi
fi
2016-11-29 19:28:15 +00:00
done
done
}
2019-07-19 14:46:42 +00:00
function test_UpgradeConfRun ( ) {
2016-11-15 23:47:27 +00:00
if [ " $OSYNC_MIN_VERSION " = = "1" ] ; then
2016-11-15 22:20:20 +00:00
echo "Skipping Upgrade script test because no further dev will happen on this for v1.1"
return 0
fi
2016-10-23 17:17:25 +00:00
2016-12-11 19:54:40 +00:00
# Basic return code tests. Need to go deep into file presence testing
cd " $OSYNC_DIR "
2016-10-23 17:17:25 +00:00
PrepareLocalDirs
2016-12-11 19:54:40 +00:00
# Make a security copy of the old config file
cp " $CONF_DIR / $OLD_CONF " " $CONF_DIR / $TMP_OLD_CONF "
2016-10-23 17:17:25 +00:00
2016-12-11 19:54:40 +00:00
./$OSYNC_UPGRADE " $CONF_DIR / $TMP_OLD_CONF "
assertEquals "Conf file upgrade" "0" $?
2016-12-23 20:30:38 +00:00
# Update remote conf files with SSH port
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/${HOME}/osync-tests/target#ssh://' $REMOTE_USER '@localhost:' $SSH_PORT '/${HOME}/osync-tests/target#' " $CONF_DIR / $TMP_OLD_CONF "
2018-06-30 17:46:11 +00:00
$OSYNC_EXECUTABLE " $CONF_DIR / $TMP_OLD_CONF "
2016-12-11 19:54:40 +00:00
assertEquals "Upgraded conf file execution test" "0" $?
2016-10-23 17:17:25 +00:00
2016-12-11 19:54:40 +00:00
rm -f " $CONF_DIR / $TMP_OLD_CONF "
rm -f " $CONF_DIR / $TMP_OLD_CONF .save "
2016-10-23 17:17:25 +00:00
}
2019-07-19 14:46:42 +00:00
function test_DaemonMode ( ) {
2016-12-09 18:22:14 +00:00
if [ " $LOCAL_OS " = = "WinNT10" ] || [ " $LOCAL_OS " = = "msys" ] || [ " $LOCAL_OS " = = "Cygwin" ] ; then
echo " Skipping daemon mode test as [ $LOCAL_OS ] does not have inotifywait support. "
2016-11-22 16:40:47 +00:00
return 0
fi
2016-11-17 23:03:34 +00:00
2016-11-17 22:40:17 +00:00
for i in " ${ osyncDaemonParameters [@] } " ; do
cd " $OSYNC_DIR "
PrepareLocalDirs
FileA = "FileA"
FileB = "FileB"
FileC = "FileC"
touch " $INITIATOR_DIR / $FileA "
touch " $TARGET_DIR / $FileB "
2018-06-30 17:46:11 +00:00
$OSYNC_EXECUTABLE " $CONF_DIR / $LOCAL_CONF " --on-changes &
2016-11-17 22:40:17 +00:00
pid = $!
2016-10-23 17:17:25 +00:00
2018-10-01 18:13:58 +00:00
#TODO: Lower that value when dispatecher is written
2016-11-17 22:40:17 +00:00
# Trivial value of 2xMIN_WAIT from config files
echo "Sleeping for 120s"
sleep 120
[ -f " $TARGET_DIR / $FileB " ]
assertEquals " File [ $TARGET_DIR / $FileB ] should be synced. " "0" $?
[ -f " $INITIATOR_DIR / $FileA " ]
assertEquals " File [ $INITIATOR_DIR / $FileB ] should be synced. " "0" $?
touch " $INITIATOR_DIR / $FileC "
rm -f " $INITIATOR_DIR / $FileA "
rm -f " $TARGET_DIR / $FileB "
echo "Sleeping for 120s"
sleep 120
[ ! -f " $TARGET_DIR / $FileB " ]
assertEquals " File [ $TARGET_DIR / $FileB ] should be deleted. " "0" $?
[ ! -f " $INITIATOR_DIR / $FileA " ]
assertEquals " File [ $INITIATOR_DIR / $FileA ] should be deleted. " "0" $?
[ -f " $TARGET_DIR / $OSYNC_DELETE_DIR / $FileA " ]
assertEquals " File [ $TARGET_DIR / $OSYNC_DELETE_DIR / $FileA ] should be in soft deletion dir. " "0" $?
[ -f " $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileB " ]
assertEquals " File [ $INITIATOR_DIR / $OSYNC_DELETE_DIR / $FileB ] should be in soft deletion dir. " "0" $?
[ -f " $TARGET_DIR / $FileC " ]
2016-11-22 18:24:51 +00:00
assertEquals " File [ $TARGET_DIR / $FileC ] should be synced. " "0" $?
2016-11-17 22:40:17 +00:00
kill $pid
done
}
2016-11-19 13:21:42 +00:00
2019-07-19 14:46:42 +00:00
function test_NoRemoteAccessTest ( ) {
2016-11-19 13:21:42 +00:00
RemoveSSH
2016-12-11 19:54:40 +00:00
cd " $OSYNC_DIR "
2016-11-19 13:21:42 +00:00
PrepareLocalDirs
2018-06-30 17:46:11 +00:00
REMOTE_HOST_PING = $RHOST_PING $OSYNC_EXECUTABLE ${ osyncParameters [ $__confLocal ] }
2016-11-19 13:21:42 +00:00
assertEquals "Basic local test without remote access." "0" $?
}
2016-09-05 20:21:25 +00:00
. " $TESTS_DIR /shunit2/shunit2 "