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