Merge "CM SUBSCRIPTION: add new subscription for non existing xpath"
[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'/actuator/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 ###################### verify ncmp-cps health ##########################
76
77 check_health $CPS_CORE_HOST:$CPS_CORE_PORT 'cps-ncmp'
78
79 ###################### verify dmi health ##########################
80
81 check_health $DMI_HOST:$DMI_PORT 'dmi-plugin'
82
83 ###################### ROBOT Configurations ##########################
84 # Pass variables required for Robot test suites in ROBOT_VARIABLES
85 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 DMI_AUTH_ENABLED:$DMI_AUTH_ENABLED -v DATADIR_CPS_CORE:$WORKSPACE/data/cps-core -v DATADIR_NCMP:$WORKSPACE/data/ncmp -v DATADIR_SUBS_NOTIFICATION:$WORKSPACE/data/subscription-notification --exitonfailure"