From 957f2dd61ecdeb66966a979fd0380faa54694c21 Mon Sep 17 00:00:00 2001 From: "halil.cakal" Date: Fri, 27 Jan 2023 14:07:20 +0000 Subject: [PATCH] Introduce setup.py to create pip distributions, and update README.md. Run & fix the result of local Sonarcube scan. Issue-ID: NONRTRIC-817 Change-Id: If1695c7d3ada11420d3efbbfc844a485776db90f Signed-off-by: halil.cakal --- catalogue-enhanced/.gitignore | 4 ++ catalogue-enhanced/README.md | 37 ++++++++++++++++-- catalogue-enhanced/setup.py | 45 ++++++++++++++++++++++ catalogue-enhanced/src/catalogue_manager.py | 4 +- .../tests/test_sychronized_rapp_registry.py | 3 -- 5 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 catalogue-enhanced/setup.py diff --git a/catalogue-enhanced/.gitignore b/catalogue-enhanced/.gitignore index 00f2c95..3309556 100644 --- a/catalogue-enhanced/.gitignore +++ b/catalogue-enhanced/.gitignore @@ -14,3 +14,7 @@ htmlcov/ # Python virtual env venv/ + +# Local Sonarqube scan folder +.scannerwork/ + diff --git a/catalogue-enhanced/README.md b/catalogue-enhanced/README.md index 070d345..83c8c0a 100644 --- a/catalogue-enhanced/README.md +++ b/catalogue-enhanced/README.md @@ -27,7 +27,7 @@ The overall folder structure is (relative to the location of this README file): | Dir | Description | | ---------------- | ----------- | -|. |Dockerfile, container-tag.yaml, nginx.conf, pyproject.toml, tox.ini and README.md | +|. |Dockerfile, container-tag.yaml, nginx.conf, pyproject.toml, tox.ini, setup.py, and README.md | |api |The OpenApi yaml rapp-catalogue-enhanced.yaml | |src |Python source codes includes sub-directories repository, configuration, and start.sh | |certificate |A self-signed certificate and a key | @@ -93,12 +93,43 @@ Goto the main directory, 'rappcatalogue/catalogue-enhanced-test'. This folder co Note that test can be performed both using the nonsecure HTTP port and the secure HTTPS port. +# Building the rApp Catalogue Enhanced + Build and start the rApp catalogue enhanced containers: ./build_and_start.sh This will build and start the container in interactive mode. The built container only resides in the local docker repository. When running the rApp Catalogue Enhanced as a container, the defualt ports can be re-mapped to any port on the localhost. -In a second terminal, go to the same folder and run the basic test script, basic_test.sh nonsecure|secure. +# API Testing of rApp Catalogue Enhanced + +In a second terminal, go to the same folder and run the basic test script: + basic_test.sh nonsecure|secure. + +This script runs a number of API tests towards the rApp Catalogue Enhanced to make sure it works properply. + +# Unit Testing of rApp Catalogue Enhanced + +In order to run unit test cases, there is no need to build, and start any container. However, Python's venv must exist. You can follow the below steps to create a venv: + 1- Change current directory to project's root directory that is rappcatalogue. + 2- Run the commands consecutively: + python3 -m venv venv --prompt="rappcatalogue" + source venv/bin/activate + pip install connexion + 3- Change current directory to 'catalogue-enhanced/tests/' + 4- Run the command below: + python suite.py +The suite.py will detect existing unit test cases, and run them all. + +# Installing the pip distribution of rApp Catalogue Enhanced + +It is also possible to have a pip distro of rApp catalogue. In order to install in your venv, you have to first install a venv mentioned in Unit Testing of rApp. + +Then, you can follow the below steps: + 1- Change current directory to 'rappcatalogue/catalogue-enhanced' where you can find setup.py + 2- Run the command: + pip install . + +This will build the rApp catalogue on your local. + -This script runs a number of tests towards the rApp Catalogue Enhanced to make sure it works properply. diff --git a/catalogue-enhanced/setup.py b/catalogue-enhanced/setup.py new file mode 100644 index 0000000..0c82586 --- /dev/null +++ b/catalogue-enhanced/setup.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# ============LICENSE_START=============================================== +# Copyright (C) 2023 Nordix Foundation. All rights reserved. +# ======================================================================== +# 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. +# ============LICENSE_END================================================= +# + +from setuptools import setup + +setup(name='rappcatalogue-enhanced', + version='1.0.0', + description='The O-RAN Non-RT RIC rApp Catalogue Enhanced provides an OpenApi 3.0 REST API for rApp services to register/unregister themselves and discover other services', + maintainer='Halil Cakal', + maintainer_email='halil.cakal@est.tech', + url='https://gerrit.o-ran-sc.org/r/admin/repos/nonrtric/plt/rappcatalogue,general', + license='Apache License, Version 2.0', + platforms='any', + packages=[ + 'src', + 'src.configuration', + 'src.repository', + 'api', + 'certificate', + 'config', + 'csar', + 'tests' + ], + zip_safe=False, + include_package_data=True, + install_requires=[ + 'connexion[swagger-ui]', + ], +) diff --git a/catalogue-enhanced/src/catalogue_manager.py b/catalogue-enhanced/src/catalogue_manager.py index d1a0470..599d4ad 100644 --- a/catalogue-enhanced/src/catalogue_manager.py +++ b/catalogue-enhanced/src/catalogue_manager.py @@ -92,7 +92,7 @@ def query_api_list_by_rapp_id_and_service_type(rappid, servicetype): arr_api_list = rapp_definition['apiList'] arr_filtered_api_list = [arr_item for arr_item in arr_api_list if arr_item['serviceType'] == service_type] return (arr_filtered_api_list, 200) - except Exception as err: + except Exception: pjson=create_problem_json(None, "The rapp definition is corrupt or missing.", 400, None, rapp_id) return Response(json.dumps(pjson), 400, mimetype=APPL_PROB_JSON) @@ -152,7 +152,7 @@ def open_zip_and_filter(filename): for file_name in file_names: if file_name.endswith('TOSCA.meta'): return TextIOWrapper(zip_object.open(file_name)) # TextIOWrapper: provides buffered text stream - except Exception as err: + except Exception: pjson=create_problem_json(None, "The CSAR zip content is corrupt or missing.", 400, None, rapp_id) return Response(json.dumps(pjson), 400, mimetype=APPL_PROB_JSON) finally: diff --git a/catalogue-enhanced/tests/test_sychronized_rapp_registry.py b/catalogue-enhanced/tests/test_sychronized_rapp_registry.py index 1b2c6ca..bd79e77 100644 --- a/catalogue-enhanced/tests/test_sychronized_rapp_registry.py +++ b/catalogue-enhanced/tests/test_sychronized_rapp_registry.py @@ -32,9 +32,6 @@ class TestSynchronizedRappRegistry(unittest.TestCase): # add to the dict self.synch_registry.set_rapp(i, 'rapp'+str(i)) - def tearDown(self): - pass - def test_synch_registry_setup_size(self): self.assertEqual(100, len(self.synch_registry._rapps)) -- 2.16.6