#!/usr/bin/make -f

UPSTREAM_GIT := https://opendev.org/x/ovn-bgp-agent
include /usr/share/openstack-pkg-tools/pkgos.make

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

override_dh_auto_clean:
	rm -rf build *.egg-info $(CURDIR)/debian/ovn-bgp-agent.init $(CURDIR)/debian/ovn-bgp-agent.service
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done

override_dh_auto_build:
	echo "Doing nothing..."

override_dh_auto_install:
	echo "Do nothing..."

override_dh_auto_test:
	echo "Do nothing..."

override_dh_install:
	pkgos-dh_auto_install --no-py2 --in-tmp
		
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test --no-py2 'ovn_bgp_agent\.tests\.unit\.(?!utils\.test_linux_net\.TestLinuxNet\.test_add_ips_to_dev|utils\.test_linux_net\.TestLinuxNet\.test_del_ips_from_dev|utils\.test_linux_net\.TestLinuxNet\.test_delete_ip_routes)'
endif

	mkdir -p $(CURDIR)/debian/ovn-bgp-agent/etc/ovn-bgp-agent
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslo-config-generator \
		--namespace ovnbgpagent \
		--output-file $(CURDIR)/debian/ovn-bgp-agent/etc/ovn-bgp-agent/bgp-agent.conf

	dh_install
	mkdir -p $(CURDIR)/debian/ovn-bgp-agent/etc/ovn-bgp-agent
	mv $(CURDIR)/debian/tmp/usr/etc/ovn-bgp-agent/* $(CURDIR)/debian/ovn-bgp-agent/etc/ovn-bgp-agent
	rmdir $(CURDIR)/debian/tmp/usr/etc/ovn-bgp-agent
	rmdir $(CURDIR)/debian/tmp/usr/etc
	dh_missing --fail-missing


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