Add script to start PMS and add policy type 14/10214/10
authorelinuxhenrik <henrik.b.andersson@est.tech>
Wed, 28 Dec 2022 15:21:47 +0000 (16:21 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Mon, 2 Jan 2023 14:09:58 +0000 (15:09 +0100)
Issue-ID: NONRTRIC-749
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: I85f05228f186499d68123f484dd09781141d407d

README.md
test/application_configuration.json [new file with mode: 0644]
test/sim_hw.json [new file with mode: 0644]
test/start.sh [new file with mode: 0755]
test/stop.sh [new file with mode: 0755]

index af87608..d6a8ac9 100644 (file)
--- a/README.md
+++ b/README.md
@@ -6,24 +6,33 @@ The Health Check use case test provides a python script that regularly creates,
 in all Near-RT RICs that support the type used by the script. A self refreshing web page provides a view of statistics
 for these regular checks.
 
-## Prerequisits
+## Prerequisites
 
 To run this script Python3 needs to be installed. To install the script's dependencies, run the following command from
 the `src` folder: `pip install -r requirements.txt`
 
 ## How to run
 
-Go to the `src/` folder and run `python3 main.py`. The script will start and run until stopped. Use the `-h` option to
+To start the Policy Management Service (PMS) and RIC simulators and install the default policy type, do the following:
+
+1. Go to the `test` folder.
+2. Check that the `start.sh` script has the correct versions of PMS and simulators. If not, update it to the correct versions.
+3. Run the `start.sh` script.
+4. The script will finnish when the policy type is registered and synched in PMS.
+
+To start the use case, go to the `src/` folder and run `python3 main.py`. The script will start and run until stopped. Use the `-h` option to
 see the options available for the script.
 
 As default, the script uses the "Hello World" policy type with ID "2". To create the instances it uses the body file
 `nonrtric/test/autotest/testdata/OSC/pihw_template.json`. The body file contains the string "XXX" as a parameter value.
-This string vill be replaced with dynamic data during creation. It is possible to provide a custom policy type and
+This string will be replaced with dynamic data during creation. It is possible to provide a custom policy type and
 body file to the script at startup.
 
 To see the web page, navigate to `localhost:9990/stats`. The page refreshes itself with the same interval as the script
 uses.
 
+To stop PMS and the simulators, run the `stop.sh` script.
+
 ## License
 
 Copyright (C) 2020-2022 Nordix Foundation.
diff --git a/test/application_configuration.json b/test/application_configuration.json
new file mode 100644 (file)
index 0000000..53da122
--- /dev/null
@@ -0,0 +1,22 @@
+{
+    "config": {
+        "ric": [
+            {
+                "name": "ric1",
+                "baseUrl": "http://ric1:8085/",
+                "managedElementIds": [
+                    "kista_1",
+                    "kista_2"
+                ]
+            },
+            {
+                "name": "ric2",
+                "baseUrl": "http://ric2:8085/",
+                "managedElementIds": [
+                    "kista_3",
+                    "kista_4"
+                ]
+            }
+        ]
+    }
+}
diff --git a/test/sim_hw.json b/test/sim_hw.json
new file mode 100644 (file)
index 0000000..47e0ae0
--- /dev/null
@@ -0,0 +1,18 @@
+{
+    "name": "hwpolicy",
+    "description": "Hellow World policy type",
+    "policy_type_id": 2,
+    "create_schema": {
+      "$schema": "http://json-schema.org/draft-07/schema#",
+      "title": "HW Policy",
+      "description": "Hello World policy type",
+      "type": "object",
+      "properties": {
+        "threshold": {
+          "type": "integer",
+          "default": 0
+        }
+      },
+      "additionalProperties": false
+    }
+  }
\ No newline at end of file
diff --git a/test/start.sh b/test/start.sh
new file mode 100755 (executable)
index 0000000..1063c5a
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2022 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=================================================
+#
+
+docker network create nonrtric-docker-net 2> /dev/null
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+
+PMS_PORT=8081
+docker run --detach --rm -v $DIR/application_configuration.json:/opt/app/policy-agent/data/application_configuration.json -p $PMS_PORT:$PMS_PORT -p 8433:8433 --network=nonrtric-docker-net --name=policy-agent-container nexus3.o-ran-sc.org:10002/o-ran-sc/nonrtric-plt-a1policymanagementservice:2.5.0
+SIM_PORT=8085
+docker run --detach --rm -p $SIM_PORT:$SIM_PORT -p 8185:8185 -e A1_VERSION=OSC_2.1.0 -e ALLOW_HTTP=true --network=nonrtric-docker-net --name=ric1 nexus3.o-ran-sc.org:10002/o-ran-sc/a1-simulator:2.3.1
+
+docker run --detach --rm -p 8086:$SIM_PORT -p 8186:8185 -e A1_VERSION=STD_1.1.3 -e ALLOW_HTTP=true --network=nonrtric-docker-net --name=ric2 nexus3.o-ran-sc.org:10002/o-ran-sc/a1-simulator:2.3.1
+
+retcode=1
+while [ $retcode -ne 0 ]; do
+    RES=$(curl -s -w '%{http_code}'  -X PUT -v http://localhost:$SIM_PORT/a1-p/policytypes/2 -H Content-Type:application/json --data-binary @sim_hw.json)
+    retcode=$?
+    if [ $retcode -eq 0 ]; then
+        status=${RES:${#RES}-3}
+        if [ $status -ne 201 ]; then
+            retcode=1
+        fi
+    fi
+
+    if [ $retcode -ne 0 ]; then
+        echo "Retrying..."
+        sleep 1
+    fi
+done
+
+retcode=1
+while [ $retcode -ne 0 ]; do
+    echo "Checking that type is available"
+    RES=$(curl -s -w '%{http_code}' localhost:$PMS_PORT/a1-policy/v2/rics)
+    retcode=$?
+    if [ $retcode -eq 0 ]; then
+        if [[ "$RES" != *'"policytype_ids":["2"]'* ]]; then
+            retcode=1
+        fi
+    fi
+    if [ $retcode -ne 0 ]; then
+        echo "Retrying..."
+        sleep 1
+    fi
+done
diff --git a/test/stop.sh b/test/stop.sh
new file mode 100755 (executable)
index 0000000..ac1a623
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2022: 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.
+#   ========================LICENSE_END===================================
+#
+
+docker stop policy-agent-container ric1 ric2