Introduce setup.py to create pip distributions, 13/10313/4
authorhalil.cakal <halil.cakal@est.tech>
Fri, 27 Jan 2023 14:07:20 +0000 (14:07 +0000)
committerhalil.cakal <halil.cakal@est.tech>
Mon, 30 Jan 2023 12:29:21 +0000 (12:29 +0000)
and update README.md. Run & fix the result of local Sonarcube scan.

Issue-ID: NONRTRIC-817
Change-Id: If1695c7d3ada11420d3efbbfc844a485776db90f
Signed-off-by: halil.cakal <halil.cakal@est.tech>
catalogue-enhanced/.gitignore
catalogue-enhanced/README.md
catalogue-enhanced/setup.py [new file with mode: 0644]
catalogue-enhanced/src/catalogue_manager.py
catalogue-enhanced/tests/test_sychronized_rapp_registry.py

index 00f2c95..3309556 100644 (file)
@@ -14,3 +14,7 @@ htmlcov/
 
 # Python virtual env
 venv/
+
+# Local Sonarqube scan folder
+.scannerwork/
+
index 070d345..83c8c0a 100644 (file)
@@ -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 (file)
index 0000000..0c82586
--- /dev/null
@@ -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]',
+      ],
+)
index d1a0470..599d4ad 100644 (file)
@@ -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:
index 1b2c6ca..bd79e77 100644 (file)
@@ -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))