Improve the dockerized auto test 59/2559/1
authorYongchaoWu <yongchao.wu@est.tech>
Mon, 24 Feb 2020 08:18:16 +0000 (09:18 +0100)
committeryongchao <yongchao.wu@est.tech>
Mon, 24 Feb 2020 08:22:22 +0000 (09:22 +0100)
The auto test can bring up any number of near rt ric simulators
as requied.

Issue-ID: NONRTRIC-115
Signed-off-by: YongchaoWu <yongchao.wu@est.tech>
Change-Id: I88461b6b5d3fa33a9fccd7cedf15535e06143bb6

near-rt-ric-simulator/auto-test/Dockerize_test.sh
near-rt-ric-simulator/common/testcase_common.sh
near-rt-ric-simulator/simulator-group/consul_cbs/config.json
near-rt-ric-simulator/simulator-group/consul_cbs/docker-compose-template.yml
near-rt-ric-simulator/simulator-group/ric/cleanConsul.py [new file with mode: 0644]
near-rt-ric-simulator/simulator-group/ric/docker-compose.yml [new file with mode: 0644]
near-rt-ric-simulator/simulator-group/ric/prepareConsul.py [new file with mode: 0644]
near-rt-ric-simulator/simulator-group/simulators-start.sh

index 611523e..93cc310 100755 (executable)
@@ -2,12 +2,16 @@
 
 TC_ONELINE_DESCR="dockerirze the test, setup docker container for policy agent, cbs, consul, near realtime ric simulator"
 
-. ../common/testcase_common.sh $1
+. ../common/testcase_common.sh $1 $2
 
 #### TEST BEGIN ####
 
 clean_containers
 
+start_ric_simulator
+
+prepare_consul_config
+
 start_simulators
 
 consul_config_app         "../simulator-group/consul_cbs/config.json"
index dfca543..d9a012e 100755 (executable)
@@ -2,18 +2,20 @@
 
 . ../common/test_env.sh
 
-echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1
+echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2
+echo "Numbers of ric simulator started" $2
 
 # This is a script that contains all the functions needed for auto test
-# Arg: local | remote
+# Arg: local | remote (1, 2, 3, 4....)
 
 STARTED_POLICY_AGENT="" #Policy agent app names added to this var to keep track of started container in the script
 START_ARG=$1
 IMAGE_TAG="1.0.0-SNAPSHOT"
 IMAGE_TAG_REMOTE="latest"
+RIC_NUMBER=$2
 
 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
-       echo "Expected arg: local  | remote  "
+       echo "Expected arg: local  | remote  and numbers of the rics "
        exit 1
 elif [ $1 == "local" ]; then
        if [ -z $POLICY_AGENT_LOCAL_IMAGE ]; then
@@ -144,12 +146,48 @@ consul_config_app() {
 
 }
 
