9e87b041652b38fb2fcad93b60a8583d9c369133
[integration/csit.git] / plans / usecases / config-over-netconf / setup.sh
1 #!/bin/bash
2 #
3 # ============LICENSE_START=======================================================
4 #   Copyright (C) 2019 Nordix Foundation.
5 # ================================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #
18 #  SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
20
21 # @author Rahul Tyagi (rahul.tyagi@est.tech)
22
23
24 SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
25 export PARENT=usecases
26 export SUB_PARENT=config-over-netconf
27 source ${WORKSPACE}/plans/$PARENT/$SUB_PARENT/test.properties
28
29 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
30
31 if [ "$MTU" == "" ]; then
32           export MTU="1450"
33 fi
34
35 # clone integration branch for pnf-simulator
36 mkdir -m 755 -p $WORKSPACE/temp/integration
37 cd $WORKSPACE/temp
38 git clone -b dublin --single-branch --depth=1 http://gerrit.onap.org/r/integration.git integration
39
40 HOST_IP_ADDR=localhost
41
42 # setup sdnc
43
44 cd $SDNC_DOCKER_PATH
45 unset http_proxy https_proxy
46
47 #sed -i "s/DMAAP_TOPIC_ENV=.*/DMAAP_TOPIC_ENV="AUTO"/g" diocker-compose.yml
48 docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
49
50 docker pull $NEXUS_DOCKER_REPO/onap/sdnc-image:$SDNC_IMAGE_TAG
51 docker tag $NEXUS_DOCKER_REPO/onap/sdnc-image:$SDNC_IMAGE_TAG onap/sdnc-image:latest
52
53 docker pull $NEXUS_DOCKER_REPO/onap/sdnc-ansible-server-image:$ANSIBLE_IMAGE_TAG
54 docker tag $NEXUS_DOCKER_REPO/onap/sdnc-ansible-server-image:$ANSIBLE_IMAGE_TAG onap/sdnc-ansible-server-image:latest
55
56 docker pull $NEXUS_DOCKER_REPO/onap/ccsdk-blueprintsprocessor:$BP_IMAGE_TAG
57 docker tag $NEXUS_DOCKER_REPO/onap/ccsdk-blueprintsprocessor:$BP_IMAGE_TAG onap/ccsdk-blueprintsprocessor:latest
58
59 export SDNC_CERT_PATH=${CERT_SUBPATH}
60 #sed -i 's/sdnc_controller_container/sdnc_controller_container\n    volumes: \n      - $SDNC_CERT_PATH:\/opt\/opendaylight\/current\/certs/' docker-compose.yaml
61 # start SDNC containers with docker compose and configuration from docker-compose.yml
62 docker-compose up -d
63
64 # start pnf simulator
65
66 cd $INT_DOCKER_PATH
67
68 ./simulator.sh start&
69
70 # WAIT 10 minutes maximum and test every 5 seconds if SDNC is up using HealthCheck API
71 TIME_OUT=1000
72 INTERVAL=30
73 TIME=0
74 while [ "$TIME" -lt "$TIME_OUT" ]; do
75   response=$(curl --write-out '%{http_code}' --silent --output /dev/null -H "Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==" -X POST -H "X-FromAppId: csit-sdnc" -H "X-TransactionId: csit-sdnc" -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8282/restconf/operations/SLI-API:healthcheck ); echo $response
76
77   if [ "$response" == "200" ]; then
78     echo SDNC started in $TIME seconds
79     break;
80   fi
81
82   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
83   sleep $INTERVAL
84   TIME=$(($TIME+$INTERVAL))
85 done
86
87 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
88 sed -i "s/pnfaddr/$LOCAL_IP/g" $REQUEST_DATA_PATH/mount.xml
89
90
91 if [ "$TIME" -ge "$TIME_OUT" ]; then
92    echo TIME OUT: karaf session not started in $TIME_OUT seconds... Could cause problems for testing activities...
93 fi
94
95 ########################################## blueprintsprocessor setup ##########################################################
96 source $CDS_DOCKER_PATH/cds_setup.sh
97
98 ########## update pnf simulator ip in config deploy request ########
99
100 NETOPEER_CONTAINER=$(docker ps -a -q --filter="name=netopeer")
101 NETOPEER_CONTAINER_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SDNC_CONTAINER)
102 RES_KEY=$(uuidgen -r)
103 sed -i "s/pnfaddr/$LOCAL_IP/g" $REQUEST_DATA_PATH/config-deploy.json
104 sed -i "s/pnfaddr/$LOCAL_IP/g" $REQUEST_DATA_PATH/config-assign.json
105
106 sed -i "s/reskey/$RES_KEY/g" $REQUEST_DATA_PATH/config-deploy.json
107 sed -i "s/reskey/$RES_KEY/g" $REQUEST_DATA_PATH/config-assign.json
108
109 #########################check if server is up gracefully ######################################
110
111 TIME_OUT=1500
112 INTERVAL=60
113 TIME=0
114 while [ "$TIME" -lt "$TIME_OUT" ]; do
115 docker exec sdnc_controller_container rm -f /opt/opendaylight/current/etc/host.key
116 response=$(docker exec sdnc_controller_container /opt/opendaylight/current/bin/client system:start-level)
117 docker exec sdnc_controller_container rm -f /opt/opendaylight/current/etc/host.key
118
119   if [ "$response" == "Level 100" ] ; then
120     echo SDNC karaf started in $TIME seconds
121     break;
122   fi
123
124   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
125   sleep $INTERVAL
126   TIME=$(($TIME+$INTERVAL))
127 done
128
129 if [ "$TIME" -ge "$TIME_OUT" ]; then
130    echo TIME OUT: karaf session not started in $TIME_OUT seconds... Could cause problems for testing activities...
131 fi
132
133 response=$(docker exec sdnc_controller_container /opt/opendaylight/current/bin/client system:start-level)
134
135   if [ "$response" == "Level 100" ] ; then
136     num_failed_bundles=$(docker exec sdnc_controller_container /opt/opendaylight/current/bin/client bundle:list | grep Failure | wc -l)
137     failed_bundles=$(docker exec sdnc_controller_container /opt/opendaylight/current/bin/client bundle:list | grep Failure)
138     echo There is/are $num_failed_bundles failed bundles out of $num_bundles installed bundles.
139   fi
140
141 if [ "$num_failed_bundles" -ge 1 ]; then
142   echo "The following bundle(s) are in a failed state: "
143   echo "  $failed_bundles"
144 fi
145
146
147 # Sleep additional 3 minutes (180 secs) to give application time to finish
148
149 sleep 150
150
151 # Pass any variables required by Robot test suites in ROBOT_VARIABLES
152
153 ROBOT_VARIABLES="-v SCRIPTS:${SCRIPTS}"