Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Refactoring integration job to archive logs on error
Browse files Browse the repository at this point in the history
Currently if the stack.sh fails, the openstack project
logs are not archived.

Change-Id: If48f27bc6e5e0ee2eacecbf5358a8d4884e7f267
Closes-bug: #1466224
  • Loading branch information
snaiksat committed Jun 17, 2015
1 parent f587c5f commit e4ac752
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
31 changes: 31 additions & 0 deletions gbpservice/tests/contrib/functions-gbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

TOP_DIR="$BASE/new/devstack"
NEW_BASE="$BASE/new"
GBP_DIR="$NEW_BASE/group-based-policy"
SCRIPTS_DIR="/usr/local/jenkins/slave_scripts"
LOGS_DIR="$NEW_BASE/logs"
ARCHIVE_LOGS_DIR="$BASE/logs"

# Prepare the log files for Jenkins to upload
function prepare_logs {
cd $LOGS_DIR
for f in $(find . -name "*.log.2*"); do
sudo mv $f ${f/.log.*/.txt}
done
sudo gzip -9fk `find . -maxdepth 1 \! -type l -name "*.txt" | xargs ls -d`
mv *.gz $ARCHIVE_LOGS_DIR/
}

function generate_testr_results {
# Give job user rights to access tox logs
sudo -H chmod o+rw .
sudo -H chmod o+rw -R .testrepository
if [ -f ".testrepository/0" ] ; then
.tox/dsvm-functional/bin/subunit-1to2 < .testrepository/0 > ./testrepository.subunit
.tox/dsvm-functional/bin/python $SCRIPTS_DIR/subunit2html.py ./testrepository.subunit testr_results.html
gzip -9 ./testrepository.subunit
gzip -9 ./testr_results.html
sudo mv ./*.gz $ARCHIVE_LOGS_DIR/
fi
}
8 changes: 6 additions & 2 deletions gbpservice/tests/contrib/gate_hook.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash

set -ex
cp /opt/stack/new/group-based-policy/gbpservice/tests/contrib/functions-gbp .
source functions-gbp

set -x

trap prepare_logs ERR

TOP_DIR=$BASE/new/devstack
cd $TOP_DIR
sudo git remote add group-policy http://github.com/group-policy/devstack
sudo git fetch group-policy
Expand Down
51 changes: 5 additions & 46 deletions gbpservice/tests/contrib/post_test_hook.sh
Original file line number Diff line number Diff line change
@@ -1,76 +1,35 @@
#!/bin/bash

set -xe
source functions-gbp

NEW_BASE="$BASE/new"
GBP_DIR="$NEW_BASE/group-based-policy"
SCRIPTS_DIR="/usr/local/jenkins/slave_scripts"
LOGS_DIR="$NEW_BASE/logs"

function generate_testr_results {
# Give job user rights to access tox logs
sudo -H chmod o+rw .
sudo -H chmod o+rw -R .testrepository
if [ -f ".testrepository/0" ] ; then
.tox/dsvm-functional/bin/subunit-1to2 < .testrepository/0 > ./testrepository.subunit
.tox/dsvm-functional/bin/python $SCRIPTS_DIR/subunit2html.py ./testrepository.subunit testr_results.html
gzip -9 ./testrepository.subunit
gzip -9 ./testr_results.html
sudo mv ./*.gz /opt/stack/logs/
fi
}


function dsvm_functional_prep_func {
:
}
set -x

# Check if any gbp exercises failed
set +e
exercises_exit_code=0
if grep -qs "FAILED gbp*" $LOGS_DIR/*; then
exercises_exit_code=1
fi
set -e

prep_func="dsvm_functional_prep_func"

# Run tests
# Run integration tests
echo "Running gbpfunc test suite"
set +e
cd $NEW_BASE/devstack
source openrc demo demo
cd $NEW_BASE
sudo git clone https://github.com/noironetworks/devstack -b jishnub/testsuites gbpfunctests
cd gbpfunctests/testcases/testcases_func
python suite_run.py -s func
gbpfunc_exit_code=$?
set -e

# Set owner permissions according to job's requirements.
# Run functional tests
cd $GBP_DIR
# Prep the environment according to job's requirements.
$prep_func

# Run tests
echo "Running group-based-policy dsvm-functional test suite"
set +e
# Temporary workaround for subunit not getting installed in tox environment
sudo -H tox -e dsvm-functional
testr_exit_code=$?
set -e

# Collect and parse results
generate_testr_results

# Prepare the log files for Jenkins to upload
set +e
cd $LOGS_DIR
for f in $(find . -name "*.log.2*"); do
sudo mv $f ${f/.log.*/.txt}
done
sudo gzip -9fk `find . -maxdepth 1 \! -type l -name "*.txt" | xargs ls -d`
mv *.gz /opt/stack/logs/
set -e
prepare_logs

exit $(($exercises_exit_code+$gbpfunc_exit_code+$testr_exit_code))

0 comments on commit e4ac752

Please sign in to comment.