+
+
+start_ric_simulator() {
+
+  DOCKER_SIM_NWNAME="nonrtric-docker-net"
+  echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
+  docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
+
+  echo "start ric simulator"
+  curdir=$PWD
+  cd $SIM_GROUP
+  cd ric/
+
+  docker-compose up --scale ric-simulator=$RIC_NUMBER -d
+
+  cd $curdir
+       echo ""
+}
+
+prepare_consul_config() {
+  echo "prepare consul config"
+  curdir=$PWD
+  cd $SIM_GROUP
+  cd ric/
+
+  python3 cleanConsul.py
+  python3 prepareConsul.py
+
+  cd $curdir
+       echo ""
+
+
+}
+
+
 # Start all simulators in the simulator group
 start_simulators() {
 
        echo "Starting all simulators"
        curdir=$PWD
        cd $SIM_GROUP
+
        $SIM_GROUP/simulators-start.sh
        cd $curdir
        echo ""
@@ -160,6 +198,10 @@ clean_containers() {
        docker stop $(docker ps -q --filter name=/policy-agent) &> /dev/null
        echo "Removing all containers, policy agent app and simulators with name prefix 'policy_agent'"
        docker rm $(docker ps -a -q --filter name=/policy-agent) &> /dev/null
+       echo "Stopping all containers, policy agent app(s) and simulators with name prefix 'ric-simulator'"
+       docker stop $(docker ps -q --filter name=ric-simulator) &> /dev/null
+       echo "Removing all containers, policy agent app and simulators with name prefix 'ric-simulator'"
+       docker rm $(docker ps -a -q --filter name=ric-simulator) &> /dev/null
        echo "Removing unused docker networks with substring 'policy agent' in network name"
        docker network rm $(docker network ls -q --filter name=nonrtric)
        echo ""
index 16975ca..432eddf 100644 (file)
 {
-      "ric":[
-         {
-            "name":"ric3",
-            "baseUrl":"http://ric3:8085/",
-            "managedElementIds":[
-               "kista_1",
-               "kista_2"
-            ]
-         }
-      ],
-      "streams_publishes":{
-         "dmaap_publisher":{
-            "type":"message_router",
-            "dmaap_info":{
-               "topic_url":"http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE"
+    "ric": [
+        {
+            "name": "ric_ric-simulator_6",
+            "baseUrl": "http://ric_ric-simulator_6:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_6",
+                "stockholm_ric_ric-simulator_6"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_2",
+            "baseUrl": "http://ric_ric-simulator_2:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_2",
+                "stockholm_ric_ric-simulator_2"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_3",
+            "baseUrl": "http://ric_ric-simulator_3:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_3",
+                "stockholm_ric_ric-simulator_3"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_7",
+            "baseUrl": "http://ric_ric-simulator_7:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_7",
+                "stockholm_ric_ric-simulator_7"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_8",
+            "baseUrl": "http://ric_ric-simulator_8:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_8",
+                "stockholm_ric_ric-simulator_8"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_5",
+            "baseUrl": "http://ric_ric-simulator_5:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_5",
+                "stockholm_ric_ric-simulator_5"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_1",
+            "baseUrl": "http://ric_ric-simulator_1:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_1",
+                "stockholm_ric_ric-simulator_1"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_9",
+            "baseUrl": "http://ric_ric-simulator_9:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_9",
+                "stockholm_ric_ric-simulator_9"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_4",
+            "baseUrl": "http://ric_ric-simulator_4:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_4",
+                "stockholm_ric_ric-simulator_4"
+            ]
+        },
+        {
+            "name": "ric_ric-simulator_10",
+            "baseUrl": "http://ric_ric-simulator_10:8085/",
+            "managedElementIds": [
+                "kista_ric_ric-simulator_10",
+                "stockholm_ric_ric-simulator_10"
+            ]
+        }
+    ],
+    "streams_publishes": {
+        "dmaap_publisher": {
+            "type": "message_router",
+            "dmaap_info": {
+                "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE"
             }
-         }
-      },
-      "streams_subscribes":{
-         "dmaap_subscriber":{
-            "type":"message_router",
-            "dmaap_info":{
-               "topic_url":"http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent"
+        }
+    },
+    "streams_subscribes": {
+        "dmaap_subscriber": {
+            "type": "message_router",
+            "dmaap_info": {
+                "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent"
             }
-         }
-      }
-}
+        }
+    }
+}
\ No newline at end of file
index 2f7ac3e..c2d07de 100644 (file)
@@ -29,10 +29,3 @@ services:
     depends_on:
       - consul-server
 
-  ric-simulator:
-    networks:
-      - nonrtric-docker-net
-    container_name: ric3
-    image: ric-simulator:latest
-    ports:
-      - "8085:8085"
diff --git a/near-rt-ric-simulator/simulator-group/ric/cleanConsul.py b/near-rt-ric-simulator/simulator-group/ric/cleanConsul.py
new file mode 100644 (file)
index 0000000..1e40416
--- /dev/null
@@ -0,0 +1,24 @@
+import json
+import subprocess
+import os
+
+print("Clean old ric configurations in Consul config file")
+
+p = os.path.abspath('..')
+consul_config = p + '/consul_cbs' + '/config.json'
+
+
+def write_json(data, filename=consul_config):
+    with open(filename, 'w') as f:
+        json.dump(data, f, indent=4)
+
+
+with open(consul_config) as json_file:
+    clean = json.load(json_file)
+    clean['ric'] = []
+
+
+write_json(clean)
+print("Clean old ric configurations from Consul config file, done")
+
+
diff --git a/near-rt-ric-simulator/simulator-group/ric/docker-compose.yml b/near-rt-ric-simulator/simulator-group/ric/docker-compose.yml
new file mode 100644 (file)
index 0000000..e45e0e4
--- /dev/null
@@ -0,0 +1,12 @@
+networks:
+  nonrtric-docker-net:
+    external:
+      name: nonrtric-docker-net
+services:
+  ric-simulator:
+    image: ric-simulator:latest
+    networks:
+      nonrtric-docker-net: null
+    ports:
+    - 8085/tcp
+version: '3.0'
\ No newline at end of file
diff --git a/near-rt-ric-simulator/simulator-group/ric/prepareConsul.py b/near-rt-ric-simulator/simulator-group/ric/prepareConsul.py
new file mode 100644 (file)
index 0000000..5cb482b
--- /dev/null
@@ -0,0 +1,43 @@
+import json
+import subprocess
+import os
+
+print("Update fresh ric configuration in Consul configuration file")
+
+p = os.path.abspath('..')
+consul_config = p + '/consul_cbs' + '/config.json'
+
+
+def write_json(data, filename=consul_config):
+    with open(filename, 'w') as f:
+        json.dump(data, f, indent=4)
+
+
+def bash_command(cmd):
+    result = []
+    sp = subprocess.Popen(['/bin/bash', '-c', cmd], stdout=subprocess.PIPE)
+    for line in sp.stdout.readlines():
+        result.append(line.decode().strip())
+    return result
+
+
+command = "docker ps | grep simulator | awk '{print $NF}'"
+
+ric_list = bash_command(command)
+
+with open(consul_config) as json_file:
+    data = json.load(json_file)
+    temp = data['ric']
+    for ric in ric_list:
+        y = {"name": ric,
+             "baseUrl": "http://" + ric + ":8085/",
+             "managedElementIds": [
+                 "kista_" + ric,
+                 "stockholm_" + ric
+             ]
+             }
+        temp.append(y)
+
+
+write_json(data)
+print("Update Consul config file with fresh ric configuration,  done")
index 7f83397..adcf621 100755 (executable)
@@ -3,7 +3,6 @@
 DOCKER_SIM_NWNAME="nonrtric-docker-net"
 echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
 docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
-
 docker-compose -f consul_cbs/docker-compose-template.yml config > docker-compose.yml
 
 docker-compose up -d
\ No newline at end of file