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