#!/usr/bin/make -f

include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@  --with python3

override_dh_auto_clean:
	python3 setup.py clean
	rm -f debian/*.init debian/*.service debian/*.upstart debian/mistral-common.postinst debian/mistral-common.config
	rm -rf debian/mistral-common.postrm debian/*.templates debian/po debian/mistral-api.config debian/mistral-api.postinst
	rm -rf build .stestr *.egg-info
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-common.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-common.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-api.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-api.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_postrm mistral-common.postrm
	pkgos-merge-templates mistral-api mistral endpoint
	pkgos-merge-templates mistral-common mistral db rabbit ksat

override_dh_auto_install:
	echo "Do nothing..."

override_dh_auto_test:
	echo "Do nothing..."

override_dh_install:
	set -e ; for pyvers in $(PYTHON3S); do \
		python$$pyvers setup.py install --install-layout=deb --root $(CURDIR)/debian/tmp; \
	done

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test --no-py2 --serial 'mistral\.tests\.unit\.(?!(actions\.openstack\.test_generator\.GeneratorTest\.test_generator.*|api\.v2\.test_action_executions\.TestActionExecutionsController\.test_get_all_with_and_without_output.*|actions\.test_std_mistral_http_action\.MistralHTTPActionTest\.test_http_action.*|actions\.test_std_http_action\.HTTPActionTest\.test_http_action.*|engine\.test_action_heartbeat_checker\.ActionHeartbeatCheckerTest\.test_fail_action_with_missing_heartbeats_wf_spec_not_cached.*|engine\.test_dataflow\.DataFlowTest\.test_context_view_eval_keys.*|engine\.test_action_heartbeat_sender\.ActionHeartbeatSenderRemoteExecutorTest\.test_long_action_failure_with_disabled_sender.*|engine\.test_action_heartbeat_sender\.ActionHeartbeatSenderLocalExecutorTest\.test_long_action_failure_with_disabled_sender|scheduler\.test_default_scheduler\.DefaultSchedulerTest.*|services\.test_event_engine\.EventEngineTest\.test_process_event_queue.*|services\.test_event_engine\.EventEngineTest\.test_event_engine_public_trigger.*|engine\.test_action_heartbeat_checker\.ActionHeartbeatCheckerTest\.test_fail_action_with_missing_heartbeats.*))'
endif


	# Copy the configuration files
	set -e ; for i in logging.conf wf_trace_logging.conf ; do \
		install -D -m 0664 etc/$$i.sample $(CURDIR)/debian/mistral-common/usr/share/mistral-common/$$i ; \
	done
	install -D -m 0664 etc/policy.json $(CURDIR)/debian/mistral-common/usr/share/mistral-common/policy.json ; \
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslo-config-generator \
		--namespace mistral.config \
		--namespace cotyledon \
		--namespace oslo.concurrency \
		--namespace oslo.db \
		--namespace oslo.messaging \
		--namespace oslo.middleware.cors \
		--namespace oslo.middleware.healthcheck \
		--namespace oslo.middleware.http_proxy_to_wsgi \
		--namespace keystonemiddleware.auth_token \
		--namespace oslo.log \
		--namespace oslo.policy \
		--namespace oslo.service.sslutils \
		--output-file $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf
	pkgos-readd-keystone-authtoken-missing-options $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf keystone_authtoken mistral

	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslopolicy-sample-generator \
		--output-file $(CURDIR)/debian/mistral-common/usr/share/mistral-common/policy.json \
		--format json \
		--namespace mistral

	pkgos-fix-config-default $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf keystone_authtoken auth_protocol http

	dh_install
	dh_missing --fail-missing

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
