6ef4c9a1fe7cf3a70cc9215b6ea6254a73e82fcb
[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 check_health()
27 {
28   TIME_OUT=120
29   INTERVAL=5
30   TICKER=0
31
32   while [ "$TICKER" -le "$TIME_OUT" ]; do
33
34     RESPONSE=$(curl --location --request GET 'http://'$1'/manage/health/readiness')
35
36     if [[ "$RESPONSE" == *"UP"* ]]; then
37       echo "$2 started in $TICKER"
38       break;
39     fi
40
41     sleep $INTERVAL
42     TICKER=$((TICKER + INTERVAL))
43
44   done
45
46   if [ "$TICKER" -ge "$TIME_OUT" ]; then
47     echo TIME OUT: $2 session not started in $TIME_OUT seconds... Could cause problems for testing activities...
48   fi
49 }
50
51 ###################### setup env ############################
52 # Set env variables for docker compose
53 export LOCAL_IP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
54
55 source $WORKSPACE/plans/cps/test.properties
56 export $(cut -d= -f1 $WORKSPACE/plans/cps/test.properties)
57
58 ###################### setup cps-ncmp ############################
59 mkdir -p $WORKSPACE/archives/dc-cps
60 cp $WORKSPACE/../docker-compose/*.yml $WORKSPACE/archives/dc-cps
61 cd $WORKSPACE/archives/dc-cps
62
63 # download docker-compose of a required version (1.25.0 supports configuration of version 3.7)
64 curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > docker-compose
65 chmod +x docker-compose
66
67 # start CPS and PostgreSQL containers with docker compose
68 ./docker-compose up -d
69
70 ###################### setup onap-dmi-plugin ############################
71
72 cd $WORKSPACE/archives
73 git clone "https://gerrit.onap.org/r/cps/ncmp-dmi-plugin"
74 mkdir -p $WORKSPACE/archives/dc-dmi
75 cat $WORKSPACE/archives/ncmp-dmi-plugin/docker-compose/docker-compose.yml
76 cp $WORKSPACE/archives/ncmp-dmi-plugin/docker-compose/*.yml $WORKSPACE/archives/dc-dmi
77 cd $WORKSPACE/archives/dc-dmi
78 # copy docker-compose (downloaded already for cps)
79 cp $WORKSPACE/archives/dc-cps/docker-compose .
80 chmod +x docker-compose
81 ./docker-compose up -d
82
83 ###################### setup sdnc #######################################
84 source $WORKSPACE/plans/cps/sdnc/sdnc_setup.sh
85
86 ###################### setup pnfsim #####################################
87 docker-compose -f $WORKSPACE/plans/cps/pnfsim/docker-compose.yml up -d
88
89 # Allow time for netconf-pnp-simulator & SDNC to come up fully
90 sleep 30s
91
92 ###################### mount pnf-sim as PNFDemo ##########################
93 SDNC_TIME_OUT=250
94 SDNC_INTERVAL=10
95 SDNC_TIME=0
96
97 while [ "$SDNC_TIME" -le "$SDNC_TIME_OUT" ]; do
98
99   # Mount netconf node
100   curl --location --request PUT 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf/node/PNFDemo' \
101   --header 'Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==' \
102   --header 'Content-Type: application/json' \
103   --data-raw '{
104     "node": [
105     {
106       "node-id": "PNFDemo",
107       "netconf-node-topology:protocol": {
108       "name": "TLS"
109       },
110       "netconf-node-topology:host": "'$LOCAL_IP'",
111       "netconf-node-topology:key-based": {
112       "username": "netconf",
113       "key-id": "ODL_private_key_0"
114       },
115       "netconf-node-topology:port": 6512,
116       "netconf-node-topology:tcp-only": false,
117       "netconf-node-topology:max-connection-attempts": 5
118     }
119     ]
120   }'
121
122    # Verify node has been mounted
123
124   RESPONSE=$( curl --location --request GET 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf' --header 'Authorization: basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==')
125
126   if [[ "$RESPONSE" == *"PNFDemo"* ]]; then
127     echo "Node mounted in $SDNC_TIME"
128     break;
129   fi
130
131   sleep $SDNC_INTERVAL
132   SDNC_TIME=$((SDNC_TIME + SDNC_INTERVAL))
133
134 done
135
136 ###################### verify ncmp-cps health ##########################
137
138 check_health $CPS_CORE_HOST:$CPS_CORE_MANAGEMENT_PORT 'cps-ncmp'
139
140 ###################### verify dmi health ##########################
141
142 check_health $DMI_HOST:$DMI_MANAGEMENT_PORT 'dmi-plugin'
143
144 ###################### ROBOT Configurations ##########################
145 # Pass variables required for Robot test suites in ROBOT_VARIABLES
146 ROBOT_VARIABLES="-v CPS_CORE_HOST:$CPS_CORE_HOST -v CPS_CORE_PORT:$CPS_CORE_PORT -v DMI_HOST:$LOCAL_IP -v DMI_PORT:$DMI_PORT -v CPS_CORE_MANAGEMENT_PORT:$CPS_CORE_MANAGEMENT_PORT -v DATADIR:$WORKSPACE/data --exitonfailure"