X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=near-rt-ric-simulator%2Fcommon%2Ftestcase_common.sh;h=b4ceb0d004492be98c778267c08fdd161973c43e;hb=86edae3a023951528c89b0ae88dcfb95a5dcf9ad;hp=7a8d8dca085255c62d8cedc5f248b211abe98271;hpb=ffde6eb81f80f6ebd8e7cb48b9acacd0733dd7fe;p=nonrtric.git diff --git a/near-rt-ric-simulator/common/testcase_common.sh b/near-rt-ric-simulator/common/testcase_common.sh index 7a8d8dca..b4ceb0d0 100755 --- a/near-rt-ric-simulator/common/testcase_common.sh +++ b/near-rt-ric-simulator/common/testcase_common.sh @@ -2,18 +2,21 @@ . ../common/test_env.sh -echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2 +echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2 $3 +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 +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="1.0.0" +IMAGE_TAG_REMOTE="latest" +RIC_NUMBER=$2 +SDNC=$3 -if [ $# -lt 1 ] || [ $# -gt 2 ]; then - echo "Expected arg: local [] | remote [] " +if [ $# -lt 1 ] || [ $# -gt 4 ]; then + echo "Expected arg: local | remote and numbers of the rics and SDNC " exit 1 elif [ $1 == "local" ]; then if [ -z $POLICY_AGENT_LOCAL_IMAGE ]; then @@ -82,8 +85,8 @@ fi echo "" if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then - #echo -e "Policy agent image tag set to: \033[1m" $IMAGE_TAG"\033[0m" - echo "Configured image for policy agent app(s) (${1}): "$POLICY_AGENT_IMAGE + #echo -e "Policy Agent image tag set to: \033[1m" $IMAGE_TAG"\033[0m" + echo "Configured image for Policy Agent app(s) (${1}): "$POLICY_AGENT_IMAGE tmp_im=$(docker images ${POLICY_AGENT_IMAGE} | grep -v REPOSITORY) if [ $1 == "local" ]; then @@ -91,12 +94,12 @@ if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then echo "Local image (non nexus) "$POLICY_AGENT_IMAGE" does not exist in local registry, need to be built" exit 1 else - echo -e "Policy agent local image: \033[1m"$tmp_im"\033[0m" - echo "If the policy agent image seem outdated, rebuild the image and run the test again." + echo -e "Policy Agent local image: \033[1m"$tmp_im"\033[0m" + echo "If the Policy Agent image seem outdated, rebuild the image and run the test again." fi elif [ $1 == "remote" ]; then if [ -z "$tmp_im" ]; then - echo "Pulling policy agent image from nexus: "$POLICY_AGENT_IMAGE + echo "Pulling Policy Agent image from nexus: "$POLICY_AGENT_IMAGE docker pull $POLICY_AGENT_IMAGE > /dev/null tmp_im=$(docker images ${POLICY_AGENT_IMAGE} | grep -v REPOSITORY) if [ -z "$tmp_im" ]; then @@ -106,11 +109,37 @@ if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then echo -e "Policy Agent image: \033[1m"$tmp_im"\033[0m" else echo -e "Policy Agent image: \033[1m"$tmp_im"\033[0m" - echo "!! If the Policy agent image seem outdated, consider removing it from your docker registry and run the test again." + echo "!! If the Policy Agent image seem outdated, consider removing it from your docker registry and run the test again." fi fi fi +echo "" + +echo "Building images for the simulators" +if [ -z "$SIM_DIR" ]; then + SIM_DIR=$(find . -type d -path "*a1-interface/near-rt-ric-simulator/scripts*" 2>/dev/null -print -quit) + if [ ! -d $SIM_DIR ]; then + echo "Trying to set env var SIM_DIR to dir 'a1-interface/near-rt-ric-simulator/scripts' in the sim repo, but failed." + echo "It might be that you did not download the repository of the Near-rt-ric simulator.In that case, run the command:" + echo "git clone 'https://gerrit.o-ran-sc.org/oransc/sim/a1-interface'" + echo "Otherwise, please set the SIM_DIR manually in the test_env.sh" + exit 1 + else + echo "SIM_DIR auto set to: " $SIM_DIR + fi +fi +cd $SIM_DIR +docker build -t ric-simulator:latest . &> /dev/null +cd $curdir + +echo "" + +echo "Local registry images for simulators:" +echo "Consul: " $(docker images | grep consul) +echo "CBS: " $(docker images | grep platform.configbinding.app) +echo "RIC: " $(docker images | grep ric-simulator) +echo "" __consul_config() { @@ -128,23 +157,111 @@ 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 "" +} + +start_dashboard() { + + 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 Control Panel" + curdir=$PWD + cd $SIM_GROUP + cd dashboard/ + + docker-compose up -d + + cd $curdir + echo "" +} + +start_sdnc() { + + if [ $SDNC == "sdnc" ]; then + 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 sdnc" + curdir=$PWD + cd $SIM_GROUP + cd sdnc/ + + docker-compose up -d a1-controller + + cd $curdir + echo "" + fi +} + +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 "" } + + clean_containers() { - echo "Stopping all containers, policy agent app(s) and simulators with name prefix 'policy_agent'" + echo "Stopping all containers, Policy Agent app(s) and simulators with name prefix 'policy-agent'" 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'" + 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 "Removing unused docker networks with substring 'policy agent' in network name" + 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 all containers, Policy Agent app and simulators with name prefix 'dashboard'" + docker rm $(docker ps -a -q --filter name=dashboard) &> /dev/null + echo "Removing all containers, Policy Agent app and simulators with name prefix 'a1-controller'" + docker rm $(docker ps -a -q --filter name=a1-controller) &> /dev/null + echo "Removing all containers, Policy Agent app and simulators with name prefix 'sdnc_db_container'" + docker rm $(docker ps -a -q --filter name=sdnc_db_container) &> /dev/null + echo "Removing all containers, Policy Agent app and simulators with name prefix 'cbs'" + docker rm $(docker ps -a -q --filter name=polman_cbs) &> /dev/null + echo "Removing all containers, Policy Agent app and simulators with name prefix 'consul'" + docker rm $(docker ps -a -q --filter name=polman_consul) &> /dev/null + echo "Removing unused docker networks with substring 'nonrtric' in network name" docker network rm $(docker network ls -q --filter name=nonrtric) echo "" } @@ -167,7 +284,7 @@ __start_policy_agent_image() { docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME - echo "Starting policy agent: " $appname " with ports mapped to " $localport " in docker network "$DOCKER_SIM_NWNAME + echo "Starting Policy Agent: " $appname " with ports mapped to " $localport " in docker network "$DOCKER_SIM_NWNAME docker run -d -p $localport":8081" --network=$DOCKER_SIM_NWNAME -e CONSUL_HOST=$CONSUL_HOST -e CONSUL_PORT=$CONSUL_PORT -e CONFIG_BINDING_SERVICE=$CONFIG_BINDING_SERVICE -e HOSTNAME=$appname --name $appname $POLICY_AGENT_IMAGE #docker run -d -p 8081:8081 --network=nonrtric-docker-net -e CONSUL_HOST=CONSUL_HOST=$CONSUL_HOST -e CONSUL_PORT=$CONSUL_PORT -e CONFIG_BINDING_SERVICE=$CONFIG_BINDING_SERVICE -e HOSTNAME=policy-agent sleep 3 @@ -213,7 +330,7 @@ check_policy_agent_logs() { appname=$PA_APP_BASE tmp=$(docker ps | grep $appname) - if ! [ -z "$tmp" ]; then #Only check logs for running policy agent apps + if ! [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps __check_policy_agent_log $appname fi @@ -248,7 +365,7 @@ store_logs() { __print_err "need one arg, " exit 1 fi - echo "Storing all container logs and policy agent app log using prefix: "$1 + echo "Storing all container logs and Policy Agent app log using prefix: "$1 docker logs polman_consul > $TESTLOGS/$ATC/$1_consul.log 2>&1 docker logs polman_cbs > $TESTLOGS/$ATC/$1_cbs.log 2>&1