Fix of error handling in contrail backup
In cassandra-backup-client-runner-call.sh rsync command redirect to
log file only stdout and all error messages aren't caught by error
handling code.
Updating run_tests.sh
Closes-Bug: PROD-35981
Change-Id: Idd8a069d81c7e110c1cd988e42d7148c0dd5842a
diff --git a/cassandra/files/backup/cassandra-backup-client-runner-call.sh b/cassandra/files/backup/cassandra-backup-client-runner-call.sh
index e507f56..79805d2 100644
--- a/cassandra/files/backup/cassandra-backup-client-runner-call.sh
+++ b/cassandra/files/backup/cassandra-backup-client-runner-call.sh
@@ -125,13 +125,13 @@
ssh-keygen -R {{ backup.client.target.host }} 2>&1 | > $RSYNCLOG
ssh-keyscan {{ backup.client.target.host }} >> ~/.ssh/known_hosts 2>&1 | >> $RSYNCLOG
echo "Rsyncing files to remote host"
- /usr/bin/rsync -rhtPv --rsync-path=rsync --progress $BACKUPDIR/* -e ssh cassandra@{{ backup.client.target.host }}:$SERVERBACKUPDIR >> $RSYNCLOG
+ /usr/bin/rsync -rhtPv --rsync-path="mkdir -p $SERVERBACKUPDIR && rsync" --progress $BACKUPDIR/* -e ssh cassandra@{{ backup.client.target.host }}:$SERVERBACKUPDIR >> $RSYNCLOG 2>&1
# Check if the rsync succeeded or failed
if [ -s $RSYNCLOG ] && ! grep -q "rsync error: " $RSYNCLOG; then
echo "Rsync to remote host completed OK"
else
- echo "Rsync to remote host FAILED"
+ echo "Rsync to remote host FAILED. Check $RSYNCLOG for details"
exit 1
fi
{%- endif %}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 9761585..6542700 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -37,9 +37,13 @@
setup_virtualenv() {
log_info "Setting up Python virtualenv"
+ dependency_check virtualenv
virtualenv $VENV_DIR
source ${VENV_DIR}/bin/activate
python -m pip install salt${PIP_SALT_VERSION}
+ if [[ -f ${CURDIR}/test-requirements.txt ]]; then
+ python -m pip install -r ${CURDIR}/test-requirements.txt
+ fi
}
setup_mock_bin() {
@@ -145,14 +149,14 @@
salt_run grains.set 'noservices' False force=True
echo "Checking state ${FORMULA_NAME}.${state_name} ..."
- salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1)
+ salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1; }
# Check that all files in 'meta' folder can be rendered using any valid pillar
for meta in `find ${FORMULA_META_DIR} -type f`; do
meta_name=$(basename ${meta})
echo "Checking meta ${meta_name} ..."
salt_run --out=quiet --id=${state_name} cp.get_template ${meta} ${SALT_CACHE_DIR}/${meta_name} \
- || (log_err "Failed to render meta ${meta} using pillar ${FORMULA_NAME}.${state_name}"; exit 1)
+ || { log_err "Failed to render meta ${meta} using pillar ${FORMULA_NAME}.${state_name}"; exit 1; }
cat ${SALT_CACHE_DIR}/${meta_name}
done
done
@@ -161,10 +165,18 @@
real_run() {
for pillar in ${PILLARDIR}/*.sls; do
state_name=$(basename ${pillar%.sls})
- salt_run --id=${state_name} state.sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1)
+ salt_run --id=${state_name} state.sls ${FORMULA_NAME} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1; }
done
}
+dependency_check() {
+ local DEPENDENCY_COMMANDS=$*
+
+ for DEPENDENCY_COMMAND in $DEPENDENCY_COMMANDS; do
+ which $DEPENDENCY_COMMAND > /dev/null || ( log_err "Command \"$DEPENDENCY_COMMAND\" can not be found in default path."; exit 1; )
+ done
+}
+
_atexit() {
RETVAL=$?
trap true INT TERM EXIT
diff --git a/tests/test-requirements.txt b/tests/test-requirements.txt
new file mode 100644
index 0000000..bc7dc7f
--- /dev/null
+++ b/tests/test-requirements.txt
@@ -0,0 +1,4 @@
+jsonschema
+reno
+setuptools<45.0.0
+msgpack<1.0.0