#!/bin/sh

set -e

EXCLUDE_FILE=/etc/tempest/exclude.conf
TMP_EXCLUDE=`mktemp -t nose-exclude-XXXXXX`
if [ -r "${EXCLUDE_FILE}" ] ; then
	for i in `grep -v -e '^#' -e '^[ \t]*$' ${EXCLUDE_FILE}` ; do
		if [ -n "${A}" ] ; then
			A="${A}|"'.*'"${i}"'.*'
		else
			A='.*'${i}'.*'
		fi
	done
fi

cd /var/lib/tempest

if [ ! -d .stestr ] ; then
	PYTHON=python3 stestr init
fi

if [ -z "${1}" ] && [ -n ${A} ] ; then
	PYTHON=python3 stestr run --parallel --concurrency=2 --subunit '^(?!('"${A}"'))' $@ | subunit-trace
else
	PYTHON=python3 stestr run --parallel --concurrency=2 --subunit $@ | subunit-trace
fi

#testr run --parallel --subunit $@ | subunit-trace
