Step 5 : Release docker artifacts cps-2.0.1
[cps.git] / csit / plans / cps / 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) 2017 AT&T Intellectual Property
18 # Modifications copyright (c) 2020-2021 Samsung Electronics Co., Ltd.
19 # Modifications Copyright (C) 2021 Pantheon.tech
20 # Modifications Copyright (C) 2021 Bell Canada.
21 # Modifications Copyright (C) 2021 Nordix Foundation.
22 #
23 # Branched from ccsdk/distribution to this repository Feb 23, 2021
24 #
25
26 # Copy docker-compose.yml and application.yml to archives
27 mkdir -p $WORKSPACE/archives/docker-compose
28 cp $WORKSPACE/../docker-compose/*.yml $WORKSPACE/archives/docker-compose
29 cd $WORKSPACE/archives/docker-compose
30
31 # Set env variables for docker compose
32 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
33 export DMI_SERVICE_URL=http://$LOCAL_IP:8783
34 export DB_HOST=$LOCAL_IP
35 export SDNC_HOST=$LOCAL_IP
36 export CPS_CORE_HOST=$LOCAL_IP
37 export DB_USERNAME=cps
38 export DB_PASSWORD=cps
39 # Use latest image version
40 export VERSION=latest
41
42 # download docker-compose of a required version (1.25.0 supports configuration of version 3.7)
43 curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > docker-compose
44 chmod +x docker-compose
45
46 # start CPS and PostgreSQL containers with docker compose
47 docker network create test_network
48 ./docker-compose up -d
49
50 ###################### setup sdnc ############################
51 source $WORKSPACE/plans/cps/sdnc/sdnc_setup.sh
52
53 ###################### setup pnfsim ##########################
54 docker-compose -f $WORKSPACE/plans/cps/pnfsim/docker-compose.yml up -d
55
56 # Allow time for netconf-pnp-simulator & SDNC to come up fully
57 sleep 30s
58
59 SDNC_TIME_OUT=250
60 SDNC_INTERVAL=10
61 SDNC_TIME=0
62
63 while [ "$SDNC_TIME" -le "$SDNC_TIME_OUT" ]; do
64
65         # Mount netconf node
66
67         curl --location --request PUT 'http://'"$LOCAL_IP"':8282/restconf/config/network-topology:network-topology/topology/topology-netconf/node/PNFDemo' \
68         --header 'Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==' \
69         --header 'Content-Type: application/json' \
70         --data-raw '{
71           "node": [
72                 {
73                   "node-id": "PNFDemo",
74                   "netconf-node-topology:protocol": {
75                         "name": "TLS"
76                   },
77                   "netconf-node-topology:host": '"$LOCAL_IP"',
78                   "netconf-node-topology:key-based": {
79                         "username": "netconf",
80                         "key-id": "ODL_private_key_0"
81                   },
82                   "netconf-node-topology:port": 6512,
83                   "netconf-node-topology:tcp-only": false,
84                   "netconf-node-topology:max-connection-attempts": 5
85                 }
86           ]
87          }'
88
89         # Verify node has been mounted
90
91         RESPONSE=$( curl --location --request GET 'http://'"$LOCAL_IP"':8282/restconf/config/network-topology:network-topology/topology/topology-netconf' --header 'Authorization: basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==')
92
93           if [[ "$RESPONSE" == *"PNFDemo"* ]]; then
94             echo "Node mounted in $SDNC_TIME"
95                   break;
96           fi
97
98          sleep $SDNC_INTERVAL
99          SDNC_TIME=$((SDNC_TIME + SDNC_INTERVAL))
100
101 done
102
103 # Validate CPS service initialization completed via periodic log checking for line like below:
104 # org.onap.cps.Application ... Started Application in X.XXX seconds
105
106 TIME_OUT=300
107 INTERVAL=5
108 TIME=0
109
110 while [ "$TIME" -le "$TIME_OUT" ]; do
111   LOG_FOUND=$( ./docker-compose logs --tail="all" | grep "org.onap.cps.Application" | egrep -c "Started Application in" )
112
113   if [ "$LOG_FOUND" -gt 0 ]; then
114     echo "CPS Service started"
115     break;
116   fi
117
118   echo "Sleep $INTERVAL seconds before next check for CPS initialization (waiting $TIME seconds; timeout is $TIME_OUT seconds)"
119   sleep $INTERVAL
120   TIME=$((TIME + INTERVAL))
121 done
122
123 if [ "$TIME" -gt "$TIME_OUT" ]; then
124    echo "TIME OUT: CPS Service wasn't able to start in $TIME_OUT seconds, setup failed."
125    exit 1;
126 fi
127
128 # Pass variables required for Robot test suites in ROBOT_VARIABLES
129 ROBOT_VARIABLES="-v CPS_HOST:$LOCAL_IP -v CPS_PORT:8883 -v DMI_HOST:$LOCAL_IP -v DMI_PORT:8783 -v MANAGEMENT_PORT:8887 -v DATADIR:$WORKSPACE/data"