From 9cbad100ed3bffbda8d90d5edb289d938ad7e738 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Wed, 5 Apr 2023 11:09:19 +0200 Subject: [PATCH] Feature 10981: skeleton of osm_webhook_translator package Change-Id: I80217214941241e1e97dee80b978e0f1e55f4d1a Signed-off-by: garciadeblas --- .gitignore | 2 + devops-stages/stage-build.sh | 22 ++++++++- osm_webhook_translator/README.rst | 33 +++++++++++++ osm_webhook_translator/requirements-dist.in | 18 +++++++ osm_webhook_translator/requirements-dist.txt | 32 +++++++++++++ osm_webhook_translator/requirements.in | 20 ++++++++ osm_webhook_translator/requirements.txt | 48 +++++++++++++++++++ osm_webhook_translator/setup.py | 43 +++++++++++++++++ .../src/osm_webhook_translator/__init__.py | 17 +++++++ tox.ini | 34 +++++++++++-- 10 files changed, 263 insertions(+), 6 deletions(-) create mode 100644 osm_webhook_translator/README.rst create mode 100644 osm_webhook_translator/requirements-dist.in create mode 100644 osm_webhook_translator/requirements-dist.txt create mode 100644 osm_webhook_translator/requirements.in create mode 100644 osm_webhook_translator/requirements.txt create mode 100644 osm_webhook_translator/setup.py create mode 100644 osm_webhook_translator/src/osm_webhook_translator/__init__.py diff --git a/.gitignore b/.gitignore index fb6947e..c6f5743 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,6 @@ dist *.local local +# Version files src/osm_ngsa/_version.py +osm_webhook_translator/src/osm_webhook_translator/_version.py diff --git a/devops-stages/stage-build.sh b/devops-stages/stage-build.sh index 7b483a8..780d6c7 100755 --- a/devops-stages/stage-build.sh +++ b/devops-stages/stage-build.sh @@ -16,6 +16,26 @@ # limitations under the License. # +set -ex + rm -rf dist deb_dist osm*.tar.gz *.egg-info .eggs -tox -e dist +for p in "osm_webhook_translator"; do + rm -rf $p/dist $p/deb_dist $p/osm*.tar.gz $p/*.egg-info $p/.eggs +done + +mkdir -p deb_dist +mkdir -p osm_webhook_translator/deb_dist + +PACKAGES=" +dist_ng_sa +dist_webhook_translator" + +TOX_ENV_LIST="$(echo $PACKAGES | sed "s/ /,/g")" + +tox -e $TOX_ENV_LIST + +# Copying packages +# Webhook Translator +cp osm_webhook_translator/deb_dist/python3-osm-webhook-translator_*.deb deb_dist/ + diff --git a/osm_webhook_translator/README.rst b/osm_webhook_translator/README.rst new file mode 100644 index 0000000..a84b409 --- /dev/null +++ b/osm_webhook_translator/README.rst @@ -0,0 +1,33 @@ +.. + ####################################################################################### + # Copyright ETSI Contributors and Others. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + # implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ####################################################################################### + +================== +webhook-translator +================== + +webhook-translator is a component in the Service Assurance architecture for OSM. + +Its role is to receive alerts from entities such as Prometheus AlertManager or external systems, and to translate them to a format that can be consumed by Airflow DAGs. It basically receives HTTP POST messages and forwards them to an Airflow webhook + +The main characteristics are: + +* Lightweight: a very small number of lines of code does the work. +* Stateless. It only translates HTTP requests. No state for those translations. When running as a Kubernetes deployment, native scaling is achieved by means of Kubernetes services. +* Simple. Based on `FastAPI ` +* Independent from the source of the alert. No maintenance is required to incorporate new alert sources. + diff --git a/osm_webhook_translator/requirements-dist.in b/osm_webhook_translator/requirements-dist.in new file mode 100644 index 0000000..03ff6e9 --- /dev/null +++ b/osm_webhook_translator/requirements-dist.in @@ -0,0 +1,18 @@ +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +stdeb +setuptools-scm +setuptools<60 diff --git a/osm_webhook_translator/requirements-dist.txt b/osm_webhook_translator/requirements-dist.txt new file mode 100644 index 0000000..6ddded6 --- /dev/null +++ b/osm_webhook_translator/requirements-dist.txt @@ -0,0 +1,32 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### +packaging==23.0 + # via setuptools-scm +setuptools-scm==7.1.0 + # via -r osm_webhook_translator/requirements-dist.in +stdeb==0.10.0 + # via -r osm_webhook_translator/requirements-dist.in +tomli==2.0.1 + # via setuptools-scm +typing-extensions==4.5.0 + # via setuptools-scm + +# The following packages are considered to be unsafe in a requirements file: +setuptools==59.8.0 + # via + # -r osm_webhook_translator/requirements-dist.in + # setuptools-scm diff --git a/osm_webhook_translator/requirements.in b/osm_webhook_translator/requirements.in new file mode 100644 index 0000000..33c6214 --- /dev/null +++ b/osm_webhook_translator/requirements.in @@ -0,0 +1,20 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### + +fastapi +requests +uvicorn diff --git a/osm_webhook_translator/requirements.txt b/osm_webhook_translator/requirements.txt new file mode 100644 index 0000000..6cf7f42 --- /dev/null +++ b/osm_webhook_translator/requirements.txt @@ -0,0 +1,48 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### +anyio==3.6.2 + # via starlette +certifi==2022.12.7 + # via requests +charset-normalizer==3.1.0 + # via requests +click==8.1.3 + # via uvicorn +fastapi==0.95.0 + # via -r osm_webhook_translator/requirements.in +h11==0.14.0 + # via uvicorn +idna==3.4 + # via + # anyio + # requests +pydantic==1.10.7 + # via fastapi +requests==2.28.2 + # via -r osm_webhook_translator/requirements.in +sniffio==1.3.0 + # via anyio +starlette==0.26.1 + # via fastapi +typing-extensions==4.5.0 + # via + # pydantic + # starlette +urllib3==1.26.15 + # via requests +uvicorn==0.21.1 + # via -r osm_webhook_translator/requirements.in diff --git a/osm_webhook_translator/setup.py b/osm_webhook_translator/setup.py new file mode 100644 index 0000000..3323757 --- /dev/null +++ b/osm_webhook_translator/setup.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from setuptools import find_namespace_packages, setup + +exec(open("src/osm_webhook_translator/_version.py").read()) + +_name = "osm_webhook_translator" +_description = "OSM Webhook Translator" +with open(os.path.join(".", "README.rst")) as readme_file: + README = readme_file.read() + +setup( + name=_name, + description=_description, + long_description=README, + version=__version__, # noqa: F821 + author="ETSI OSM", + author_email="osmsupport@etsi.org", + maintainer="ETSI OSM", + maintainer_email="osmsupport@etsi.org", + url="https://osm.etsi.org/gitweb/?p=osm/NG-SA.git;a=summary", + license="Apache 2.0", + package_dir={"": "src"}, + packages=find_namespace_packages(where="src"), + include_package_data=True, +) diff --git a/osm_webhook_translator/src/osm_webhook_translator/__init__.py b/osm_webhook_translator/src/osm_webhook_translator/__init__.py new file mode 100644 index 0000000..d5daf3e --- /dev/null +++ b/osm_webhook_translator/src/osm_webhook_translator/__init__.py @@ -0,0 +1,17 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### +from osm_webhook_translator._version import __version__ # noqa: F401 diff --git a/tox.ini b/tox.ini index 3301d0b..6c750c9 100644 --- a/tox.ini +++ b/tox.ini @@ -37,6 +37,7 @@ deps = black skip_install = true commands = black --check --diff src setup.py + black --check --diff osm_webhook_translator ####################################################################################### @@ -49,7 +50,9 @@ commands = sh -c 'rm -f nosetests.xml' coverage erase nose2 -C --coverage src -s src - sh -c 'mv .coverage .coverage_mon' + sh -c 'mv .coverage .coverage_ngsa' + nose2 -C --coverage osm_webhook_translator -s osm_webhook_translator + sh -c 'mv .coverage .coverage_webhook_translator' coverage report --omit='*tests*' coverage html -d ./cover --omit='*tests*' coverage xml -o coverage.xml --omit='*tests*' @@ -61,6 +64,7 @@ deps = flake8==5.0.4 flake8-import-order commands = flake8 src setup.py + flake8 osm_webhook_translator ####################################################################################### @@ -72,6 +76,7 @@ deps = {[testenv]deps} skip_install = true commands = pylint -E src + pylint -E osm_webhook_translator ####################################################################################### @@ -100,15 +105,20 @@ commands = out=`echo $file | sed 's/.in/.txt/'` ; \ sed -i -e '1 e head -16 tox.ini' $out ;\ done" + bash -c "for file in osm_webhook_translator/requirements*.in ; do \ + UNSAFE="" ; \ + if [[ $file =~ 'dist' ]] ; then UNSAFE='--allow-unsafe' ; fi ; \ + pip-compile -rU --no-header $UNSAFE $file ;\ + out=`echo $file | sed 's/.in/.txt/'` ; \ + sed -i -e '1 e head -16 tox.ini' $out ;\ + done" ####################################################################################### -[testenv:dist] +[testenv:dist_ng_sa] deps = {[testenv]deps} -r{toxinidir}/requirements-dist.txt - -# In the commands, we copy the requirements.txt to be presented as a source file (.py) -# so it gets included in the .deb package for others to consume +allowlist_externals = sh commands = sh -c 'cp requirements.txt src/osm_ngsa/requirements.txt' sh -c 'cp README.rst src/osm_ngsa/README.rst' @@ -116,7 +126,21 @@ commands = sh -c 'cd deb_dist/osm-ngsa*/ && dpkg-buildpackage -rfakeroot -uc -us' sh -c 'rm src/osm_ngsa/requirements.txt' sh -c 'rm src/osm_ngsa/README.rst' + + +####################################################################################### +[testenv:dist_webhook_translator] +deps = -r{toxinidir}/osm_webhook_translator/requirements.txt + -r{toxinidir}/osm_webhook_translator/requirements-dist.txt allowlist_externals = sh +commands = + sh -c 'cp src/osm_ngsa/_version.py osm_webhook_translator/src/osm_webhook_translator/_version.py' + sh -c 'cd osm_webhook_translator && cp requirements.txt src/osm_webhook_translator/requirements.txt' + sh -c 'cd osm_webhook_translator && cp README.rst src/osm_webhook_translator/README.rst' + sh -c 'cd osm_webhook_translator && python3 setup.py --command-packages=stdeb.command sdist_dsc' + sh -c 'cd osm_webhook_translator/deb_dist/osm-webhook-translator*/ && dpkg-buildpackage -rfakeroot -uc -us' + sh -c 'rm osm_webhook_translator/src/osm_webhook_translator/requirements.txt' + sh -c 'rm osm_webhook_translator/src/osm_webhook_translator/README.rst' ####################################################################################### -- 2.25.1