#!/usr/bin/make -f

PYTHONS:=$(shell pyversions -vr)
#PYTHON3S:=$(shell py3versions -vr)

UPSTREAM_GIT = git://github.com/stackforge/rally.git

include /usr/share/openstack-pkg-tools/pkgos.make
export OSLO_PACKAGE_VERSION=$(VERSION)

%:
	dh $@  --with python2

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	@echo "===> Running tests"
	set -e ; set -x ; for i in 2.7 ; do \
		PYMAJOR=`echo $$i | cut -d'.' -f1` ; \
		echo "===> Testing with python$$i (python$$PYMAJOR)" ; \
		rm -rf .testrepository ; \
		testr-python$$PYMAJOR init ; \
		TEMP_REZ=`mktemp -t` ; \
		PYTHONPATH=$(CURDIR) PYTHON=python$$i testr-python$$PYMAJOR run --subunit 'tests\.unit\.(?!(.*deploy.serverprovider.providers.test_lxc.LxcHostTestCase.test_prepare.*|.*deploy.test_lxc.LxcEngineTestCase.test_cleanup.*))' | tee $$TEMP_REZ | subunit2pyunit ; \
		cat $$TEMP_REZ | subunit-filter -s --no-passthrough | subunit-stats ; \
		rm -f $$TEMP_REZ ; \
		testr-python$$PYMAJOR slowest ; \
	done
endif

override_dh_auto_build:
	dh_auto_build
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func rally.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func rally.postinst

override_dh_clean:
	dh_clean
	rm -rf build debian/rally.config debian/rally.postinst

override_dh_install:
	dh_install --fail-missing -Xetc/bash_completion.d/rally.bash_completion
	
	install -D -m 0644 $(CURDIR)/etc/rally.bash_completion $(CURDIR)/debian/rally/usr/share/bash-completion/completions/rally
	install -D -m 0644 $(CURDIR)/etc/rally/rally.conf.sample $(CURDIR)/debian/rally/usr/share/rally/rally.conf
	sed -i 's|^[ \t#]connection[ \t]*=|connection=sqlite:///var/lib/rally/rally.db|' $(CURDIR)/debian/rally/usr/share/rally/rally.conf

	# This shells script is broken, so I'm removing it.
	rm $(CURDIR)/debian/rally/usr/share/rally/samples/tasks/support/instance_linpack.sh
