#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export PYBUILD_NAME=neutron

SHELL := /bin/sh -e

DEBVERS ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION ?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/[+].*//' -e 's/~git.*//g' -e 's/~/./g')
export PBR_VERSION=$(VERSION)

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

%:
	dh $@  --with python3 --buildsystem=pybuild


override_dh_install:
	rm -rf $(CURDIR)/debian/python3-neutron/usr/etc/neutron
	PYTHONPATH=$(CURDIR) $(CURDIR)/tools/generate_config_file_samples.sh
	find $(CURDIR)/etc -type f | xargs rename 's/\.sample$$//'a
	crudini --merge $(CURDIR)/etc/neutron.conf < $(CURDIR)/debian/neutron.conf.defaults
	crudini --merge $(CURDIR)/etc/neutron_ovn_metadata_agent.ini < $(CURDIR)/debian/neutron_ovn_metadata_agent.ini.defaults
	dh_install
	dh_missing --fail-missing -X/usr/etc

override_dh_installsystemd:
	dh_installsystemd \
		-pneutron-openvswitch-agent --name=neutron-ovs-cleanup \
		--no-start --no-stop-on-upgrade --no-restart-after-upgrade \
		neutron-ovs-cleanup.service
	dh_installsystemd -Xneutron-ovs-cleanup.service \
		-pneutron-linuxbridge-agent --name=neutron-linuxbridge-cleanup \
		--no-start --no-stop-on-upgrade --no-restart-after-upgrade \
		neutron-linuxbridge-cleanup.service
	dh_installsystemd -Xneutron-ovs-cleanup.service -Xneutron-linuxbridge-cleanup.service

override_dh_installinit:
	dh_installinit \
		-pneutron-openvswitch-agent --name=neutron-ovs-cleanup \
		--no-start --no-stop-on-upgrade
	dh_installinit -Xneutron-ovs-cleanup \
		-pneutron-linuxbridge-agent --name=neutron-linuxbridge-cleanup \
		--no-start --no-stop-on-upgrade
	dh_installinit -Xneutron-ovs-cleanup -Xneutron-linuxbridge-cleanup \
		--error-handler=true

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/*.upstart debian/*.init debian/*.service .testrepository

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	OS_TEST_TIMEOUT=180 OS_LOG_CAPTURE=true OS_STDOUT_CAPTURE=true OS_STDERR_CAPTURE=true \
	PYTHONWARNINGS=default::DeprecationWarning,ignore::DeprecationWarning:distutils,ignore::DeprecationWarning:site \
	pkgos-dh_auto_test --no-py2
endif

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