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