diff options
Diffstat (limited to 'components/pm-subscription-handler')
19 files changed, 1107 insertions, 0 deletions
diff --git a/components/pm-subscription-handler/.coveragerc b/components/pm-subscription-handler/.coveragerc new file mode 100644 index 00000000..d1c3205b --- /dev/null +++ b/components/pm-subscription-handler/.coveragerc @@ -0,0 +1,43 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + +# .coveragerc to control coverage.py +[run] +branch = True +cover_pylib = False +include = */pmsh_service/*.py + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + +ignore_errors = True diff --git a/components/pm-subscription-handler/.gitignore b/components/pm-subscription-handler/.gitignore new file mode 100644 index 00000000..98ba212b --- /dev/null +++ b/components/pm-subscription-handler/.gitignore @@ -0,0 +1,100 @@ +mvn-phase-lib.sh +tox-local.ini +*.wgn +.pytest_cache/ +xunit-results.xml +.DS_Store +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +venv-tox/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +# Test report +xunit-reports +coverage-reports diff --git a/components/pm-subscription-handler/.gitreview b/components/pm-subscription-handler/.gitreview new file mode 100644 index 00000000..4acf10dd --- /dev/null +++ b/components/pm-subscription-handler/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=gerrit.onap.org +port=29418 +project=dcaegen2/services.git diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md new file mode 100644 index 00000000..87c282ff --- /dev/null +++ b/components/pm-subscription-handler/Changelog.md @@ -0,0 +1,7 @@ +# Change Log +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [1.0.0] - 11/4/2019
\ No newline at end of file diff --git a/components/pm-subscription-handler/Dockerfile b/components/pm-subscription-handler/Dockerfile new file mode 100644 index 00000000..e1dd16fe --- /dev/null +++ b/components/pm-subscription-handler/Dockerfile @@ -0,0 +1,55 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + +FROM python:3.7-slim-buster +MAINTAINER lego@est.tech + +ENV PMSHUSER=pmsh \ + APPDIR="/opt/app/pmsh" \ + # turn on file based EELF logging + PROD_LOGGING=1 \ + # set PATH & PYTHONPATH vars + PATH=/usr/local/lib/python3.7/bin:$PATH:$APPDIR/bin \ + PYTHONPATH=/usr/local/lib/python3.7/site-packages:./mod:./:$PYTHONPATH:$APPDIR/bin \ + REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt + +WORKDIR $APPDIR + + # add non root user & group +RUN addgroup --system $PMSHUSER && adduser --ingroup $PMSHUSER --system $PMSHUSER && \ + # create logs dir and change permissions + mkdir -p /var/log/ONAP/$PMSHUSER/logs && \ + chmod a+w /var/log/ONAP/$PMSHUSER/logs + +COPY setup.py ./ +COPY requirements.txt ./ +COPY ./pmsh_service ./bin/ + + # run the pip install +RUN pip install --upgrade pip && \ + pip install -r requirements.txt && \ + pip install -e . && \ + # change own & perms on entrypoint + chown -R $PMSHUSER:$PMSHUSER $APPDIR && \ + chmod 500 $APPDIR/bin/*.py + +# set to non root user +USER $PMSHUSER + +# run the app +ENTRYPOINT ["python", "./bin/pmsh_service.py"]
\ No newline at end of file diff --git a/components/pm-subscription-handler/LICENSE.txt b/components/pm-subscription-handler/LICENSE.txt new file mode 100644 index 00000000..e7116cbd --- /dev/null +++ b/components/pm-subscription-handler/LICENSE.txt @@ -0,0 +1,20 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + diff --git a/components/pm-subscription-handler/README.md b/components/pm-subscription-handler/README.md new file mode 100644 index 00000000..661d71f6 --- /dev/null +++ b/components/pm-subscription-handler/README.md @@ -0,0 +1,47 @@ +# pm_subscription_handler + + ============LICENSE_START======================================================= + Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= + + + +# Changelog +All changes are logged in Changelog.md + +# Overview + + + +# Usage + +# Assumptions +1. + + +# Development +## Version changes +Development changes require a version bump in several places. They are: +1. Changelod.md +2. version.properties +3. pom.xml +4. setup.py + +## Unit esting +You need `tox`; then just run: + + tox diff --git a/components/pm-subscription-handler/mvn-phase-script.sh b/components/pm-subscription-handler/mvn-phase-script.sh new file mode 100755 index 00000000..f51fa1ca --- /dev/null +++ b/components/pm-subscription-handler/mvn-phase-script.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +set -ex + +echo "running script: [$0] for module [$1] at stage [$2]" + +MVN_PROJECT_MODULEID="$1" +MVN_PHASE="$2" +PROJECT_ROOT=$(dirname $0) + + +echo "MVN_RELEASE_TAG is set to [$MVN_RELEASE_TAG]" +RELEASE_TAG=${MVN_RELEASE_TAG:-R6} +if [[ "$RELEASE_TAG" != "R1" ]]; then + RELEASE_TAGGED_DIR="${RELEASE_TAG}/" +else + RELEASE_TAGGED_DIR="" +fi + + +if [[ ! -f "${PROJECT_ROOT}/mvn-phase-lib.sh" ]]; then + if ! wget -O ${PROJECT_ROOT}/mvn-phase-lib.sh \ + "$MVN_RAWREPO_BASEURL_DOWNLOAD"/org.onap.dcaegen2.utils/${RELEASE_TAGGED_DIR}scripts/mvn-phase-lib.sh; then + echo "Fail to download mvn-phase-lib.sh" + exit 1 + fi +fi + +source ./mvn-phase-lib.sh + +# Customize the section below for each project +case ${MVN_PHASE} in +clean) + echo "==> clean phase script" + clean_templated_files + clean_tox_files + rm -rf ./venv-* ./*.wgn + ;; +generate-sources) + echo "==> generate-sources phase script" + ;; +compile) + echo "==> compile phase script" + ;; +test) + echo "==> test phase script" + run_tox_test + ;; +package) + echo "==> package phase script" + ;; +install) + echo "==> install phase script" + ;; +deploy) + echo "==> deploy phase script" + # below segments are example of how to deploy various artifacts + # copy the ones suitable for your repo + + # build docker image from Docker file (under root of repo) and push to registry + build_and_push_docker + ;; +*) + echo "==> unprocessed phase" + ;; +esac + diff --git a/components/pm-subscription-handler/pmsh_service/__init__.py b/components/pm-subscription-handler/pmsh_service/__init__.py new file mode 100644 index 00000000..d2f6f2fd --- /dev/null +++ b/components/pm-subscription-handler/pmsh_service/__init__.py @@ -0,0 +1,21 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + + +# empty __init__.py so that pytest can add correct path to coverage report, +# -- per pytest best practice guideline diff --git a/components/pm-subscription-handler/pmsh_service/mod/__init__.py b/components/pm-subscription-handler/pmsh_service/mod/__init__.py new file mode 100644 index 00000000..d2f6f2fd --- /dev/null +++ b/components/pm-subscription-handler/pmsh_service/mod/__init__.py @@ -0,0 +1,21 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + + +# empty __init__.py so that pytest can add correct path to coverage report, +# -- per pytest best practice guideline diff --git a/components/pm-subscription-handler/pmsh_service/mod/pmsh_logging.py b/components/pm-subscription-handler/pmsh_service/mod/pmsh_logging.py new file mode 100644 index 00000000..30c8db8e --- /dev/null +++ b/components/pm-subscription-handler/pmsh_service/mod/pmsh_logging.py @@ -0,0 +1,285 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + +import logging as log +from logging.handlers import RotatingFileHandler +from os import makedirs +import datetime + +# These loggers will be overwritten with EELF logging when running in Docker +_AUDIT_LOGGER = log.getLogger("defaultlogger") +_ERROR_LOGGER = log.getLogger("defaultlogger") +_METRICS_LOGGER = log.getLogger("defaultlogger") + +# Set up debug logger +_DEBUG_LOGGER = log.getLogger("defaultlogger") + + +def _create_logger(name, logfile): + """ + Create a RotatingFileHandler and a streamhandler for stdout + https://docs.python.org/3/library/logging.handlers.html + what's with the non-pythonic naming in these stdlib methods? Shameful. + """ + logger = log.getLogger(name) + file_handler = RotatingFileHandler(logfile, maxBytes=10000000, # 10 meg with one backup.., + backupCount=2) + formatter = log.Formatter("%(message)s") + file_handler.setFormatter(formatter) + logger.setLevel(log.DEBUG) + logger.addHandler(file_handler) + return logger + + +# Public + +def get_module_logger(mod_name): + """ + To use this, do logger = get_module_logger(__name__) + """ + logger = log.getLogger(mod_name) + handler = log.StreamHandler() + formatter = log.Formatter("%(asctime)s " + "[%(name)-12s] " + "%(levelname)-8s " + "%(message)s") + handler.setFormatter(formatter) + logger.addHandler(handler) + logger.setLevel(log.DEBUG) + return logger + + +def create_loggers(): + """ + Public method to set the global logger, launched from Run + This is *not* launched during unit testing, so unit tests do not + create/write log files + """ + makedirs("/var/log/ONAP/pmsh/logs", exist_ok=True) + + # create the audit log + aud_file = "/var/log/ONAP/pmsh/logs/audit.log" + open(aud_file, "a").close() # this is like "touch" + global _AUDIT_LOGGER + _AUDIT_LOGGER = _create_logger("pmsh_service_audit", aud_file) + + # create the error log + err_file = "/var/log/ONAP/pmsh/logs/error.log" + open(err_file, "a").close() # this is like "touch" + global _ERROR_LOGGER + _ERROR_LOGGER = _create_logger("pmsh_service_error", err_file) + + # create the metrics log + met_file = "/var/log/ONAP/pmsh/logs/metrics.log" + open(met_file, "a").close() # this is like "touch" + global _METRICS_LOGGER + _METRICS_LOGGER = _create_logger("pmsh_service_metrics", met_file) + + # create the debug log + debug_file = "/var/log/ONAP/pmsh/logs/debug.log" + open(debug_file, "a").close() # this is like "touch" + global _DEBUG_LOGGER + _DEBUG_LOGGER = _create_logger("pmsh_service_debug", debug_file) + + +def utc(): + """gets current time in utc""" + return datetime.datetime.utcnow() + + +def debug(msg="n/a"): + """ + This can be extended/modified to suit pmsh needs + """ + ets = utc() + + _DEBUG_LOGGER.info( + "{ets}|{msg}".format( + ets=ets.isoformat(), + msg=msg, + ) + ) + + +""" +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +These loggers can be modified to suit the pmsh functionality +""" + + +def audit(raw_request, bts, xer, rcode, calling_mod, msg="n/a"): + """ + write an EELF error record per + 'https://wiki.onap.org/download/attachments/1015849/ + ONAP%20application%20logging%20guidelines.pdf?api=v2' + + %The audit fields implemented: + + 1 BeginTimestamp Implemented (bts) + 2 EndTimestamp Auto Injected when this is called + 3 RequestID Implemented (xer) + 5 threadId n/a + 7 serviceName Implemented (from Req) + 9 StatusCode Auto injected based on rcode + 10 ResponseCode Implemented (rcode) + 13 Category log level - all audit records are INFO. + 15 Server IP address Implemented (from Req) + 16 ElapsedTime Auto Injected (milliseconds) + 17 Server This is running in a Docker container so this is + not applicable, my HOSTNAME is always + "config_binding_service" + 18 ClientIPaddress Implemented (from Req) + 19 class name Implemented (mod), though docs say OOP, + I am using the python module here + 20 Unused ...implemented.... + 21-25 Custom n/a + 26 detailMessage Implemented (msg) + + Not implemented + 4 serviceInstanceID - ? + 6 physical/virtual server name (Optional) + 8 PartnerName - nothing in the request tells me this + 11 Response Description - the CBS follows standard HTTP + error codes so look them up + 12 instanceUUID - Optional + 14 Severity (Optional) + """ + ets = utc() + + _AUDIT_LOGGER.info( + "{bts}|{ets}|{xer}||n/a||{path}||{status}|{rcode}|||INFO||{servip}|{et}|" + "config_binding_service|{clientip}|{calling_mod}|||||||{msg}".format( + bts=bts.isoformat(), + ets=ets.isoformat(), + xer=xer, + rcode=rcode, + path=raw_request.path.split("/")[1], + status="COMPLETE" if rcode < 400 else "ERROR", + servip=raw_request.host.split(":")[0], + et=int((ets - bts).microseconds / 1000), + clientip=raw_request.remote_addr, + calling_mod=calling_mod, + msg=msg, + ) + ) + + +def error(raw_request, xer, severity, ecode, tgt_entity="n/a", + tgt_path="n/a", msg="n/a", adv_msg="n/a"): + """ + write an EELF error record per + 'https://wiki.onap.org/download/attachments/1015849/ + ONAP%20application%20logging%20guidelines.pdf?api=v2' + + the error fields implemented: + + 1 Timestamp Auto Injected when this is called + 2 RequestID Implemented (xer) + 3 ThreadID n/a + 4 ServiceName Implemented (from Req) + 6 TargetEntity Implemented (tgt_entity) + 7 TargetServiceName Implemented (tgt_path)/ + 8 ErrorCategory Implemented (severity) + 9. ErrorCode Implemented (ecode) + 10 ErrorDescription Implemented (msg) + 11. detailMessage Implemented (adv_msg) + + Not implemented: + 5 PartnerName - nothing in the request tells me this + """ + ets = utc() + + _ERROR_LOGGER.error( + "{ets}|{xer}|n/a|{path}||{tge}|{tgp}|{sev}|{ecode}|{msg}|{amsg}" + .format( + ets=ets, + xer=xer, + path=raw_request.path.split("/")[1], + tge=tgt_entity, + tgp=tgt_path, + sev=severity, + ecode=ecode, + msg=msg, + amsg=adv_msg, + ) + ) + + +def metrics(raw_request, bts, xer, target, target_path, rcode, + calling_mod, msg="n/a"): + """ + write an EELF error record per + 'https://wiki.onap.org/download/attachments/1015849/ + ONAP%20application%20logging%20guidelines.pdf?api=v2' + + %The metrics fields implemented: + + 1 BeginTimestamp Implemented (bts) + 2 EndTimestamp Auto Injected when this is called + 3 RequestID Implemented (xer) + 5 threadId n/a + 7 serviceName Implemented (from Req) + 9 TargetEntity Implemented (target) + 10 TargetServiceName Implemented (target_path) + 11 StatusCode Implemented (based on rcode) + 12 Response Code Implemented (rcode) + 15 Category log level all metrics records are INFO. + 17 Server IP address Implemented (from Req) + 18 ElapsedTime Auto Injected (milliseconds) + 19 Server This is running in a Docker container so this is + not applicable, my HOSTNAME is always + "config_binding_service" + 20 ClientIPaddress Implemented (from Req) + 21 class name Implemented (mod), though docs say OOP, + I am using the python module here + 22 Unused ...implemented.... + 24 TargetVirtualEntity n/a + 25-28 Custom n/a + 29 detailMessage Implemented (msg) + + Not implemented + 4 serviceInstanceID - ? + 6 physical/virtual server name (Optional) + 8 PartnerName - nothing in the request tells me this + 13 Response Description - the CBS follows standard HTTP error + codes so look them up + 14 instanceUUID - Optional + 16 Severity (Optional) + 23 ProcessKey - optional + """ + ets = utc() + + _METRICS_LOGGER.info( + "{bts}|{ets}|{xer}||n/a||{path}||{tge}|{tgp}|{status}|{rcode}|||INFO||{servip}|" + "{et}|config_binding_service|{clientip}|{calling_mod}|||n/a|||||{msg}" + .format( + bts=bts.isoformat(), + ets=ets.isoformat(), + xer=xer, + path=raw_request.path.split("/")[1], + tge=target, + tgp=target_path, + status="COMPLETE" if rcode < 400 else "ERROR", + rcode=rcode, + servip=raw_request.host.split(":")[0], + et=int((ets - bts).microseconds / 1000), + clientip=raw_request.remote_addr, + calling_mod=calling_mod, + msg=msg, + ) + ) diff --git a/components/pm-subscription-handler/pmsh_service/pmsh_service.py b/components/pm-subscription-handler/pmsh_service/pmsh_service.py new file mode 100755 index 00000000..6764c75f --- /dev/null +++ b/components/pm-subscription-handler/pmsh_service/pmsh_service.py @@ -0,0 +1,35 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + +import os +import time + +import mod.pmsh_logging as logger + + +def main(): + """Entrypoint""" + if "PROD_LOGGING" in os.environ: + logger.create_loggers() + while True: + time.sleep(30) + logger.debug("Ni! Ni! Ni!") + + +if __name__ == '__main__': + main() diff --git a/components/pm-subscription-handler/pom.xml b/components/pm-subscription-handler/pom.xml new file mode 100644 index 00000000..a4258060 --- /dev/null +++ b/components/pm-subscription-handler/pom.xml @@ -0,0 +1,245 @@ +<?xml version="1.0"?> +<!-- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.oparent</groupId> + <artifactId>oparent</artifactId> + <version>2.1.0</version> + </parent> + <!--- CHANGE THE FOLLOWING 3 OBJECTS for your own repo --> + <groupId>org.onap.dcaegen2.services</groupId> + <artifactId>pmsh</artifactId> + <name>dcaegen2-services-pm-subscription-handler</name> + <version>1.0.0-SNAPSHOT</version> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <sonar.sources>.</sonar.sources> + <sonar.junit.reportsPath>xunit-results.xml</sonar.junit.reportsPath> + <sonar.python.coverage.reportPath>coverage.xml</sonar.python.coverage.reportPath> + <sonar.python.xunit.reportPath>xunit-results.xml</sonar.python.xunit.reportPath> + <sonar.language>py</sonar.language> + <sonar.pluginname>python</sonar.pluginname> + <sonar.inclusions>**/**.py</sonar.inclusions> + <sonar.exclusions>target/**,tests/**,setup.py,**/__init__.py</sonar.exclusions> + <exec-mvn-plugin-version>1.2.1</exec-mvn-plugin-version> + </properties> + <build> + <finalName>${project.artifactId}-${project.version}</finalName> + <pluginManagement> + <plugins> + <!-- the following plugins are invoked from oparent, we do not need them --> + <plugin> + <groupId>org.sonatype.plugins</groupId> + <artifactId>nexus-staging-maven-plugin</artifactId> + <configuration> + <skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <!-- This version supports the "deployAtEnd" parameter --> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <!-- first disable the default Java plugins at various stages --> + <!-- maven-resources-plugin is called during "*resource" phases by default behavior. it prepares the resources + dir. we do not need it --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <!-- maven-compiler-plugin is called during "compile" phases by default behavior. we do not need it --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <!-- maven-jar-plugin is called during "compile" phase by default behavior. we do not need it --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>default-jar</id> + </execution> + </executions> + </plugin> + <!-- maven-install-plugin is called during "install" phase by default behavior. it tries to copy stuff under + target dir to ~/.m2. we do not need it --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <!-- maven-surefire-plugin is called during "test" phase by default behavior. it triggers junit test. + we do not need it --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>${exec-mvn-plugin-version}</version> + <configuration> + <executable>${project.basedir}/mvn-phase-script.sh</executable> + <environmentVariables> + <!-- make mvn properties as env for our script --> + <MVN_PROJECT_GROUPID>${project.groupId}</MVN_PROJECT_GROUPID> + <MVN_PROJECT_ARTIFACTID>${project.artifactId}</MVN_PROJECT_ARTIFACTID> + <MVN_PROJECT_VERSION>${project.version}</MVN_PROJECT_VERSION> + <MVN_NEXUSPROXY>${onap.nexus.url}</MVN_NEXUSPROXY> + <MVN_RAWREPO_BASEURL_UPLOAD>${onap.nexus.rawrepo.baseurl.upload}</MVN_RAWREPO_BASEURL_UPLOAD> + <MVN_RAWREPO_BASEURL_DOWNLOAD>${onap.nexus.rawrepo.baseurl.download}</MVN_RAWREPO_BASEURL_DOWNLOAD> + <MVN_RAWREPO_SERVERID>${onap.nexus.rawrepo.serverid}</MVN_RAWREPO_SERVERID> + <MVN_DOCKERREGISTRY_DAILY>${onap.nexus.dockerregistry.daily}</MVN_DOCKERREGISTRY_DAILY> + <MVN_DOCKERREGISTRY_SNAPSHOT>${onap.nexus.dockerregistry.daily}</MVN_DOCKERREGISTRY_SNAPSHOT> + <MVN_DOCKERREGISTRY_RELEASE>${onap.nexus.dockerregistry.release}</MVN_DOCKERREGISTRY_RELEASE> + </environmentVariables> + </configuration> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <!-- now we configure custom action (calling a script) at various lifecycle phases --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>${exec-mvn-plugin-version}</version> + <executions> + <execution> + <id>clean phase script</id> + <phase>clean</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>clean</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>generate-sources script</id> + <phase>generate-sources</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>generate-sources</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>compile script</id> + <phase>compile</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>compile</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>package script</id> + <phase>package</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>package</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>test script</id> + <phase>test</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>test</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>install script</id> + <phase>install</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>install</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>deploy script</id> + <phase>deploy</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <arguments> + <argument>__</argument> + <argument>deploy</argument> + </arguments> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/components/pm-subscription-handler/requirements.txt b/components/pm-subscription-handler/requirements.txt new file mode 100644 index 00000000..a60bdc68 --- /dev/null +++ b/components/pm-subscription-handler/requirements.txt @@ -0,0 +1,9 @@ + # requirements.txt + # + # installs dependencies from ./setup.py, and the package itself, + # in editable mode + # -e . + + # (the -e above is optional). you could also just install the package + # normally with just the line below (after uncommenting) + . diff --git a/components/pm-subscription-handler/setup.py b/components/pm-subscription-handler/setup.py new file mode 100644 index 00000000..9012a04c --- /dev/null +++ b/components/pm-subscription-handler/setup.py @@ -0,0 +1,35 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +from setuptools import setup, find_packages + +setup( + name="pm_subscription_handler", + version="1.0.0", + packages=find_packages(), + author="lego@est.tech", + author_email="lego@est.tech", + license='Apache 2', + description="Service to handle PM subscriptions", + url="https://gerrit.onap.org/r/#/admin/projects/dcaegen2/services", + python_requires='>=3', + install_requires=[ + "requests==2.22.0", + "aiohttp==3.6.2", + "onappylog==1.0.9"], +) diff --git a/components/pm-subscription-handler/tests/__init__.py b/components/pm-subscription-handler/tests/__init__.py new file mode 100644 index 00000000..d2f6f2fd --- /dev/null +++ b/components/pm-subscription-handler/tests/__init__.py @@ -0,0 +1,21 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + + +# empty __init__.py so that pytest can add correct path to coverage report, +# -- per pytest best practice guideline diff --git a/components/pm-subscription-handler/tests/test_logging.py b/components/pm-subscription-handler/tests/test_logging.py new file mode 100644 index 00000000..790aa40c --- /dev/null +++ b/components/pm-subscription-handler/tests/test_logging.py @@ -0,0 +1,28 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2019 Nordix Foundation. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + +import unittest + + +class MyTestCase(unittest.TestCase): + def test_something(self): + self.assertEqual(True, True) + + +if __name__ == '__main__': + unittest.main() diff --git a/components/pm-subscription-handler/tox.ini b/components/pm-subscription-handler/tox.ini new file mode 100644 index 00000000..fcbb647c --- /dev/null +++ b/components/pm-subscription-handler/tox.ini @@ -0,0 +1,41 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +[tox] +envlist = py36,py37,flake8 +skip_missing_interpreters = true + +[testenv] +deps= + -rrequirements.txt + pytest + coverage + pytest-cov +setenv = + PYTHONPATH={toxinidir}/pmsh_service:{toxinidir}/pmsh_service/mod:{toxinidir}/tests +commands= + pytest --junitxml xunit-results.xml --cov pmsh_service --cov-report xml --cov-report term tests --verbose --cov-fail-under=0 + +[testenv:flake8] +basepython = python3 +skip_install = true +deps = flake8 +commands = flake8 pmsh_service tests + +[flake8] +max-line-length=100 diff --git a/components/pm-subscription-handler/version.properties b/components/pm-subscription-handler/version.properties new file mode 100644 index 00000000..2ddebb39 --- /dev/null +++ b/components/pm-subscription-handler/version.properties @@ -0,0 +1,6 @@ +major=1 +minor=0 +patch=0 +base_version=${major}.${minor}.${patch} +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT |