Async request response NCMP -> Client
[cps.git] / csit / plans / cps / setup.sh
1 #!/bin/bash
2 #
3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modifications Copyright (C) 2022 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 # Modifications copyright (c) 2017 AT&T Intellectual Property
19 # Modifications copyright (c) 2020-2021 Samsung Electronics Co., Ltd.
20 # Modifications Copyright (C) 2021 Pantheon.tech
21 # Modifications Copyright (C) 2021 Bell Canada.
22 # Modifications Copyright (C) 2021 Nordix Foundation.
23 #
24 # Branched from ccsdk/distribution to this repository Feb 23, 2021
25 #
26
27 check_health()
28 {
29   TIME_OUT=120
30   INTERVAL=5
31   TICKER=0
32
33   while [ "$TICKER" -le "$TIME_OUT" ]; do
34
35     RESPONSE=$(curl --location --request GET 'http://'$1'/manage/health/readiness')
36
37     if [[ "$RESPONSE" == *"UP"* ]]; then
38       echo "$2 started in $TICKER"
39       break;
40     fi
41
42     sleep $INTERVAL
43     TICKER=$((TICKER + INTERVAL))
44
45   done
46
47   if [ "$TICKER" -ge "$TIME_OUT" ]; then
48     echo TIME OUT: $2 session not started in $TIME_OUT seconds... Could cause problems for testing activities...
49   fi
50 }
51
52 ###################### setup env ############################
53 # Set env variables for docker compose
54 export LOCAL_IP=$((ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+') || hostname -I | awk '{print $1}')
55
56 source $WORKSPACE/plans/cps/test.properties
57 export $(cut -d= -f1 $WORKSPACE/plans/cps/test.properties)
58
59 ###################### setup cps-ncmp ############################
60 mkdir -p $WORKSPACE/archives/dc-cps
61 cp $WORKSPACE/../docker-compose/*.yml $WORKSPACE/archives/dc-cps
62 cd $WORKSPACE/archives/dc-cps
63
64 # download docker-compose of a required version (1.25.0 supports configuration of version 3.7)
65 curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > docker-compose
66 chmod +x docker-compose
67
68 # start CPS/NCMP, DMI, and PostgreSQL containers with docker compose
69 ./docker-compose up -d
70
71 ###################### setup sdnc #######################################
72 source $WORKSPACE/plans/cps/sdnc/sdnc_setup.sh
73
74 ###################### setup pnfsim #####################################
75 docker-compose -f $WORKSPACE/plans/cps/pnfsim/docker-compose.yml up -d
76
77 # Allow time for netconf-pnp-simulator & SDNC to come up fully
78 sleep 30s
79
80 ###################### mount pnf-sim as PNFDemo ##########################
81 SDNC_TIME_OUT=250
82 SDNC_INTERVAL=10
83 SDNC_TIME=0
84
85 while [ "$SDNC_TIME" -le "$SDNC_TIME_OUT" ]; do
86
87   # Mount netconf node
88   curl --location --request PUT 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf/node/PNFDemo' \
89   --header 'Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==' \
90   --header 'Content-Type: application/json' \
91   --data-raw '{
92     "node": [
93     {
94       "node-id": "PNFDemo",
95       "netconf-node-topology:protocol": {
96       "name": "TLS"
97       },
98       "netconf-node-topology:host": "'$LOCAL_IP'",
99       "netconf-node-topology:key-based": {
100       "username": "netconf",
101       "key-id": "ODL_private_key_0"
102       },
103       "netconf-node-topology:port": 6512,
104       "netconf-node-topology:tcp-only": false,
105       "netconf-node-topology:max-connection-attempts": 5
106     }
107     ]
108   }'
109
110    # Verify node has been mounted
111
112   RESPONSE=$( curl --location --request GET 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf' --header 'Authorization: basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==')
113
114   if [[ "$RESPONSE" == *"PNFDemo"* ]]; then
115     echo "Node mounted in $SDNC_TIME"
116     break;
117   fi
118
119   sleep $SDNC_INTERVAL
120   SDNC_TIME=$((SDNC_TIME + SDNC_INTERVAL))
121
122 done
123
124 ###################### verify ncmp-cps health ##########################
125
126 check_health $CPS_CORE_HOST:$CPS_CORE_MANAGEMENT_PORT 'cps-ncmp'
127
128 ###################### verify dmi health ##########################
129
130 check_health $DMI_HOST:$DMI_MANAGEMENT_PORT 'dmi-plugin'
131
132 ###################### ROBOT Configurations ##########################
133 # Pass variables required for Robot test suites in ROBOT_VARIABLES
134 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"