[CSIT] Fix SDC CSIT Run Errors/Warnings & Path Correction
[integration/csit.git] / plans / sdnc / sdnc_netconf_tls_post_deploy / setup.sh
1 #!/bin/bash
2 #
3 # ============LICENSE_START=======================================================
4 #   Copyright (C) 2020 Nordix Foundation.
5 #   Modification copyright (C) 2021 Samsung Electronics, Co., Ltd.
6 # ================================================================================
7 #  Licensed under the Apache License, Version 2.0 (the "License");
8 #  you may not use this file except in compliance with the License.
9 #  You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #  Unless required by applicable law or agreed to in writing, software
14 #  distributed under the License is distributed on an "AS IS" BASIS,
15 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #  See the License for the specific language governing permissions and
17 #  limitations under the License.
18 #
19 #  SPDX-License-Identifier: Apache-2.0
20 # ============LICENSE_END=========================================================
21
22 # @author Ajay Deep Singh (ajay.deep.singh@est.tech)
23
24 # Source SDNC, AAF-CertService, Netconf-Pnp-Simulator config env
25 source "${WORKSPACE}"/plans/sdnc/sdnc_netconf_tls_post_deploy/sdnc-csit.env
26
27 chmod +x "${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/libraries/config.sh
28 chmod +x "${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/libraries/config_tls.sh
29
30 # Export temp directory
31 export TEMP_DIR_PATH=${TEMP_DIR_PATH}
32
33
34 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
35
36 if [ "$MTU" == "" ]; then
37   export MTU="1450"
38 fi
39
40 # Export default Networking bridge created on the host machine
41 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
42
43 # Prepare enviroment
44 echo "Uninstall docker-py and reinstall docker."
45 pip uninstall -y docker-py
46 pip uninstall -y docker
47 pip install -U docker==2.7.0
48
49 # Reinstall pyOpenSSL library
50 echo "Reinstall pyOpenSSL library."
51 pip uninstall pyopenssl -y
52 pip install pyopenssl==17.5.0
53
54 # Install PYJKS for .jks files management
55 pip install pyjks
56
57 # Disable Proxy - for local run
58 unset http_proxy https_proxy
59
60 ###################### Netconf Simulator Setup ######################
61
62 # Get integration/simulators
63 if [ -d ${SCRIPTS}/sdnc/pnf-simulator ]
64 then
65     rm -rf ${SCRIPTS}/sdnc/pnf-simulator
66 fi
67 mkdir ${SCRIPTS}/sdnc/pnf-simulator
68 git clone "https://gerrit.onap.org/r/integration/simulators/pnf-simulator" ${SCRIPTS}/sdnc/pnf-simulator
69
70 # Fix docker-compose to add nexus repo for onap dockers 
71 mv ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/docker-compose.yml ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/docker-compose.yml.orig
72 cat ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/docker-compose.yml.orig | sed -e "s/image: onap/image: nexus3.onap.org:10001\/onap/" > ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/docker-compose.yml
73
74 # Remove carriage returns (if any) from netopeer start script
75 mv ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh.orig
76 cat ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh.orig | sed -e "s/\r$//g" > ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh
77 chmod 755 ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/netconf/initialize_netopeer.sh
78
79
80 # Start Netconf Simulator Container with docker-compose and configuration from docker-compose.yml
81 docker-compose -f "${SCRIPTS}"/sdnc/pnf-simulator/netconfsimulator/docker-compose.yml up -d
82
83 # Add test user in netopeer container
84 sleep 60
85 docker exec netconfsimulator_netopeer_1 useradd --system test
86
87
88 ############################## SDNC Setup ##############################
89
90 # Copy client certs from netconf simulator to SDNC certs directory
91 mkdir /tmp/keys0
92 cp ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/tls/client.crt /tmp/keys0
93 cp ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/tls/client.key /tmp/keys0
94 cp ${SCRIPTS}/sdnc/pnf-simulator/netconfsimulator/tls/ca.crt /tmp/keys0/trustedCertificates.crt
95 cwd=$(pwd)
96 cd /tmp
97 zip -r $SDNC_CERT_PATH/keys0.zip keys0
98 rm -rf /tmp/keys0
99
100 # Export Mariadb, SDNC tmp, cert directory path
101 export SDNC_CERT_PATH=${SDNC_CERT_PATH}
102
103 docker pull "${NEXUS_DOCKER_REPO}"/onap/sdnc-image:"${SDNC_IMAGE_TAG}"
104 docker tag "${NEXUS_DOCKER_REPO}"/onap/sdnc-image:"${SDNC_IMAGE_TAG}" onap/sdnc-image:latest
105
106 # Fix permissions on certs directory to guarantee directory is read/
107 # writable and that files are readable
108 chmod ugo+rwx ${SCRIPTS}/sdnc/sdnc/certs
109 chmod ugo+r ${SCRIPTS}/sdnc/sdnc/certs/*
110
111 # Start Mariadb, SDNC Containers with docker-compose and configuration from docker-compose.yml
112 docker-compose -f "${SCRIPTS}"/sdnc/sdnc/docker-compose.yml up -d
113
114 # Check if SDNC Service is healthy and ready
115 for i in {1..10}; do
116   SDNC_IP=$(get-instance-ip.sh sdnc)
117   RESP_CODE=$(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)
118   if [[ "${RESP_CODE}" == '200' ]]; then
119     echo "SDNC Service is Ready."
120     break
121   fi
122   echo "Waiting for SDNC Service to Start Up..."
123   sleep 30s
124 done
125
126 if [[ "${SDNC_IP}" == 'none' || "${SDNC_IP}" == '' || "${RESP_CODE}" != '200' ]]; then
127   echo "SDNC Service not started, setup failed"
128   exit 1
129 fi
130
131 # Check if SDNC-ODL Karaf Session started
132 TIME_OUT=300
133 INTERVAL=10
134 TIME=0
135 while [ "$TIME" -lt "$TIME_OUT" ]; do
136
137   docker exec sdnc cat /opt/opendaylight/data/log/karaf.log | grep 'warp coils'
138
139   if [ $? == 0 ] ; then
140     echo SDNC karaf started in $TIME seconds
141     break;
142   fi
143
144   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
145   sleep $INTERVAL
146   TIME=$(($TIME+$INTERVAL))
147 done
148
149 if [ "$TIME" -ge "$TIME_OUT" ]; then
150    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
151    exit 1;
152 fi
153
154 # Check if certificate installation is done
155 TIME_OUT=300
156 INTERVAL=10
157 TIME=0
158 while [ "$TIME" -lt "$TIME_OUT" ]; do
159
160   docker-compose -f "${SCRIPTS}"/sdnc/sdnc/docker-compose.yml logs sdnc | grep 'Everything OK in Certificate Installation'
161
162   if [ $? == 0 ] ; then
163     echo SDNC karaf started in $TIME seconds
164     break;
165   fi
166
167   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
168   sleep $INTERVAL
169   TIME=$(($TIME+$INTERVAL))
170 done
171
172 if [ "$TIME" -ge "$TIME_OUT" ]; then
173    echo TIME OUT: karaf session not started in $TIME_OUT seconds, setup failed
174    exit 1;
175 fi
176
177 # Update default Networking bridge IP in mount.json file
178 sed -i "s/pnfaddr/${LOCAL_IP}/g" "${REQUEST_DATA_PATH}"/mount.xml
179
180 #########################################################################
181
182 # Export SDNC, AAF-Certservice-Cient, Netconf-Pnp-Simulator Continer Names
183 export REQUEST_DATA_PATH="${REQUEST_DATA_PATH}"
184 export SDNC_CONTAINER_NAME="${SDNC_CONTAINER_NAME}"
185 export CLIENT_CONTAINER_NAME="${CLIENT_CONTAINER_NAME}"
186 export NETCONF_PNP_SIM_CONTAINER_NAME="${NETCONF_PNP_SIM_CONTAINER_NAME}"
187
188 REPO_IP='127.0.0.1'
189 ROBOT_VARIABLES+=" -v REPO_IP:${REPO_IP} "
190 ROBOT_VARIABLES+=" -v SCRIPTS:${SCRIPTS} "
191
192 echo "Finished executing setup for SDNC-Netconf-TLS-Post-Deploy"