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