Chore: Add gerrit maven verify GHA workflow
[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 PNF_SIM_REGISTRY=nexus3.onap.org:10001
43 PNF_SIM_VERSION=1.0.5
44 mv ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml.orig
45 cat ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml.orig | sed -re "s/image: onap\/org.onap.integration.simulators.(.*$)/image: $PNF_SIM_REGISTRY\/onap\/org.onap.integration.simulators.\1:$PNF_SIM_VERSION/"  > ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/docker-compose.yml
46
47 # Remove carriage returns (if any) from netopeer start script
48 mv ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh.orig
49 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
50 chmod 755 ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh
51
52 # generate fresh certificates for netconfserver [INT-2269]
53
54 ./generate_certs.sh "${WORKSPACE}"/archives/pnf-simulator/netconfsimulator/tls
55
56 # Start Netconf Simulator Container with docker-compose and configuration from docker-compose.yml
57 docker-compose -f "${WORKSPACE}"/archives/pnf-simulator/netconfsimulator/docker-compose.yml up -d
58
59 # Add test user in netopeer container
60 sleep 60
61 docker exec netconfsimulator_netopeer_1 useradd --system test
62
63 ############################## SDNC Setup ##############################
64
65 # Copy client certs from netconf simulator to SDNC certs directory
66 mkdir /tmp/keys0
67 cp ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/tls/client.crt /tmp/keys0
68 cp ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/tls/client.key /tmp/keys0
69 cp ${WORKSPACE}/archives/pnf-simulator/netconfsimulator/tls/ca.crt /tmp/keys0/trustedCertificates.crt
70 cwd=$(pwd)
71 cd /tmp
72 if [ ! -d ${SDNC_CERT_PATH} ]
73 then
74     mkdir -p ${SDNC_CERT_PATH}
75 fi
76 chmod -f go+w $SDNC_CERT_PATH
77 cat > $SDNC_CERT_PATH/certs.properties <<-END
78 keys0.zip
79 *****
80 END
81 zip -r $SDNC_CERT_PATH/keys0.zip keys0
82 rm -rf /tmp/keys0
83
84
85 # Export default Networking bridge created on the host machine
86 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
87
88 unset http_proxy https_proxy
89
90 # Append test data to standard data init file to create db init script
91 cat ${WORKSPACE}/../installation/sdnc/src/main/resources/sdnctl.dump ${WORKSPACE}/scripts/csit-data.sql > ${WORKSPACE}/archives/csit-dbinit.sql
92
93 # start SDNC containers with docker compose and configuration from docker-compose.yml
94 docker-compose -f ${SCRIPTS}/docker-compose.yml up -d
95
96
97 # WAIT 5 minutes maximum and check karaf.log for readiness every 10 seconds
98
99 TIME_OUT=300
100 INTERVAL=10
101 TIME=0
102 while [ "$TIME" -lt "$TIME_OUT" ]; do
103
104 docker exec ${SDNC_CONTAINER_NAME} cat /opt/opendaylight/data/log/karaf.log | grep 'warp coils'
105
106   if [ $? == 0 ] ; then
107     echo SDNC karaf started in $TIME seconds
108     break;
109   fi
110
111   echo Sleep $INTERVAL seconds before testing if SDNC is up. Total wait time up until now is $TIME seconds. Timeout is $TIME_OUT seconds
112   sleep $INTERVAL
113   TIME=$(($TIME+$INTERVAL))
114 done
115
116 if [ "$TIME" -ge "$TIME_OUT" ]; then
117    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
118    exit 1;
119 fi
120
121 num_bundles=$(docker exec -i ${SDNC_CONTAINER_NAME} sh -c "echo '' | /opt/opendaylight/current/bin/client bundle:list" | tail -1 | cut -d' ' -f1)
122
123   if [ "$num_bundles" -ge 333 ]; then
124     num_failed_bundles=$(docker exec -i ${SDNC_CONTAINER_NAME} sh -c "echo '' | /opt/opendaylight/current/bin/client bundle:list" | grep -w Failure | wc -l)
125     failed_bundles=$(docker exec -i ${SDNC_CONTAINER_NAME} sh -c "echo '' | /opt/opendaylight/current/bin/client bundle:list" | grep -w Failure)
126     echo There is/are $num_failed_bundles failed bundles out of $num_bundles installed bundles.
127   fi
128
129 if [ "$num_failed_bundles" -ge 1 ]; then
130   echo "The following bundle(s) are in a failed state: "
131   echo "  $failed_bundles"
132 fi
133
134 # Check if certificate installation is done
135 TIME_OUT=300
136 INTERVAL=10
137 TIME=0
138 while [ "$TIME" -lt "$TIME_OUT" ]; do
139
140   docker-compose -f "${SCRIPTS}"/docker-compose.yml logs sdnc | grep 'Everything OK in Certificate Installation'
141
142   if [ $? == 0 ] ; then
143     echo SDNC karaf started in $TIME seconds
144     break;
145   fi
146
147   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
148   sleep $INTERVAL
149   TIME=$(($TIME+$INTERVAL))
150 done
151
152 if [ "$TIME" -ge "$TIME_OUT" ]; then
153    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
154    exit 1;
155 fi
156
157 # Update default Networking bridge IP in mount.json file
158 cp ${REQUEST_DATA_PATH}/mount.xml.tmpl ${REQUEST_DATA_PATH}/mount.xml
159 sed -i "s/pnfaddr/${LOCAL_IP}/g" "${REQUEST_DATA_PATH}"/mount.xml
160
161
162 #########################################################################
163
164 # Export SDNC, AAF-Certservice-Cient, Netconf-Pnp-Simulator Continer Names
165 export REQUEST_DATA_PATH="${REQUEST_DATA_PATH}"
166 export SDNC_CONTAINER_NAME="${SDNC_CONTAINER_NAME}"
167 export CLIENT_CONTAINER_NAME="${CLIENT_CONTAINER_NAME}"
168 export NETCONF_PNP_SIM_CONTAINER_NAME="${NETCONF_PNP_SIM_CONTAINER_NAME}"
169
170 REPO_IP='127.0.0.1'
171 ROBOT_VARIABLES+=" -v REPO_IP:${REPO_IP} "
172 ROBOT_VARIABLES+=" -v SCRIPTS:${SCRIPTS} "
173
174 echo "Finished executing setup for SDNC"
175