From: Henrik Andersson Date: Mon, 24 Feb 2020 15:06:37 +0000 (+0000) Subject: Merge "Improve the dockerized auto test" X-Git-Tag: 2.0.0~164 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=063e00d7a9f1f56c8b0714602fcaecb3c4eac951;hp=1391d501b25e6559a76bb1ab5681429a181d358a;p=nonrtric.git Merge "Improve the dockerized auto test" --- diff --git a/near-rt-ric-simulator/auto-test/Dockerize_test.sh b/near-rt-ric-simulator/auto-test/Dockerize_test.sh index 611523e2..93cc3102 100755 --- a/near-rt-ric-simulator/auto-test/Dockerize_test.sh +++ b/near-rt-ric-simulator/auto-test/Dockerize_test.sh @@ -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" diff --git a/near-rt-ric-simulator/common/testcase_common.sh b/near-rt-ric-simulator/common/testcase_common.sh index dfca543c..d9a012ea 100755 --- a/near-rt-ric-simulator/common/testcase_common.sh +++ b/near-rt-ric-simulator/common/testcase_common.sh @@ -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 "" diff --git a/near-rt-ric-simulator/simulator-group/consul_cbs/config.json b/near-rt-ric-simulator/simulator-group/consul_cbs/config.json index 16975ca0..432eddf2 100644 --- a/near-rt-ric-simulator/simulator-group/consul_cbs/config.json +++ b/near-rt-ric-simulator/simulator-group/consul_cbs/config.json @@ -1,28 +1,100 @@ { - "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 diff --git a/near-rt-ric-simulator/simulator-group/consul_cbs/docker-compose-template.yml b/near-rt-ric-simulator/simulator-group/consul_cbs/docker-compose-template.yml index 2f7ac3ed..c2d07de9 100644 --- a/near-rt-ric-simulator/simulator-group/consul_cbs/docker-compose-template.yml +++ b/near-rt-ric-simulator/simulator-group/consul_cbs/docker-compose-template.yml @@ -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 index 00000000..1e404169 --- /dev/null +++ b/near-rt-ric-simulator/simulator-group/ric/cleanConsul.py @@ -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 index 00000000..e45e0e41 --- /dev/null +++ b/near-rt-ric-simulator/simulator-group/ric/docker-compose.yml @@ -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 index 00000000..5cb482bb --- /dev/null +++ b/near-rt-ric-simulator/simulator-group/ric/prepareConsul.py @@ -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") diff --git a/near-rt-ric-simulator/simulator-group/simulators-start.sh b/near-rt-ric-simulator/simulator-group/simulators-start.sh index 7f833973..adcf6219 100755 --- a/near-rt-ric-simulator/simulator-group/simulators-start.sh +++ b/near-rt-ric-simulator/simulator-group/simulators-start.sh @@ -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