Fix root pom version definition
[sdnc/oam.git] / csit / plans / sdnc / setup.sh
1 #!/bin/bash
2 #
3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # Modifications copyright (c) 2020-2021 Samsung Electronics Co., Ltd.
18 # Modifications copyright (c) 2021 AT&T Intellectual Property
19 #
20
21 # Remove all dangling images and cleanup /w/workspace and /tmp
22 docker image prune -f
23 echo "Remove onap repository artifacts"
24 rm -r /tmp/r/org/onap
25 echo "Remove all target folders from workspace"
26 rm -r $(find /w/workspace -name target)
27
28 ###################### Netconf Simulator Setup ######################
29
30 echo "Clean"
31 sudo apt clean
32
33 # Get integration/simulators
34 if [ -d ${WORKSPACE}/archives/pnf-simulator ]
35 then
36     rm -rf ${WORKSPACE}/archives/pnf-simulator
37 fi
38 mkdir ${WORKSPACE}/archives/pnf-simulator
39 git clone "https://gerrit.onap.org/r/integration/simulators/pnf-simulator" ${WORKSPACE}/archives/pnf-simulator
40
41 # Fix docker-compose to add nexus repo for onap dockers
42 mv ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml.orig
43 cat ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml.orig | sed -e "s/image: onap/image: nexus3.onap.org:10001\/onap/" > ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml
44
45 # Remove carriage returns (if any) from netopeer start script
46 mv ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh.orig
47 cat ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh.orig | sed -e "s/\r$//g" > ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh
48 chmod 755 ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh
49
50
51 # Start Netconf Simulator Container with docker-compose and configuration from docker-compose.yml
52 docker-compose -f "${WORKSPACE}"/archives/pnf-simulator/netconfsimulator/docker-compose.yml up -d
53
54 # Add test user in netopeer container
55 sleep 60
56 docker exec netconfsimulator_netopeer_1 useradd --system test
57
58 ############################## SDNC Setup ##############################
59
60 # Copy client certs from netconf simulator to SDNC certs directory
61 mkdir /tmp/keys0
62 cp ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/tls/client.crt /tmp/keys0
63 cp ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/tls/client.key /tmp/keys0
64 cp ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/tls/ca.crt /tmp/keys0/trustedCertificates.crt
65 cwd=$(pwd)
66 cd /tmp
67 if [ ! -d ${SDNC_CERT_PATH} ]
68 then
69     mkdir -p ${SDNC_CERT_PATH}
70 fi
71 chmod -f go+w $SDNC_CERT_PATH
72 cat > $SDNC_CERT_PATH/certs.properties <<-END
73 keys0.zip
74 *****
75 END
76 zip -r $SDNC_CERT_PATH/keys0.zip keys0
77 rm -rf /tmp/keys0
78
79
80 # Export default Networking bridge created on the host machine
81 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
82
83 unset http_proxy https_proxy
84
85 # Append test data to standard data init file to create db init script
86 cat ${WORKSPACE}/../installation/sdnc/src/main/resources/sdnctl.dump ${WORKSPACE}/scripts/csit-data.sql > ${WORKSPACE}/archives/csit-dbinit.sql
87
88 # start SDNC containers with docker compose and configuration from docker-compose.yml
89 docker-compose -f ${SCRIPTS}/docker-compose.yml up -d
90
91
92 # WAIT 5 minutes maximum and check karaf.log for readiness every 10 seconds
93
94 TIME_OUT=300
95 INTERVAL=10
96 TIME=0
97 while [ "$TIME" -lt "$TIME_OUT" ]; do
98
99 docker exec ${SDNC_CONTAINER_NAME} cat /opt/opendaylight/data/log/karaf.log | grep 'warp coils'
100
101   if [ $? == 0 ] ; then
102     echo SDNC karaf started in $TIME seconds
103     break;
104   fi
105
106   echo Sleep $INTERVAL seconds before testing if SDNC is up. Total wait time up until now is $TIME seconds. Timeout is $TIME_OUT seconds
107   sleep $INTERVAL
108   TIME=$(($TIME+$INTERVAL))
109 done
110
111 if [ "$TIME" -ge "$TIME_OUT" ]; then
112    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
113    exit 1;
114 fi
115
116 num_bundles=$(docker exec -i ${SDNC_CONTAINER_NAME} sh -c "echo '' | /opt/opendaylight/current/bin/client bundle:list" | tail -1 | cut -d' ' -f1)
117
118   if [ "$num_bundles" -ge 333 ]; then
119     num_failed_bundles=$(docker exec -i ${SDNC_CONTAINER_NAME} sh -c "echo '' | /opt/opendaylight/current/bin/client bundle:list" | grep -w Failure | wc -l)
120     failed_bundles=$(docker exec -i ${SDNC_CONTAINER_NAME} sh -c "echo '' | /opt/opendaylight/current/bin/client bundle:list" | grep -w Failure)
121     echo There is/are $num_failed_bundles failed bundles out of $num_bundles installed bundles.
122   fi
123
124 if [ "$num_failed_bundles" -ge 1 ]; then
125   echo "The following bundle(s) are in a failed state: "
126   echo "  $failed_bundles"
127 fi
128
129 # Check if certificate installation is done
130 TIME_OUT=300
131 INTERVAL=10
132 TIME=0
133 while [ "$TIME" -lt "$TIME_OUT" ]; do
134
135   docker-compose -f "${SCRIPTS}"/docker-compose.yml logs sdnc | grep 'Everything OK in Certificate Installation'
136
137   if [ $? == 0 ] ; then
138     echo SDNC karaf started in $TIME seconds
139     break;
140   fi
141
142   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
143   sleep $INTERVAL
144   TIME=$(($TIME+$INTERVAL))
145 done
146
147 if [ "$TIME" -ge "$TIME_OUT" ]; then
148    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
149    exit 1;
150 fi
151
152 # Update default Networking bridge IP in mount.json file
153 cp ${REQUEST_DATA_PATH}/mount.xml.tmpl ${REQUEST_DATA_PATH}/mount.xml
154 sed -i "s/pnfaddr/${LOCAL_IP}/g" "${REQUEST_DATA_PATH}"/mount.xml
155
156
157 #########################################################################
158
159 # Export SDNC, AAF-Certservice-Cient, Netconf-Pnp-Simulator Continer Names
160 export REQUEST_DATA_PATH="${REQUEST_DATA_PATH}"
161 export SDNC_CONTAINER_NAME="${SDNC_CONTAINER_NAME}"
162 export CLIENT_CONTAINER_NAME="${CLIENT_CONTAINER_NAME}"
163 export NETCONF_PNP_SIM_CONTAINER_NAME="${NETCONF_PNP_SIM_CONTAINER_NAME}"
164
165 REPO_IP='127.0.0.1'
166 ROBOT_VARIABLES+=" -v REPO_IP:${REPO_IP} "
167 ROBOT_VARIABLES+=" -v SCRIPTS:${SCRIPTS} "
168
169 echo "Finished executing setup for SDNC"
170