From 5fa91815945b1b4469c0f345ebb56c9aba5c72c1 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Tue, 29 Aug 2023 17:33:09 +0100 Subject: [PATCH 01/16] NONRTRIC-892: A1-Simulator - add unit test for sendstatus Change-Id: Iafd13306c9a7156a42f8d5f553188cc1bc57c28b Signed-off-by: DenisGNoonan --- near-rt-ric-simulator/tests/test_osc_2_1_0.py | 90 ++++++++++++++------------- near-rt-ric-simulator/tests/unittest_setup.py | 8 +-- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/near-rt-ric-simulator/tests/test_osc_2_1_0.py b/near-rt-ric-simulator/tests/test_osc_2_1_0.py index 5c9b780..169f360 100644 --- a/near-rt-ric-simulator/tests/test_osc_2_1_0.py +++ b/near-rt-ric-simulator/tests/test_osc_2_1_0.py @@ -23,10 +23,9 @@ INTERFACE_VERSION="OSC_2.1.0" import json import pytest -import requests -import threading +import multiprocessing from unittest_setup import SERVER_URL, PORT_NUMBER, setup_env, get_testdata_dir, client -# from unittest_setup import run_flask_app +from unittest_setup import run_flask_app # Setup env and import paths setup_env(INTERFACE_VERSION) @@ -51,7 +50,7 @@ def test_enforce_reason(client): enforce_dict = enforceStatus.to_dict() assert enforce_dict['enforceStatus'] == 'ENFORCED' assert enforce_dict['enforceReason'] == 'STATEMENT_NOT_APPLICABLE' - + enforceStatus.enforce_reason = 'OTHER_REASON' enforce_dict = enforceStatus.to_dict() assert enforce_dict['enforceReason'] == 'OTHER_REASON' @@ -596,43 +595,46 @@ def test_notificationDestination(client): response = client.put(SERVER_URL+"a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(policytype_2)) assert response.status_code == 202 result = response.data - assert result == b"" - -# def test_sendstatus(client): -# testdata=get_testdata_dir() -# # Header for json payload -# header = { -# "Content-Type" : "application/json" -# } - -# # === Send status for pi2===" -# with open(testdata+'pi2.json') as json_file: -# policytype_2 = json.load(json_file) -# response = client.post(SERVER_URL+'sendstatus?policyid=pi2', headers=header, data=json.dumps(policytype_2)) -# assert response.status_code == 201 -# result = response.data -# assert result == b"OK" - - -# def test_multithreaded(client): -# # Create a new thread to run the Flask app -# app_thread = threading.Thread(target=run_flask_app) -# app_thread.start() - -# # Perform your tests here -# testdata=get_testdata_dir() -# # Header for json payload -# header = { -# "Content-Type" : "application/json" -# } - -# # === Send status for pi2===" -# with open(testdata+'pi2.json') as json_file: -# policytype_2 = json.load(json_file) -# response = client.post(SERVER_URL+'sendstatus?policyid=pi2', headers=header, data=json.dumps(policytype_2)) -# assert response.status_code == 201 -# result = response.data -# assert result == b"OK" - -# # Wait for the Flask app thread to finish -# app_thread.join() + assert result == b"" + +def test_notificationDestination(client): + test_data = get_testdata_dir() + 'pi2.json' + # Header for json payload + header = { "Content-Type" : "application/json" } + + # === API: Update policy instance pi2 of type: 2 ===" + with open(test_data) as json_file: + payload = json.load(json_file) + response = client.put(SERVER_URL+"a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(payload)) + + assert response.status_code == 202 + result = response.data + assert result == b"" + + +def test_sendstatus(client): + # Create a new thread to run the Flask app in parallel on a different port so that we can call the callback. + proc = multiprocessing.Process(target=run_flask_app, args=()) + proc.start() + + test_data = get_testdata_dir() + 'pi2.json' + header = { "Content-Type" : "application/json" } + + # === Send status for pi2=== + with open(test_data) as json_file: + payload = json.load(json_file) + response = client.post(SERVER_URL+'sendstatus?policyid=pi2', headers=header, data=json.dumps(payload)) + + assert response.status_code == 201 + result = response.data + assert result == b"OK" + + # Send status, negative test with missing parameter + response = client.post(SERVER_URL+'sendstatus', headers=header, data="") + assert response.status_code == 400 + + # Send status pi9, negative test for policy id not found + response = client.post(SERVER_URL+'sendstatus?policyid=pi9', headers=header, data="") + assert response.status_code == 404 + + proc.terminate() diff --git a/near-rt-ric-simulator/tests/unittest_setup.py b/near-rt-ric-simulator/tests/unittest_setup.py index 06567cf..f2c2955 100644 --- a/near-rt-ric-simulator/tests/unittest_setup.py +++ b/near-rt-ric-simulator/tests/unittest_setup.py @@ -58,7 +58,7 @@ def client(): with app.app.test_client() as client: yield client -# # Run the Flask app in a separate thread for testing -# def run_flask_app(): -# from main import app -# app.app.run(port=8085, host="127.0.0.1", threaded=True) +# Run the Flask app in a separate thread for testing +def run_flask_app(): + from main import app + app.app.run(port=8085, host="127.0.0.1") -- 2.16.6 From c8869f47f6ab67e0a1516cb0eca517ef31ba9a10 Mon Sep 17 00:00:00 2001 From: ktimoney Date: Mon, 4 Sep 2023 11:06:07 +0100 Subject: [PATCH 02/16] Update readthedocs config Issue-ID: NONRTRIC-921 Change-Id: I3a7263acd3da4f030cca0d4571a1338bcf45ee2d Signed-off-by: ktimoney --- .readthedocs.yaml | 24 +++++++++++++++++++++--- docs/index.rst | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 3797dc8..862cc04 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,3 +1,20 @@ +# ============LICENSE_START=============================================== +# Copyright (C) 2020-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================================================= +# + --- # .readthedocs.yml # Read the Docs configuration file @@ -9,12 +26,13 @@ formats: - htmlzip build: - image: latest + os: ubuntu-22.04 + tools: + python: "3.11" python: - version: 3.7 install: - - requirements: docs/requirements-docs.txt + - requirements: docs/requirements-docs.txt sphinx: configuration: docs/conf.py diff --git a/docs/index.rst b/docs/index.rst index b96a895..95bc3a9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,6 @@ .. This work is licensed under a Creative Commons Attribution 4.0 International License. .. SPDX-License-Identifier: CC-BY-4.0 -.. Copyright (C) 2021-2022 Nordix +.. Copyright (C) 2021-2023 Nordix .. |nbsp| unicode:: 0xA0 :trim: -- 2.16.6 From d629ad239729f3b4b4131c012c3808d8b1491889 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Wed, 4 Oct 2023 12:34:55 +0100 Subject: [PATCH 03/16] NONRTRIC-933: NONRTRIC - A1Sim - sendstatus needs to return HTTP code 204 Issue-ID: NONRTRIC-933 Change-Id: I13d876740a3b867c795c6993af7395983ab1b470 Signed-off-by: DenisGNoonan --- near-rt-ric-simulator/src/STD_2.0.0/a1.py | 4 +- near-rt-ric-simulator/src/STD_2.0.0/main.py | 3 +- near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh | 2 +- near-rt-ric-simulator/tests/test_osc_2_1_0.py | 16 ----- near-rt-ric-simulator/tests/test_std_2_0_0.py | 72 +++++++++++++++------- 5 files changed, 53 insertions(+), 44 deletions(-) diff --git a/near-rt-ric-simulator/src/STD_2.0.0/a1.py b/near-rt-ric-simulator/src/STD_2.0.0/a1.py index e70a8ed..f773118 100755 --- a/near-rt-ric-simulator/src/STD_2.0.0/a1.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/a1.py @@ -152,8 +152,8 @@ def put_policy(policyTypeId, policyId): policy_fingerprint[fp]=policy_id - noti=request.args.get('notificationDestination') - callbacks[policy_id]=noti + noti = request.args.get('notificationDestination') + callbacks[policy_id] = noti policy_instances[policy_type_id][policy_id]=data diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py index 9733a0f..d2ac7cb 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/main.py @@ -199,8 +199,7 @@ def sendstatus(): if (resp.status_code<199 & resp.status_code > 299): return Response('Post status failed with code: '+resp.status_code, status=500, mimetype=TEXT_PLAIN) - data = resp.json() - return Response(data, 200, mimetype=APPL_JSON) + return Response(None, 204, mimetype=APPL_JSON) #Receive status (only for testing callbacks) #/statustest diff --git a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh index fd49caa..cabb757 100755 --- a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh +++ b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh @@ -373,7 +373,7 @@ do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Send status for pi2===" RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" -do_curl POST '/sendstatus?policyid=pi2' 200 +do_curl POST '/sendstatus?policyid=pi2' 204 echo "=== Get counter: datadelivery ===" RESULT="0" diff --git a/near-rt-ric-simulator/tests/test_osc_2_1_0.py b/near-rt-ric-simulator/tests/test_osc_2_1_0.py index 169f360..b1d947b 100644 --- a/near-rt-ric-simulator/tests/test_osc_2_1_0.py +++ b/near-rt-ric-simulator/tests/test_osc_2_1_0.py @@ -581,22 +581,6 @@ def test_apis(client): assert response.status_code == 200 assert response.data == b"2" - -def test_notificationDestination(client): - testdata=get_testdata_dir() - # Header for json payload - header = { - "Content-Type" : "application/json" - } - - # === API: Update policy instance pi2 of type: 2 ===" - with open(testdata+'pi2.json') as json_file: - policytype_2 = json.load(json_file) - response = client.put(SERVER_URL+"a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(policytype_2)) - assert response.status_code == 202 - result = response.data - assert result == b"" - def test_notificationDestination(client): test_data = get_testdata_dir() + 'pi2.json' # Header for json payload diff --git a/near-rt-ric-simulator/tests/test_std_2_0_0.py b/near-rt-ric-simulator/tests/test_std_2_0_0.py index 2a01d83..84d05dd 100644 --- a/near-rt-ric-simulator/tests/test_std_2_0_0.py +++ b/near-rt-ric-simulator/tests/test_std_2_0_0.py @@ -15,21 +15,23 @@ # ============LICENSE_END================================================= # -# This test case test the STD_2.0.0 version of the simulator +# This test case tests the STD_2.0.0 version of the simulator. import json import time +import multiprocessing +from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, get_testdata_dir, client +from unittest_setup import run_flask_app -#Version of simulator -INTERFACE_VERSION="STD_2.0.0" +# Setup env and import paths -from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, get_testdata_dir, client +# Version of simulator +INTERFACE_VERSION="STD_2.0.0" -#Setup env and import paths setup_env(INTERFACE_VERSION) - from compare_json import compare + def test_apis(client): testdata=get_testdata_dir() @@ -390,22 +392,6 @@ def test_apis(client): res=compare(data_response, result) assert res == True - - # #Found no way to test these functions - # #'sendstatus' will send a http request that will fail - # #since no server will receive the call - # #These function is instead tested when running the bash script in the 'test' dir - # # # Send status for pi2 - # # response=client.post(SERVER_URL+'sendstatus?policyid=pi2') - # # assert response.status_code == 200 - # # result=json.loads(response.data) - # # res=compare(data_get_status, result) - # # assert res == True - - # # # Send status, shall fail - # # response=client.post(SERVER_URL+'sendstatus') - # # assert response.status_code == 400 - # Get counter: data_delivery response=client.get(SERVER_URL+'counter/datadelivery') assert response.status_code == 200 @@ -438,4 +424,44 @@ def test_apis(client): # Get counter: types response=client.get(SERVER_URL+'counter/num_types') assert response.status_code == 200 - assert response.data == b"1" \ No newline at end of file + assert response.data == b"1" + +def test_notificationDestination(client): + test_data = get_testdata_dir() + 'pi2.json' + # Header for json payload + header = { "Content-Type" : "application/json" } + + # === API: Update policy instance pi2 of type: 2 ===" + with open(test_data) as json_file: + payload = json.load(json_file) + response = client.put(SERVER_URL+"A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(payload)) + assert response.status_code == 200 + result = json.loads(response.data) + assert compare(payload, result) == True + +def test_sendstatus(client): + # Create a new thread to run the Flask app in parallel on a different port so that we can call the callback. + proc = multiprocessing.Process(target=run_flask_app, args=()) + proc.start() + + test_data = get_testdata_dir() + 'pi2.json' + header = { "Content-Type" : "application/json" } + + # === Send status for pi2=== + with open(test_data) as json_file: + payload = json.load(json_file) + response = client.post(SERVER_URL+'sendstatus?policyid=pi2', headers=header, data=json.dumps(payload)) + + assert response.status_code == 204 + result = response.data + assert result == b"" + + # Send status, negative test with missing parameter + response = client.post(SERVER_URL+'sendstatus', headers=header, data="") + assert response.status_code == 400 + + # Send status pi9, negative test for policy id not found + response = client.post(SERVER_URL+'sendstatus?policyid=pi9', headers=header, data="") + assert response.status_code == 404 + + proc.terminate() -- 2.16.6 From f5ffd09d7b10237f7ba31617b30821a36e5647f3 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Mon, 9 Oct 2023 17:28:30 +0100 Subject: [PATCH 04/16] NONRTRIC-937: NONRTRIC - A1Sim - Add Definition of Enumeration EnforcementStatusType Signed-off-by: DenisGNoonan Change-Id: Ieab531cad05bab5b7877766e1dd058f23ec65fd9 --- .../src/OSC_2.1.0/{ => models}/__init__.py | 0 .../src/OSC_2.1.0/models/enforceStatus.py | 17 ++++ near-rt-ric-simulator/src/STD_2.0.0/a1.py | 17 ++-- .../src/STD_2.0.0/models/__init__.py | 0 .../src/STD_2.0.0/models/enforceStatus.py | 98 ++++++++++++++++++++++ near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh | 18 ++-- near-rt-ric-simulator/tests/test_std_2_0_0.py | 49 +++++++++-- 7 files changed, 175 insertions(+), 24 deletions(-) rename near-rt-ric-simulator/src/OSC_2.1.0/{ => models}/__init__.py (100%) create mode 100644 near-rt-ric-simulator/src/STD_2.0.0/models/__init__.py create mode 100644 near-rt-ric-simulator/src/STD_2.0.0/models/enforceStatus.py diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/__init__.py b/near-rt-ric-simulator/src/OSC_2.1.0/models/__init__.py similarity index 100% rename from near-rt-ric-simulator/src/OSC_2.1.0/__init__.py rename to near-rt-ric-simulator/src/OSC_2.1.0/models/__init__.py diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/models/enforceStatus.py b/near-rt-ric-simulator/src/OSC_2.1.0/models/enforceStatus.py index 89fafd9..308c7b2 100644 --- a/near-rt-ric-simulator/src/OSC_2.1.0/models/enforceStatus.py +++ b/near-rt-ric-simulator/src/OSC_2.1.0/models/enforceStatus.py @@ -1,3 +1,20 @@ +# ============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================================================= +# + # coding: utf-8 from __future__ import absolute_import diff --git a/near-rt-ric-simulator/src/STD_2.0.0/a1.py b/near-rt-ric-simulator/src/STD_2.0.0/a1.py index f773118..1dd0859 100755 --- a/near-rt-ric-simulator/src/STD_2.0.0/a1.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/a1.py @@ -30,8 +30,9 @@ from jsonschema import validate from var_declaration import policy_instances, policy_types, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set from utils import calcFingerprint from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name, is_duplicate_check +from models.enforceStatus import EnforceStatus -#Constsants +# Constants APPL_JSON='application/json' APPL_PROB_JSON='application/problem+json' @@ -139,8 +140,8 @@ def put_policy(policyTypeId, policyId): pjson=create_error_response(resp) return Response(json.dumps(pjson), 500, mimetype=APPL_PROB_JSON) - #Callout hooks for external server - #When it fails, break and return 419 HTTP status code + # Callout hooks for external server + # When it fails, break and return HTTP status code 500 if (EXT_SRV_URL is not None): resp = callout_external_server(policy_id, data, 'PUT') if (resp != retcode): @@ -158,10 +159,8 @@ def put_policy(policyTypeId, policyId): policy_instances[policy_type_id][policy_id]=data if (policy_types[policy_type_id]['statusSchema'] is not None): - ps = {} - ps["enforceStatus"] = "" - ps["enforceReason"] = "" - policy_status[policy_id] = ps + enforceStatus = EnforceStatus("NOT_ENFORCED", "OTHER_REASON") + policy_status[policy_id] = enforceStatus.to_dict() if (retcode == 200): return Response(json.dumps(data), 200, mimetype=APPL_JSON) @@ -217,8 +216,8 @@ def delete_policy(policyTypeId, policyId): pjson=create_error_response(resp) return Response(json.dumps(pjson), 500, mimetype=APPL_PROB_JSON) - #Callout hooks for external server - #When it fails, break and return 419 HTTP status code + # Callout hooks for external server + # When it fails, break and return HTTP status code 500 if (EXT_SRV_URL is not None): resp = callout_external_server(policy_id, None, 'DELETE') if (resp != 204): diff --git a/near-rt-ric-simulator/src/STD_2.0.0/models/__init__.py b/near-rt-ric-simulator/src/STD_2.0.0/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/near-rt-ric-simulator/src/STD_2.0.0/models/enforceStatus.py b/near-rt-ric-simulator/src/STD_2.0.0/models/enforceStatus.py new file mode 100644 index 0000000..308c7b2 --- /dev/null +++ b/near-rt-ric-simulator/src/STD_2.0.0/models/enforceStatus.py @@ -0,0 +1,98 @@ +# ============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================================================= +# + +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + + +class EnforceStatus(): + + def __init__(self, enforce_status: str=None, enforce_reason: str=None): # noqa: E501 + """EnforceStatus + + :param enforce_status: The enforce_status of this EnforceStatus. # noqa: E501 + :type enforce_status: str + :param enforce_reason: The enforce_reason of this EnforceStatus. # noqa: E501 + :type enforce_reason: str + """ + self._enforce_status = enforce_status + self._enforce_reason = enforce_reason + + @property + def enforce_status(self) -> str: + """Gets the enforce_status of this EnforceStatus. + + :return: The enforce_status of this EnforceStatus. + :rtype: str + """ + return self._enforce_status + + @enforce_status.setter + def enforce_status(self, enforce_status: str): + """Sets the enforce_status of this EnforceStatus. + + :param enforce_status: The enforce_status of this EnforceStatus. + :type enforce_status: str + """ + allowed_values = ["ENFORCED", "NOT_ENFORCED"] # noqa: E501 + if enforce_status not in allowed_values: + raise ValueError( + "Invalid value for `enforce_status` ({0}), must be one of {1}" + .format(enforce_status, allowed_values) + ) + + self._enforce_status = enforce_status + + @property + def enforce_reason(self) -> str: + """Gets the enforce_reason of this EnforceStatus. + + :return: The enforce_reason of this EnforceStatus. + :rtype: str + """ + return self._enforce_reason + + @enforce_reason.setter + def enforce_reason(self, enforce_reason: str): + """Sets the enforce_reason of this EnforceStatus. + + :param enforce_reason: The enforce_reason of this EnforceStatus. + :type enforce_reason: str + """ + allowed_values = ["SCOPE_NOT_APPLICABLE", "STATEMENT_NOT_APPLICABLE", "OTHER_REASON"] # noqa: E501 + if enforce_reason not in allowed_values: + raise ValueError( + "Invalid value for `enforce_reason` ({0}), must be one of {1}" + .format(enforce_reason, allowed_values) + ) + + self._enforce_reason = enforce_reason + + def to_dict(self): + """Returns the model properties as a dict + + :rtype: dict + """ + result = { + 'enforceStatus': self._enforce_status, + 'enforceReason': self._enforce_reason + } + return result diff --git a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh index cabb757..0e318bd 100755 --- a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh +++ b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh @@ -290,7 +290,7 @@ RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request co do_curl GET /A1-P/v2/policytypes/STD_1/policies 409 echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}" +RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\": \"OTHER_REASON\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200 echo "=== API: Create policy instance pi2 of type: STD_1 ===" @@ -352,27 +352,27 @@ if [ $EXT_SRV_EXIST == 1 ]; then fi echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}" +RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\": \"OTHER_REASON\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Set status for policy instance pi2 ===" -RESULT="Status set to OK for policy: pi2" -do_curl PUT '/status?policyid=pi2&status=OK' 200 +RESULT="Status set to ENFORCED for policy: pi2" +do_curl PUT '/status?policyid=pi2&status=ENFORCED' 200 echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"OK\"}" +RESULT="json:{\"enforceStatus\": \"ENFORCED\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Set status for policy instance pi2 ===" -RESULT="Status set to NOTOK and notok_reason for policy: pi2" -do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200 +RESULT="Status set to NOT_ENFORCED and SCOPE_NOT_APPLICABLE for policy: pi2" +do_curl PUT '/status?policyid=pi2&status=NOT_ENFORCED&reason=SCOPE_NOT_APPLICABLE' 200 echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}" +RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\":\"SCOPE_NOT_APPLICABLE\"}" do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Send status for pi2===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" +RESULT="" do_curl POST '/sendstatus?policyid=pi2' 204 echo "=== Get counter: datadelivery ===" diff --git a/near-rt-ric-simulator/tests/test_std_2_0_0.py b/near-rt-ric-simulator/tests/test_std_2_0_0.py index 84d05dd..7fc8e40 100644 --- a/near-rt-ric-simulator/tests/test_std_2_0_0.py +++ b/near-rt-ric-simulator/tests/test_std_2_0_0.py @@ -18,6 +18,7 @@ # This test case tests the STD_2.0.0 version of the simulator. import json +import pytest import time import multiprocessing from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, get_testdata_dir, client @@ -31,6 +32,42 @@ INTERFACE_VERSION="STD_2.0.0" setup_env(INTERFACE_VERSION) from compare_json import compare +from models.enforceStatus import EnforceStatus + +def test_enforce_reason(client): + """ + Test that we can set a valid enforce status and reason, and that we reject invalid cases. + """ + enforceStatus = EnforceStatus() + + enforceStatus.enforce_status = 'NOT_ENFORCED' + enforceStatus.enforce_reason = 'SCOPE_NOT_APPLICABLE' + enforce_dict = enforceStatus.to_dict() + assert enforce_dict['enforceStatus'] == 'NOT_ENFORCED' + assert enforce_dict['enforceReason'] == 'SCOPE_NOT_APPLICABLE' + + enforceStatus.enforce_status = 'ENFORCED' + enforceStatus.enforce_reason = 'STATEMENT_NOT_APPLICABLE' + enforce_dict = enforceStatus.to_dict() + assert enforce_dict['enforceStatus'] == 'ENFORCED' + assert enforce_dict['enforceReason'] == 'STATEMENT_NOT_APPLICABLE' + + enforceStatus.enforce_reason = 'OTHER_REASON' + enforce_dict = enforceStatus.to_dict() + assert enforce_dict['enforceReason'] == 'OTHER_REASON' + + enforce_status = enforceStatus.enforce_status + assert str(enforce_status) == 'ENFORCED' + + enforce_reason = enforceStatus.enforce_reason + assert str(enforce_reason) == 'OTHER_REASON' + + with pytest.raises(ValueError): + enforceStatus.enforce_status = 'ERROR' + + with pytest.raises(ValueError): + enforceStatus.enforce_reason = 'ERROR' + def test_apis(client): @@ -259,7 +296,7 @@ def test_apis(client): assert res == True # API: API: Get policy status - data_response = {"enforceStatus" : "", "enforceReason" : ""} + data_response = {"enforceStatus" : "NOT_ENFORCED", "enforceReason" : "OTHER_REASON"} response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1/status') assert response.status_code == 200 result=json.loads(response.data) @@ -360,7 +397,7 @@ def test_apis(client): assert res == True # API: API: Get policy status - data_response = {"enforceStatus" : "", "enforceReason" : ""} + data_response = {"enforceStatus" : "NOT_ENFORCED", "enforceReason" : "OTHER_REASON"} response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2/status') assert response.status_code == 200 result=json.loads(response.data) @@ -368,11 +405,11 @@ def test_apis(client): assert res == True # Set status for policy instance pi2 - response=client.put(SERVER_URL+'status?policyid=pi2&status=OK') + response=client.put(SERVER_URL+'status?policyid=pi2&status=NOT_ENFORCED&reason=STATEMENT_NOT_APPLICABLE') assert response.status_code == 200 # API: API: Get policy status - data_response = {"enforceStatus" : "OK"} + data_response = {"enforceStatus" : "NOT_ENFORCED", "enforceReason" : "STATEMENT_NOT_APPLICABLE"} response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2/status') assert response.status_code == 200 result=json.loads(response.data) @@ -381,11 +418,11 @@ def test_apis(client): assert res == True # Set status for policy instance pi2 - response=client.put(SERVER_URL+'status?policyid=pi2&status=NOTOK&reason=notok_reason') + response=client.put(SERVER_URL+'status?policyid=pi2&status=NOT_ENFORCED&reason=OTHER_REASON') assert response.status_code == 200 # API: API: Get policy status - data_response = {"enforceStatus" : "NOTOK", "enforceReason" : "notok_reason"} + data_response = {"enforceStatus" : "NOT_ENFORCED", "enforceReason" : "OTHER_REASON"} response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2/status') assert response.status_code == 200 result=json.loads(response.data) -- 2.16.6 From f65212ec78bf6d595c739c65a0e1d2d67c0f0065 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Wed, 11 Oct 2023 16:13:58 +0100 Subject: [PATCH 05/16] NONRTRIC-933: NONRTRIC - A1Sim - avoid clashing port numbers between unit tests and Docker tests Issue-ID: NONRTRIC-933 Signed-off-by: DenisGNoonan Change-Id: I5736c03cfb81bf39e034b12448d86e0e20db71fe --- near-rt-ric-simulator/tests/test_osc_2_1_0.py | 2 +- near-rt-ric-simulator/tests/test_std_2_0_0.py | 2 +- near-rt-ric-simulator/tests/unittest_setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/near-rt-ric-simulator/tests/test_osc_2_1_0.py b/near-rt-ric-simulator/tests/test_osc_2_1_0.py index b1d947b..f5222c9 100644 --- a/near-rt-ric-simulator/tests/test_osc_2_1_0.py +++ b/near-rt-ric-simulator/tests/test_osc_2_1_0.py @@ -589,7 +589,7 @@ def test_notificationDestination(client): # === API: Update policy instance pi2 of type: 2 ===" with open(test_data) as json_file: payload = json.load(json_file) - response = client.put(SERVER_URL+"a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(payload)) + response = client.put(SERVER_URL+"a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:8086/statustest", headers=header, data=json.dumps(payload)) assert response.status_code == 202 result = response.data diff --git a/near-rt-ric-simulator/tests/test_std_2_0_0.py b/near-rt-ric-simulator/tests/test_std_2_0_0.py index 7fc8e40..0da2467 100644 --- a/near-rt-ric-simulator/tests/test_std_2_0_0.py +++ b/near-rt-ric-simulator/tests/test_std_2_0_0.py @@ -471,7 +471,7 @@ def test_notificationDestination(client): # === API: Update policy instance pi2 of type: 2 ===" with open(test_data) as json_file: payload = json.load(json_file) - response = client.put(SERVER_URL+"A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(payload)) + response = client.put(SERVER_URL+"A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:8086/statustest", headers=header, data=json.dumps(payload)) assert response.status_code == 200 result = json.loads(response.data) assert compare(payload, result) == True diff --git a/near-rt-ric-simulator/tests/unittest_setup.py b/near-rt-ric-simulator/tests/unittest_setup.py index f2c2955..e30b1ad 100644 --- a/near-rt-ric-simulator/tests/unittest_setup.py +++ b/near-rt-ric-simulator/tests/unittest_setup.py @@ -61,4 +61,4 @@ def client(): # Run the Flask app in a separate thread for testing def run_flask_app(): from main import app - app.app.run(port=8085, host="127.0.0.1") + app.app.run(port=8086, host="127.0.0.1") -- 2.16.6 From d59dd37cba1f908100f3e0a191e0f4e4c769004b Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Wed, 22 Nov 2023 14:37:21 +0000 Subject: [PATCH 06/16] NONRTRIC-892: Fix issue with missing comment symbol Issue-Id: NONRTRIC-892 Change-Id: I4b0948f1b9b34345009c119c86e72fd38e5caa1e Signed-off-by: DenisGNoonan --- near-rt-ric-simulator/src/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/near-rt-ric-simulator/src/start.sh b/near-rt-ric-simulator/src/start.sh index ad5c677..e87b69e 100755 --- a/near-rt-ric-simulator/src/start.sh +++ b/near-rt-ric-simulator/src/start.sh @@ -40,7 +40,7 @@ cd $1 # start nginx nginx -c /usr/src/app/nginx.conf -start callBack server +# start callBack server if [[ ${A1_VERSION} == "STD"* ]]; then echo "Path to callBack.py: "$PWD python -u callBack.py & -- 2.16.6 From 44f19a357a768bd7d8978ee3a3f539e9e8d34a55 Mon Sep 17 00:00:00 2001 From: rohithrajneesh Date: Wed, 22 Nov 2023 16:23:16 +0000 Subject: [PATCH 07/16] Adding Flask to requirements file Issue-Id: NONRTRIC-892 Change-Id: Ia936c05839a5c729a4247ca156046da1a92d2236 Signed-off-by: rohithrajneesh --- docs/requirements-docs.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 59e8e0a..c943b3c 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -12,3 +12,4 @@ urllib3~=1.26.15 setuptools doc8 docutils < 0.17 +Flask==3.0.0 \ No newline at end of file -- 2.16.6 From 4b90aa51114102d43f43c849df2411d7a1598fe0 Mon Sep 17 00:00:00 2001 From: rohithrajneesh Date: Thu, 23 Nov 2023 16:57:56 +0000 Subject: [PATCH 08/16] Correction in requirements.txt Issue-Id: NONRTRIC-892 Change-Id: Ic3a133847d0b8942cfb2667177605738ad406f82 Signed-off-by: rohithrajneesh --- docs/requirements-docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index c943b3c..997c486 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -12,4 +12,4 @@ urllib3~=1.26.15 setuptools doc8 docutils < 0.17 -Flask==3.0.0 \ No newline at end of file +flask==3.0.0 \ No newline at end of file -- 2.16.6 From 0224bbc1c3d0e0306cd481df27a04cef0ed9807a Mon Sep 17 00:00:00 2001 From: rohithrajneesh Date: Thu, 23 Nov 2023 17:21:12 +0000 Subject: [PATCH 09/16] Rollback the changes in requirements.txt file Issue-Id: NONRTRIC-892 Change-Id: I4e06eed46a89717cde44e5856c54e620f5d0cea4 Signed-off-by: rohithrajneesh --- docs/requirements-docs.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 997c486..59e8e0a 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -12,4 +12,3 @@ urllib3~=1.26.15 setuptools doc8 docutils < 0.17 -flask==3.0.0 \ No newline at end of file -- 2.16.6 From f13ce01cc75bf9c5d699984a3219da04b5f1ed9f Mon Sep 17 00:00:00 2001 From: rohithrajneesh Date: Fri, 24 Nov 2023 16:00:36 +0000 Subject: [PATCH 10/16] Code changes for A1-Sim 2.6.0 to work with it/dep deployment Issue-Id: NONRTRIC-892 Change-Id: I57126120187cc6a48f950e4071f85baf0eb7a982 Signed-off-by: rohithrajneesh --- near-rt-ric-simulator/Dockerfile | 6 +++--- near-rt-ric-simulator/src/OSC_2.1.0/main.py | 3 ++- near-rt-ric-simulator/src/STD_1.1.3/main.py | 5 +++-- near-rt-ric-simulator/src/STD_2.0.0/main.py | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/near-rt-ric-simulator/Dockerfile b/near-rt-ric-simulator/Dockerfile index c23f034..0c52dc9 100644 --- a/near-rt-ric-simulator/Dockerfile +++ b/near-rt-ric-simulator/Dockerfile @@ -1,5 +1,6 @@ # ============LICENSE_START=============================================== # Copyright (C) 2021-2023 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 OpenInfra Foundation Europe. 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. @@ -17,9 +18,9 @@ FROM alpine:3.17.3 -RUN apk add --update --no-cache python3 py3-pip nginx nginx-mod-http-lua +RUN apk add --update --no-cache python3=3.10.13-r0 py3-pip nginx nginx-mod-http-lua -RUN pip3 install connexion[swagger-ui] +RUN pip3 install Flask==2.2.5 connexion[swagger-ui,flask,uvicorn] WORKDIR /usr/src/app @@ -44,4 +45,3 @@ USER ${user} RUN chmod +x src/start.sh CMD src/start.sh ${A1_VERSION} - diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/main.py b/near-rt-ric-simulator/src/OSC_2.1.0/main.py index 736438e..a487d88 100644 --- a/near-rt-ric-simulator/src/OSC_2.1.0/main.py +++ b/near-rt-ric-simulator/src/OSC_2.1.0/main.py @@ -1,5 +1,6 @@ # ============LICENSE_START=============================================== # Copyright (C) 2021-2023 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 OpenInfra Foundation Europe. 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. @@ -266,4 +267,4 @@ def statustest(): app.add_api('openapi.yaml', resolver=RelativeResolver('controllers.a1_mediator_controller')) if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1", threaded=True) \ No newline at end of file + app.run(port=port_number, host="127.0.0.1") \ No newline at end of file diff --git a/near-rt-ric-simulator/src/STD_1.1.3/main.py b/near-rt-ric-simulator/src/STD_1.1.3/main.py index 7db215a..7cdda0c 100644 --- a/near-rt-ric-simulator/src/STD_1.1.3/main.py +++ b/near-rt-ric-simulator/src/STD_1.1.3/main.py @@ -1,5 +1,6 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2021 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 OpenInfra Foundation Europe. 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. @@ -178,4 +179,4 @@ if len(sys.argv) >= 2: app.add_api('STD_A1.yaml') if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file + app.run(port=port_number, host="127.0.0.1") \ No newline at end of file diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py index d2ac7cb..85aa153 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/main.py @@ -1,5 +1,6 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2021 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 OpenInfra Foundation Europe. 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. @@ -255,4 +256,4 @@ if len(sys.argv) >= 2: app.add_api('ORAN_A1-p_V2.0.0_api.yaml') if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file + app.run(port=port_number, host="127.0.0.1") \ No newline at end of file -- 2.16.6 From d9b25321d9bce8a3db88102c127e2aa4436d81c8 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Fri, 8 Dec 2023 12:29:14 +0000 Subject: [PATCH 11/16] NONRTRIC-955: Add uvicorn, fix for appl/json Signed-off-by: DenisGNoonan Change-Id: I57090883cb12f602194a43801adfc41741f67c98 --- near-rt-ric-simulator/Dockerfile | 2 +- .../src/OSC_2.1.0/controllers/a1_mediator_controller.py | 6 ++++-- near-rt-ric-simulator/src/STD_1.1.3/a1.py | 7 ++++--- near-rt-ric-simulator/src/STD_1.1.3/main.py | 2 +- near-rt-ric-simulator/src/STD_2.0.0/a1.py | 7 ++++--- near-rt-ric-simulator/src/STD_2.0.0/main.py | 8 ++++---- near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py | 13 ++++++++++--- near-rt-ric-simulator/test/EXT_SRV/src/server.py | 2 +- near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh | 2 +- 9 files changed, 30 insertions(+), 19 deletions(-) diff --git a/near-rt-ric-simulator/Dockerfile b/near-rt-ric-simulator/Dockerfile index 0c52dc9..786b003 100644 --- a/near-rt-ric-simulator/Dockerfile +++ b/near-rt-ric-simulator/Dockerfile @@ -20,7 +20,7 @@ FROM alpine:3.17.3 RUN apk add --update --no-cache python3=3.10.13-r0 py3-pip nginx nginx-mod-http-lua -RUN pip3 install Flask==2.2.5 connexion[swagger-ui,flask,uvicorn] +RUN pip3 install Flask connexion[swagger-ui,flask,uvicorn] WORKDIR /usr/src/app diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/controllers/a1_mediator_controller.py b/near-rt-ric-simulator/src/OSC_2.1.0/controllers/a1_mediator_controller.py index aec84c5..9aa0f98 100644 --- a/near-rt-ric-simulator/src/OSC_2.1.0/controllers/a1_mediator_controller.py +++ b/near-rt-ric-simulator/src/OSC_2.1.0/controllers/a1_mediator_controller.py @@ -57,7 +57,7 @@ def a1_controller_get_all_policy_types(): res = list(policy_instances.keys()) res = list(map(int, res)) - return (res, 200) + return Response(json.dumps(res), 200, mimetype=APPL_JSON) # API Function: Get a policy type def a1_controller_get_policy_type(policy_type_id): @@ -150,7 +150,9 @@ def a1_controller_get_all_instances_for_type(policy_type_id): if (policy_type_id not in policy_instances.keys()): log_resp_text("Policy type id not found") return (None, 404) - return (list(policy_instances[policy_type_id].keys()), 200) + + res = list(policy_instances[policy_type_id].keys()) + return Response(json.dumps(res), 200, mimetype=APPL_JSON) # API Function: Get a policy instance def a1_controller_get_policy_instance(policy_type_id, policy_instance_id): diff --git a/near-rt-ric-simulator/src/STD_1.1.3/a1.py b/near-rt-ric-simulator/src/STD_1.1.3/a1.py index 23f405a..ece4f39 100644 --- a/near-rt-ric-simulator/src/STD_1.1.3/a1.py +++ b/near-rt-ric-simulator/src/STD_1.1.3/a1.py @@ -23,7 +23,7 @@ import collections import time from connexion import NoContent -from flask import Flask, escape, request, Response, make_response +from flask import Flask, request, Response from var_declaration import policy_instances, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set from utils import calcFingerprint from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name, is_duplicate_check @@ -40,8 +40,9 @@ def get_all_policy_identities(): if ((r := check_modified_response()) is not None): return r - return (list(policy_instances.keys()), 200) - + res = list(policy_instances.keys()) + return Response(json.dumps(res), 200, mimetype=APPL_JSON) + # API Function: Create or update a policy def put_policy(policyId): diff --git a/near-rt-ric-simulator/src/STD_1.1.3/main.py b/near-rt-ric-simulator/src/STD_1.1.3/main.py index 7cdda0c..df021d1 100644 --- a/near-rt-ric-simulator/src/STD_1.1.3/main.py +++ b/near-rt-ric-simulator/src/STD_1.1.3/main.py @@ -24,7 +24,7 @@ import requests from pathlib import Path -from flask import Flask, escape, request, Response +from flask import Flask, request, Response from jsonschema import validate from var_declaration import policy_instances, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set, app from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name diff --git a/near-rt-ric-simulator/src/STD_2.0.0/a1.py b/near-rt-ric-simulator/src/STD_2.0.0/a1.py index 1dd0859..9b68a6c 100755 --- a/near-rt-ric-simulator/src/STD_2.0.0/a1.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/a1.py @@ -25,7 +25,7 @@ import time import requests from connexion import NoContent -from flask import Flask, escape, request, Response, make_response +from flask import Flask, request, Response from jsonschema import validate from var_declaration import policy_instances, policy_types, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set from utils import calcFingerprint @@ -48,7 +48,7 @@ def get_all_policy_types(): return r res = list(policy_types.keys()) - return (res, 200) + return Response(json.dumps(res), 200, mimetype=APPL_JSON) # API Function: Get a policy type def get_policy_type(policyTypeId): @@ -80,7 +80,8 @@ def get_all_policy_identities(policyTypeId): pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_type_id) return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - return (list(policy_instances[policy_type_id].keys()), 200) + res = list(policy_instances[policy_type_id].keys()) + return Response(json.dumps(res), 200, mimetype=APPL_JSON) # API Function: Create or update a policy def put_policy(policyTypeId, policyId): diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py index 85aa153..3057169 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/main.py @@ -17,6 +17,7 @@ # import connexion +import uvicorn import json import sys import os @@ -24,7 +25,7 @@ import requests from pathlib import Path -from flask import Flask, escape, request, Response +from flask import Flask, request, Response from jsonschema import validate from var_declaration import policy_instances, policy_types, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set, data_delivery_counter, app from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name @@ -253,7 +254,6 @@ if len(sys.argv) >= 2: if isinstance(sys.argv[1], int): port_number = sys.argv[1] -app.add_api('ORAN_A1-p_V2.0.0_api.yaml') - if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1") \ No newline at end of file + # Use Uvicorn to run the combined app + uvicorn.run(app, host="127.0.0.1", port=port_number, log_level="info") \ No newline at end of file diff --git a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py index 3bc4aa5..ed93f34 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py @@ -16,10 +16,17 @@ # from maincommon import apipath -import connexion +from flask import Flask +from connexion import FlaskApp -#Main app -app = connexion.App(__name__, specification_dir=apipath) +flask_app = Flask(__name__) + +# Main app +app = FlaskApp(__name__, specification_dir=apipath) +app.add_api('ORAN_A1-p_V2.0.0_api.yaml') + +# Combine Connexion app with Flask app +app.app = flask_app policy_types={} policy_instances = {} diff --git a/near-rt-ric-simulator/test/EXT_SRV/src/server.py b/near-rt-ric-simulator/test/EXT_SRV/src/server.py index 77286be..cbf2a47 100644 --- a/near-rt-ric-simulator/test/EXT_SRV/src/server.py +++ b/near-rt-ric-simulator/test/EXT_SRV/src/server.py @@ -22,7 +22,7 @@ import logging import collections import time -from flask import Flask, escape, request, Response, make_response +from flask import Flask, request, Response from jsonschema import validate from var_declaration import a1_policy_instances, forced_settings diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh b/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh index f97d945..9e6a88e 100755 --- a/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh +++ b/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh @@ -341,7 +341,7 @@ RESULT="[]" do_curl GET /a1-p/policytypes/1/policies 200 echo "=== API: Get instances for type 2, shall contain pi2 ===" -RESULT="[ \"pi2\" ]" +RESULT="json:[ \"pi2\" ]" do_curl GET /a1-p/policytypes/2/policies 200 echo "=== Get counter: instances ===" -- 2.16.6 From eeada8f53f73da742cc2fbdba581f2fabb9578c5 Mon Sep 17 00:00:00 2001 From: JohnKeeney Date: Thu, 14 Dec 2023 12:51:56 +0000 Subject: [PATCH 12/16] Release notes & Roll version after i-release 2.6.0 -> 2.6.1 Change-Id: Ib2fafb4aec2d50e1c1263f49bc5a6eda7cae5c9c Signed-off-by: JohnKeeney Issue-ID: NONRTRIC-958 --- docs/conf.py | 2 +- docs/release-notes.rst | 26 +++++++++++++++++++++++++- near-rt-ric-simulator/container-tag.yaml | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 42330a6..af57fd7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,6 @@ from docs_conf.conf import * -branch = 'latest' +branch = 'i-release' language = 'en' diff --git a/docs/release-notes.rst b/docs/release-notes.rst index f9442bd..48ea755 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -1,6 +1,7 @@ .. This work is licensed under a Creative Commons Attribution 4.0 International License. .. http://creativecommons.org/licenses/by/4.0 -.. Copyright (C) 2021-2023 Nordix +.. Copyright (C) 2021-2023 Nordix. All rights reserved. +.. Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. ============= Release-Notes @@ -42,6 +43,9 @@ Version history A1 Simulator (previously called Near-RT RIC A1 Interface) | 2023-06-16 | 2.5.0 | John Keeney | H Release | | | | | | +------------+----------+------------------+----------------+ +| 2023-12-14 | 2.6.0 | John Keeney | I Release | +| | | | | ++------------+----------+------------------+----------------+ Release Data ============ @@ -183,3 +187,23 @@ H Release | | Reduced Image size | | | | +-----------------------------+-------------------------------------------------------+ + +I Release +--------- ++-----------------------------+-------------------------------------------------------+ +| **Project** | Non-RT RIC | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Repo/commit-ID** | a1-interface/d9b25321d9bce8a3db88102c127e2aa4436d81c8 | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Release designation** | H | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Release date** | 2023-12-14 | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Purpose of the delivery** | a1-simulator:2.6.0 | +| | Minor improvements & better A1 compliance | +| | | ++-----------------------------+-------------------------------------------------------+ diff --git a/near-rt-ric-simulator/container-tag.yaml b/near-rt-ric-simulator/container-tag.yaml index 04f6ce0..357c8f4 100644 --- a/near-rt-ric-simulator/container-tag.yaml +++ b/near-rt-ric-simulator/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 2.6.0 +tag: 2.6.1 -- 2.16.6 From de26e8b88aee5d90681321f856467d5dc367d659 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Thu, 14 Dec 2023 13:18:20 +0000 Subject: [PATCH 13/16] NONRTRIC-955: Fix unit test 404 issue Signed-off-by: DenisGNoonan Change-Id: Ib12d9a89b397d4912364ce5884983bf7589f1380 (cherry picked from commit 3c47934969cb887007ad96d71906598a9a4bf0cc) --- near-rt-ric-simulator/src/STD_2.0.0/main.py | 6 +++--- near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py | 12 ++---------- tox.ini | 3 ++- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py index 3057169..c16b81e 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/main.py @@ -17,7 +17,6 @@ # import connexion -import uvicorn import json import sys import os @@ -254,6 +253,7 @@ if len(sys.argv) >= 2: if isinstance(sys.argv[1], int): port_number = sys.argv[1] +app.add_api('ORAN_A1-p_V2.0.0_api.yaml') + if __name__ == '__main__': - # Use Uvicorn to run the combined app - uvicorn.run(app, host="127.0.0.1", port=port_number, log_level="info") \ No newline at end of file + app.run(port=port_number, host="127.0.0.1") \ No newline at end of file diff --git a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py index ed93f34..390d3f4 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py @@ -15,18 +15,10 @@ # ============LICENSE_END================================================= # +import connexion from maincommon import apipath -from flask import Flask -from connexion import FlaskApp -flask_app = Flask(__name__) - -# Main app -app = FlaskApp(__name__, specification_dir=apipath) -app.add_api('ORAN_A1-p_V2.0.0_api.yaml') - -# Combine Connexion app with Flask app -app.app = flask_app +app = connexion.App(__name__, specification_dir=apipath) policy_types={} policy_instances = {} diff --git a/tox.ini b/tox.ini index ffbcb1b..18306b5 100644 --- a/tox.ini +++ b/tox.ini @@ -26,7 +26,8 @@ deps= pytest coverage pytest-cov - connexion + connexion==2.14.2 + Flask==2.2.5 setenv = TESTS_BASE_PATH = {toxinidir}/near-rt-ric-simulator/tests -- 2.16.6 From 6ed44f057990e00cc14968c0064bae8d2dbe20ed Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Thu, 14 Dec 2023 13:39:14 +0000 Subject: [PATCH 14/16] NONRTRIC-955: Fix unit test 404 issue Issue-Id: NONRTRIC-955 Signed-off-by: DenisGNoonan Change-Id: I36e234937630a9051abb01ad82ad7bc1186ff49c (cherry picked from commit 79992d7e456696d6211edcb64d6b2ce2d8b730c6) --- near-rt-ric-simulator/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/near-rt-ric-simulator/Dockerfile b/near-rt-ric-simulator/Dockerfile index 786b003..4407f8c 100644 --- a/near-rt-ric-simulator/Dockerfile +++ b/near-rt-ric-simulator/Dockerfile @@ -20,7 +20,7 @@ FROM alpine:3.17.3 RUN apk add --update --no-cache python3=3.10.13-r0 py3-pip nginx nginx-mod-http-lua -RUN pip3 install Flask connexion[swagger-ui,flask,uvicorn] +RUN pip3 install Flask==2.2.5 connexion[swagger-ui,flask]==2.14.2 WORKDIR /usr/src/app -- 2.16.6 From ae53095259c359f532dc9d2e0056402277379e0c Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Fri, 15 Dec 2023 11:37:19 +0000 Subject: [PATCH 15/16] NONRTRIC-955: Update copyright notices Issue-Id: NONRTRIC-955 Signed-off-by: DenisGNoonan Change-Id: I4e42482b01df5d3d869ff2cc23f05b6a34f54b84 (cherry picked from commit 7e60269c016a7889f0db0655fe19d6d6fac3d3ea) --- near-rt-ric-simulator/src/STD_2.0.0/main.py | 1 - near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py | 3 ++- tox.ini | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py index c16b81e..16779c8 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/main.py @@ -16,7 +16,6 @@ # ============LICENSE_END================================================= # -import connexion import json import sys import os diff --git a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py index 390d3f4..5280c07 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py @@ -1,5 +1,6 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2021 Nordix Foundation. All rights reserved. +# Copyright (C) 2021-2023 Nordix Foundation. All rights reserved. +# Copyright (C) 2023 OpenInfra Foundation Europe. 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. diff --git a/tox.ini b/tox.ini index 18306b5..023d9bf 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ # ================================================================================== -# Copyright (c) 2020-2022 Nordix +# Copyright (c) 2020-2023 Nordix +# Copyright (C) 2023 OpenInfra Foundation Europe. 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. -- 2.16.6 From 33a47ce05679a2a982d3a84bb8c86f3928177460 Mon Sep 17 00:00:00 2001 From: JohnKeeney Date: Sat, 16 Dec 2023 00:23:14 +0000 Subject: [PATCH 16/16] Release notes & Roll version after i-release 2.6.1 -> 2.6.2 Change-Id: I72dc89f639c231abdfadc0bfcce0f5358bf1ae4d Signed-off-by: JohnKeeney Issue-ID: NONRTRIC-958 --- docs/release-notes.rst | 23 ++++++++++++++++++++++- near-rt-ric-simulator/container-tag.yaml | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 48ea755..528f73c 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -46,6 +46,9 @@ Version history A1 Simulator (previously called Near-RT RIC A1 Interface) | 2023-12-14 | 2.6.0 | John Keeney | I Release | | | | | | +------------+----------+------------------+----------------+ +| 2023-12-15 | 2.6.1 | John Keeney | I Release | +| | | | | ++------------+----------+------------------+----------------+ Release Data ============ @@ -197,7 +200,7 @@ I Release | **Repo/commit-ID** | a1-interface/d9b25321d9bce8a3db88102c127e2aa4436d81c8 | | | | +-----------------------------+-------------------------------------------------------+ -| **Release designation** | H | +| **Release designation** | I | | | | +-----------------------------+-------------------------------------------------------+ | **Release date** | 2023-12-14 | @@ -207,3 +210,21 @@ I Release | | Minor improvements & better A1 compliance | | | | +-----------------------------+-------------------------------------------------------+ + ++-----------------------------+-------------------------------------------------------+ +| **Project** | Non-RT RIC | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Repo/commit-ID** | a1-interface/ae53095259c359f532dc9d2e0056402277379e0c | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Release designation** | I | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Release date** | 2023-12-15 | +| | | ++-----------------------------+-------------------------------------------------------+ +| **Purpose of the delivery** | a1-simulator:2.6.1 | +| | Fixed minor issue with some Unit tests | +| | | ++-----------------------------+-------------------------------------------------------+ diff --git a/near-rt-ric-simulator/container-tag.yaml b/near-rt-ric-simulator/container-tag.yaml index 357c8f4..ac16f60 100644 --- a/near-rt-ric-simulator/container-tag.yaml +++ b/near-rt-ric-simulator/container-tag.yaml @@ -1,2 +1,2 @@ --- -tag: 2.6.1 +tag: 2.6.2 -- 2.16.6