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