From d0fea7ea94e262be18a0f473eebd7e7239d892b2 Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Wed, 26 Sep 2018 20:12:58 -0300 Subject: [PATCH] Adds pip installation of python deps in deb package install Adds postinst script Adds Makefile (there is an issue when using postinst with tox) Adds stdeb.cfg declaring binary dependencies Reenables flake8 in tox Removes consumer timeout that should have never been there Readds group_id in kafka consumer Signed-off-by: Benjamin Diaz Change-Id: Ied0cb6135aee5f08cfd36c9cbaafa4c174b7434f --- .gitignore | 4 ++++ Dockerfile | 8 ++++---- MANIFEST.in | 3 +-- Makefile | 9 +++++++++ debian/python3-osm-policy-module.postinst | 9 +++++++++ devops-stages/stage-build.sh | 5 +---- osm_policy_module/core/agent.py | 5 +---- stdeb.cfg | 3 +++ tox.ini | 14 ++++++-------- 9 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 Makefile create mode 100644 debian/python3-osm-policy-module.postinst create mode 100644 stdeb.cfg diff --git a/.gitignore b/.gitignore index f4d6bb1..88962fe 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,7 @@ ChangeLog .settings/ __pycache__/ .idea + +deb_dist +*.tar.gz +*.db \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 6738633..f3af477 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ FROM ubuntu:16.04 RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get --yes install git tox make python python-pip python3 python3-pip debhelper && \ - DEBIAN_FRONTEND=noninteractive apt-get --yes install wget python-dev python-software-properties python-stdeb && \ - DEBIAN_FRONTEND=noninteractive apt-get --yes install default-jre libmysqlclient-dev && \ - DEBIAN_FRONTEND=noninteractive apt-get --yes install libmysqlclient-dev libxml2 python3-all + DEBIAN_FRONTEND=noninteractive apt-get --yes install git tox make python-all python3 python3-pip debhelper wget && \ + DEBIAN_FRONTEND=noninteractive apt-get --yes install libmysqlclient-dev libxml2 python3-all && \ + DEBIAN_FRONTEND=noninteractive pip3 install -U setuptools setuptools-version-command stdeb + diff --git a/MANIFEST.in b/MANIFEST.in index ad2c95a..9dbb8cd 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -24,5 +24,4 @@ include requirements.txt include test-requirements.txt include README.rst recursive-include osm_policy_module *.py *.xml *.sh -recursive-include devops-stages * -recursive-include test *.py +recursive-include devops-stages * \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..586b73c --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: clean package + +clean: + rm -rf dist deb_dist osm_policy_module-*.tar.gz osm_policy_module.egg-info .eggs + +package: + python3 setup.py --command-packages=stdeb.command sdist_dsc + cp debian/python3-osm-policy-module.postinst deb_dist/osm-policy-module*/debian + cd deb_dist/osm-policy-module*/ && dpkg-buildpackage -rfakeroot -uc -us \ No newline at end of file diff --git a/debian/python3-osm-policy-module.postinst b/debian/python3-osm-policy-module.postinst new file mode 100644 index 0000000..3b24842 --- /dev/null +++ b/debian/python3-osm-policy-module.postinst @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "Installing python dependencies via pip..." +pip3 install kafka==1.3.* +pip3 install peewee==3.1.* +pip3 install jsonschema==2.6.* +pip3 install six==1.11.* +pip3 install pyyaml==3.* +echo "Installation of python dependencies finished" \ No newline at end of file diff --git a/devops-stages/stage-build.sh b/devops-stages/stage-build.sh index 4251b1c..8a8d332 100755 --- a/devops-stages/stage-build.sh +++ b/devops-stages/stage-build.sh @@ -23,7 +23,4 @@ #__date__ = "14/Sep/2017" #!/bin/bash -rm -rf deb_dist -rm -rf dist -rm -rf osm_mon.egg-info -tox -e build +make diff --git a/osm_policy_module/core/agent.py b/osm_policy_module/core/agent.py index 8309da1..410413f 100644 --- a/osm_policy_module/core/agent.py +++ b/osm_policy_module/core/agent.py @@ -51,13 +51,10 @@ class PolicyModuleAgent: cfg.OSMPOL_MESSAGE_PORT) def run(self): - cfg = Config.instance() - cfg.read_environ() - consumer = KafkaConsumer(bootstrap_servers=self.kafka_server, key_deserializer=bytes.decode, value_deserializer=bytes.decode, - consumer_timeout_ms=10000) + group_id='pol-consumer') consumer.subscribe(["ns", "alarm_response"]) for message in consumer: diff --git a/stdeb.cfg b/stdeb.cfg new file mode 100644 index 0000000..021202c --- /dev/null +++ b/stdeb.cfg @@ -0,0 +1,3 @@ +[DEFAULT] +X-Python3-Version : >= 3.4 +Depends3 : libmysqlclient-dev, python3-pip, python3-osm-common \ No newline at end of file diff --git a/tox.ini b/tox.ini index 4ef6a64..584efa7 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] -envlist = py3 +envlist = py3, flake8 toxworkdir={homedir}/.tox [testenv] @@ -40,12 +40,6 @@ deps = flake8 commands = flake8 osm_policy_module -[testenv:build] -basepython = python3 -deps = stdeb - setuptools-version-command -commands = python3 setup.py --command-packages=stdeb.command bdist_deb - [flake8] # E123, E125 skipped as they are invalid PEP-8. max-line-length = 120 @@ -54,4 +48,8 @@ ignore = E123,E125,E241 builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,devops_stages/*,.rst - +[testenv:build] +basepython = python3 +deps = stdeb + setuptools-version-command +commands = python3 setup.py --command-packages=stdeb.command bdist_deb -- 2.25.1