269d3cb29d27bbf6ad0102fcca68a132b3761551
[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 cd $CPS_HOME/docker-compose
61
62 curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > docker-compose
63 chmod +x docker-compose
64 docker-compose version
65
66 # start CPS/NCMP, DMI Plugin, and PostgreSQL containers with docker compose
67 docker-compose --profile dmi-service up -d
68
69 ###################### setup sdnc #######################################
70 source $WORKSPACE/plans/cps/sdnc/sdnc_setup.sh
71
72 ###################### setup pnfsim #####################################
73 docker-compose -f $WORKSPACE/plans/cps/pnfsim/docker-compose.yml up -d
74
75 # Allow time for netconf-pnp-simulator & SDNC to come up fully
76 sleep 30s
77
78 ###################### mount pnf-sim as PNFDemo ##########################
79 SDNC_TIME_OUT=250
80 SDNC_INTERVAL=10
81 SDNC_TIME=0
82
83 while [ "$SDNC_TIME" -le "$SDNC_TIME_OUT" ]; do
84
85   # Mount netconf node
86   curl --location --request PUT 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf/node/PNFDemo' \
87   --header 'Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==' \
88   --header 'Content-Type: application/json' \
89   --data-raw '{
90     "node": [
91     {
92       "node-id": "PNFDemo",
93       "netconf-node-topology:protocol": {
94       "name": "TLS"
95       },
96       "netconf-node-topology:host": "'$LOCAL_IP'",
97       "netconf-node-topology:key-based": {
98       "username": "netconf",
99       "key-id": "ODL_private_key_0"
100       },
101       "netconf-node-topology:port": 6512,
102       "netconf-node-topology:tcp-only": false,
103       "netconf-node-topology:max-connection-attempts": 5
104     }
105     ]
106   }'
107
108    # Verify node has been mounted
109
110   RESPONSE=$( curl --location --request GET 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf' --header 'Authorization: basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==')
111
112   if [[ "$RESPONSE" == *"PNFDemo"* ]]; then
113     echo "Node mounted in $SDNC_TIME"
114     break;
115   fi
116
117   sleep $SDNC_INTERVAL
118   SDNC_TIME=$((SDNC_TIME + SDNC_INTERVAL))
119
120 done
121
122 ###################### verify ncmp-cps health ##########################
123
124 check_health $CPS_CORE_HOST:$CPS_CORE_MANAGEMENT_PORT 'cps-ncmp'
125
126 ###################### verify dmi health ##########################
127
128 check_health $DMI_HOST:$DMI_MANAGEMENT_PORT 'dmi-plugin'
129
130 ###################### ROBOT Configurations ##########################
131 # Pass variables required for Robot test suites in ROBOT_VARIABLES
132 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 DMI_CSIT_STUB_HOST:$LOCAL_IP -v DMI_CSIT_STUB_PORT:$DMI_DEMO_STUB_PORT -v CPS_CORE_MANAGEMENT_PORT:$CPS_CORE_MANAGEMENT_PORT -v DATADIR:$WORKSPACE/data --exitonfailure"