a2020aee346cab9967bb01ce1500acdff1ab4258
[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 # Create temp directory to bind with docker containers
33 mkdir -m 755 -p "${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/certs
34 mkdir -m 755 -p "${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/cert-data
35
36 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
37
38 if [ "$MTU" == "" ]; then
39   export MTU="1450"
40 fi
41
42 # Export default Networking bridge created on the host machine
43 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
44
45 # Prepare enviroment
46 echo "Uninstall docker-py and reinstall docker."
47 pip uninstall -y docker-py
48 pip uninstall -y docker
49 pip install -U docker==2.7.0
50
51 # Reinstall pyOpenSSL library
52 echo "Reinstall pyOpenSSL library."
53 pip uninstall pyopenssl -y
54 pip install pyopenssl==17.5.0
55
56 # Install PYJKS for .jks files management
57 pip install pyjks
58
59 # Disable Proxy - for local run
60 unset http_proxy https_proxy
61
62 # Export AAF Certservice config path
63 export AAF_INITIAL_CERTS
64 export EJBCA_CERTPROFILE_PATH
65 export AAF_CERTSERVICE_CONFIG_PATH
66 export AAF_CERTSERVICE_SCRIPTS_PATH
67 export CERT_PROFILE=${EJBCA_CERTPROFILE_PATH}
68 export SCRIPTS_PATH=${AAF_CERTSERVICE_SCRIPTS_PATH}
69 export CONFIGURATION_PATH=${AAF_CERTSERVICE_CONFIG_PATH}
70
71 # Generate Keystores, Truststores, Certificates and Keys
72 make all -C ./certs/
73
74 cp "${WORKSPACE}"/plans/sdnc/sdnc_netconf_tls_post_deploy/certs/root.crt "${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/certs/root.crt
75 openssl pkcs12 -in "${WORKSPACE}"/plans/sdnc/sdnc_netconf_tls_post_deploy/certs/certServiceServer-keystore.p12 -clcerts -nokeys -password pass:secret | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >"${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/certs/certServiceServer.crt
76 openssl pkcs12 -in "${WORKSPACE}"/plans/sdnc/sdnc_netconf_tls_post_deploy/certs/certServiceServer-keystore.p12 -nocerts -nodes -password pass:secret | sed -ne '/-BEGIN PRIVATE KEY-/,/-END PRIVATE KEY-/p' >"${WORKSPACE}"/tests/sdnc/sdnc_netconf_tls_post_deploy/certs/certServiceServer.key
77
78 echo "Generated KeyStores, Server Certificate and Key"
79
80 # Start EJBCA, AAF-CertService Containers with docker-compose and configuration from docker-compose.yml
81 docker-compose -f "${SCRIPTS}"/sdnc/certservice/docker-compose.yml up -d
82
83 # Check if AAF-Certservice Service is healthy and ready
84 AAFCERT_IP='none'
85 for i in {1..9}; do
86   AAFCERT_IP=$(get-instance-ip.sh aaf-cert-service)
87   RESP_CODE=$(curl -s https://localhost:8443/actuator/health --cacert ./certs/root.crt --cert-type p12 --cert ./certs/certServiceServer-keystore.p12 --pass secret |
88     python2 -c 'import json,sys;obj=json.load(sys.stdin);print obj["status"]')
89   if [[ "${RESP_CODE}" == "UP" ]]; then
90     echo "AAF Cert Service is Ready."
91     export AAFCERT_IP=${AAFCERT_IP}
92     docker exec aafcert-ejbca /opt/primekey/scripts/ejbca-configuration.sh
93     break
94   fi
95   echo "Waiting for AAF Cert Service to Start Up..."
96   sleep 2m
97 done
98
99 if [[ "${AAFCERT_IP}" == "none" || "${AAFCERT_IP}" == '' ||  "${RESP_CODE}" != "UP" ]]; then
100   echo "AAF CertService not started Could cause problems for testing activities...!"
101 fi
102
103 ############################## SDNC Setup ##############################
104
105 # Export Mariadb, SDNC tmp, cert directory path
106 export SDNC_CERT_PATH=${SDNC_CERT_PATH}
107
108 docker pull "${NEXUS_DOCKER_REPO}"/onap/sdnc-image:"${SDNC_IMAGE_TAG}"
109 docker tag "${NEXUS_DOCKER_REPO}"/onap/sdnc-image:"${SDNC_IMAGE_TAG}" onap/sdnc-image:latest
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 2m
124 done
125
126 if [[ "${SDNC_IP}" == 'none' || "${SDNC_IP}" == '' || "${RESP_CODE}" != '200' ]]; then
127   echo "SDNC Service not started Could cause problems for testing activities...!"
128 fi
129
130 # Check if SDNC-ODL Karaf Session started
131 for i in {1..15}; do
132   EXEC_RESP=$(docker exec -it sdnc /opt/opendaylight/current/bin/client system:start-level)
133   if grep -q 'Level 100' <<<"${EXEC_RESP}"; then
134     echo "SDNC-ODL Karaf Session Started."
135     break
136   fi
137   echo "Waiting for SDNC-ODL Karaf Session to Start Up..."
138   sleep 2m
139 done
140
141 if ! grep -q 'Level 100' <<<"${EXEC_RESP}"; then
142   echo "SDNC-ODL Karaf Session not Started, Could cause problems for testing activities...!"
143 fi
144
145 echo "Sleeping 5 minutes"
146 sleep 5m
147
148 ###################### Netconf-PNP-Simulator Setup ######################
149
150 # Export netconf-pnp simulator conf path
151 export NETCONF_CONFIG_PATH=${NETCONF_CONFIG_PATH}
152
153 # Start Netconf-Pnp-Simulator Container with docker-compose and configuration from docker-compose.yml
154 docker-compose -f "${SCRIPTS}"/sdnc/netconf-pnp-simulator/docker-compose.yml up -d
155
156 # Update default Networking bridge IP in mount.json file
157 sed -i "s/pnfaddr/${LOCAL_IP}/g" "${REQUEST_DATA_PATH}"/mount.xml
158
159 #########################################################################
160
161 echo "Sleeping additional for 3 minutes to give application time to finish"
162 sleep 3m
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-Netconf-TLS-Post-Deploy"