3 . ../common/test_env.sh
5 echo "Test case started as: ${BASH_SOURCE[$i+1]} "$1 $2 $3
6 echo "Numbers of ric simulator started" $2
8 # This is a script that contains all the functions needed for auto test
9 # Arg: local | remote (1, 2, 3, 4....)
11 STARTED_POLICY_AGENT="" #Policy Agent app names added to this var to keep track of started container in the script
13 IMAGE_TAG="1.0.0-SNAPSHOT"
14 IMAGE_TAG_REMOTE="latest"
18 if [ $# -lt 1 ] || [ $# -gt 4 ]; then
19 echo "Expected arg: local | remote and numbers of the rics and SDNC "
21 elif [ $1 == "local" ]; then
22 if [ -z $POLICY_AGENT_LOCAL_IMAGE ]; then
23 echo "POLICY_AGENT_LOCAL_IMAGE not set in test_env"
26 POLICY_AGENT_IMAGE=$POLICY_AGENT_LOCAL_IMAGE":"$IMAGE_TAG
27 elif [ $1 == "remote" ]; then
28 if [ -z $POLICY_AGENT_REMOTE_IMAGE ]; then
29 echo "POLICY_AGENT_REMOTE_IMAGE not set in test_env"
32 POLICY_AGENT_IMAGE=$POLICY_AGENT_REMOTE_IMAGE":"$IMAGE_TAG_REMOTE
35 # Set a description string for the test case
36 if [ -z "$TC_ONELINE_DESCR" ]; then
37 TC_ONELINE_DESCR="<no-description>"
38 echo "No test case description found, TC_ONELINE_DESCR should be set on in the test script , using "$TC_ONELINE_DESCR
41 ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh)
44 # Create the logs dir if not already created in the current dir
45 if [ ! -d "logs" ]; then
51 mkdir -p $TESTLOGS/$ATC
53 TCLOG=$TESTLOGS/$ATC/TC.log
54 exec &> >(tee ${TCLOG})
56 #Variables for counting tests as well as passed and failed tests
62 echo "-------------------------------------------------------------------------------------------------"
63 echo "----------------------------------- Test case: "$ATC
64 echo "----------------------------------- Started: "$(date)
65 echo "-------------------------------------------------------------------------------------------------"
66 echo "-- Description: "$TC_ONELINE_DESCR
67 echo "-------------------------------------------------------------------------------------------------"
68 echo "----------------------------------- Test case setup -----------------------------------"
71 if [ -z "$SIM_GROUP" ]; then
72 SIM_GROUP=$PWD/../simulator-group
73 if [ ! -d $SIM_GROUP ]; then
74 echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the integration repo, but failed."
75 echo "Please set the SIM_GROUP manually in the test_env.sh"
78 echo "SIM_GROUP auto set to: " $SIM_GROUP
80 elif [ $SIM_GROUP = *simulator_group ]; then
81 echo "Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the integration repo, check test_env.sh"
87 if [ $1 != "manual-container" ] && [ $1 != "manual-app" ]; then
88 #echo -e "Policy Agent image tag set to: \033[1m" $IMAGE_TAG"\033[0m"
89 echo "Configured image for Policy Agent app(s) (${1}): "$POLICY_AGENT_IMAGE
90 tmp_im=$(docker images ${POLICY_AGENT_IMAGE} | grep -v REPOSITORY)
92 if [ $1 == "local" ]; then
93 if [ -z "$tmp_im" ]; then
94 echo "Local image (non nexus) "$POLICY_AGENT_IMAGE" does not exist in local registry, need to be built"
97 echo -e "Policy Agent local image: \033[1m"$tmp_im"\033[0m"
98 echo "If the Policy Agent image seem outdated, rebuild the image and run the test again."
100 elif [ $1 == "remote" ]; then
101 if [ -z "$tmp_im" ]; then
102 echo "Pulling Policy Agent image from nexus: "$POLICY_AGENT_IMAGE
103 docker pull $POLICY_AGENT_IMAGE > /dev/null
104 tmp_im=$(docker images ${POLICY_AGENT_IMAGE} | grep -v REPOSITORY)
105 if [ -z "$tmp_im" ]; then
106 echo "Image could not be pulled"
109 echo -e "Policy Agent image: \033[1m"$tmp_im"\033[0m"
111 echo -e "Policy Agent image: \033[1m"$tmp_im"\033[0m"
112 echo "!! If the Policy Agent image seem outdated, consider removing it from your docker registry and run the test again."
119 echo "Building images for the simulators"
120 if [ -z "$SIM_DIR" ]; then
121 SIM_DIR=$(find . -type d -path "*a1-interface/near-rt-ric-simulator/scripts*" 2>/dev/null -print -quit)
122 if [ ! -d $SIM_DIR ]; then
123 echo "Trying to set env var SIM_DIR to dir 'a1-interface/near-rt-ric-simulator/scripts' in the sim repo, but failed."
124 echo "It might be that you did not download the repository of the Near-rt-ric simulator.In that case, run the command:"
125 echo "git clone 'https://gerrit.o-ran-sc.org/oransc/sim/a1-interface'"
126 echo "Otherwise, please set the SIM_DIR manually in the test_env.sh"
129 echo "SIM_DIR auto set to: " $SIM_DIR
133 docker build -t ric-simulator:latest . &> /dev/null
138 echo "Local registry images for simulators:"
139 echo "Consul: " $(docker images | grep consul)
140 echo "CBS: " $(docker images | grep platform.configbinding.app)
141 echo "RIC: " $(docker images | grep ric-simulator)
149 echo "Configuring consul for " $appname " from " $1
150 curl -s http://127.0.0.1:${CONSUL_PORT}/v1/kv/${appname}?dc=dc1 -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data-binary "@"$1 >/dev/null
154 consul_config_app() {
162 start_ric_simulator() {
164 DOCKER_SIM_NWNAME="nonrtric-docker-net"
165 echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
166 docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
168 echo "start ric simulator"
173 docker-compose up --scale ric-simulator=$RIC_NUMBER -d
181 DOCKER_SIM_NWNAME="nonrtric-docker-net"
182 echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
183 docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
185 echo "start Control Panel"
198 if [ $SDNC == "sdnc" ]; then
199 DOCKER_SIM_NWNAME="nonrtric-docker-net"
200 echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
201 docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
208 docker-compose up -d a1-controller
215 prepare_consul_config() {
216 echo "prepare consul config"
221 python3 cleanConsul.py
222 python3 prepareConsul.py
231 # Start all simulators in the simulator group
234 echo "Starting all simulators"
238 $SIM_GROUP/simulators-start.sh
246 echo "Stopping all containers, Policy Agent app(s) and simulators with name prefix 'policy-agent'"
247 docker stop $(docker ps -q --filter name=/policy-agent) &> /dev/null
248 echo "Removing all containers, Policy Agent app and simulators with name prefix 'policy-agent'"
249 docker rm $(docker ps -a -q --filter name=/policy-agent) &> /dev/null
250 echo "Stopping all containers, Policy Agent app(s) and simulators with name prefix 'ric-simulator'"
251 docker stop $(docker ps -q --filter name=ric-simulator) &> /dev/null
252 echo "Removing all containers, Policy Agent app and simulators with name prefix 'ric-simulator'"
253 docker rm $(docker ps -a -q --filter name=ric-simulator) &> /dev/null
254 echo "Removing all containers, Policy Agent app and simulators with name prefix 'dashboard'"
255 docker rm $(docker ps -a -q --filter name=dashboard) &> /dev/null
256 echo "Removing all containers, Policy Agent app and simulators with name prefix 'a1-controller'"
257 docker rm $(docker ps -a -q --filter name=a1-controller) &> /dev/null
258 echo "Removing all containers, Policy Agent app and simulators with name prefix 'sdnc_db_container'"
259 docker rm $(docker ps -a -q --filter name=sdnc_db_container) &> /dev/null
260 echo "Removing all containers, Policy Agent app and simulators with name prefix 'cbs'"
261 docker rm $(docker ps -a -q --filter name=polman_cbs) &> /dev/null
262 echo "Removing all containers, Policy Agent app and simulators with name prefix 'consul'"
263 docker rm $(docker ps -a -q --filter name=polman_consul) &> /dev/null
264 echo "Removing unused docker networks with substring 'nonrtric' in network name"
265 docker network rm $(docker network ls -q --filter name=nonrtric)
269 start_policy_agent() {
273 if [ $START_ARG == "local" ] || [ $START_ARG == "remote" ]; then
274 __start_policy_agent_image $appname
278 __start_policy_agent_image() {
281 localport=$POLICY_AGENT_PORT
283 echo "Creating docker network $DOCKER_SIM_NWNAME, if needed"
285 docker network ls| grep $DOCKER_SIM_NWNAME > /dev/null || docker network create $DOCKER_SIM_NWNAME
287 echo "Starting Policy Agent: " $appname " with ports mapped to " $localport " in docker network "$DOCKER_SIM_NWNAME
288 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
289 #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
294 if [ $(docker inspect --format '{{ .State.Running }}' $appname) ]
296 echo " Image: $(docker inspect --format '{{ .Config.Image }}' ${appname})"
297 echo "Policy Agent container ${appname} running"
304 if ! [ $pa_started ]; then
305 echo "Policy Agent container ${appname} could not be started"
310 echo "Waiting for Policy Agent ${appname} service status..."
312 result="$(__do_curl http://127.0.0.1:${localport}/status)"
313 if [ $? -eq 0 ]; then
314 echo "Policy Agent ${appname} responds to service status: " $result
315 echo "Policy Agent is alive."
323 if [ "$pa_st" = "false" ]; then
324 echo "Policy Agent ${appname} did not respond to service status"
329 check_policy_agent_logs() {
332 tmp=$(docker ps | grep $appname)
333 if ! [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
334 __check_policy_agent_log $appname
339 __check_policy_agent_log() {
340 echo "Checking $1 log $POLICY_AGENT_LOGPATH for WARNINGs and ERRORs"
341 foundentries=$(docker exec -it $1 grep WARN /var/log/policy-agent/application.log | wc -l)
343 echo " Problem to search $1 log $POLICY_AGENT_LOGPATH"
345 if [ $foundentries -eq 0 ]; then
346 echo " No WARN entries found in $1 log $POLICY_AGENT_LOGPATH"
348 echo -e " Found \033[1m"$foundentries"\033[0m WARN entries in $1 log $POLICY_AGENT_LOGPATH"
351 foundentries=$(docker exec -it $1 grep ERR $POLICY_AGENT_LOGPATH | wc -l)
353 echo " Problem to search $1 log $POLICY_AGENT_LOGPATH"
355 if [ $foundentries -eq 0 ]; then
356 echo " No ERR entries found in $1 log $POLICY_AGENT_LOGPATH"
358 echo -e " Found \033[1m"$foundentries"\033[0m ERR entries in $1 log $POLICY_AGENT_LOGPATH"
365 __print_err "need one arg, <file-prefix>"
368 echo "Storing all container logs and Policy Agent app log using prefix: "$1
370 docker logs polman_consul > $TESTLOGS/$ATC/$1_consul.log 2>&1
371 docker logs polman_cbs > $TESTLOGS/$ATC/$1_cbs.log 2>&1
375 res=$(curl -skw "%{http_code}" $1)
376 http_code="${res:${#res}-3}"
377 if [ ${#res} -eq 3 ]; then
378 echo "<no-response-from-server>"
381 if [ $http_code -lt 200 ] && [ $http_code -gt 299]; then
382 echo "<not found, resp:${http_code}>"
385 if [ $# -eq 2 ]; then
386 echo "${res:0:${#res}-3}" | xargs
388 echo "${res:0:${#res}-3}"