9ea667076945ceb3eb43832872683103b15a7aff
[cps.git] / csit / plans / cps / sdnc / check_sdnc_mount_node.sh
1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2023 Nordix Foundation
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
16
17 # WAIT 10 minutes maximum and test every 30 seconds if SDNC is up using HealthCheck API
18 TIME_OUT=600
19 INTERVAL=30
20 TIME=0
21 while [ "$TIME" -lt "$TIME_OUT" ]; do
22   response=$(curl --write-out '%{http_code}' --silent --output /dev/null -H "Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==" -X POST -H "X-FromAppId: csit-sdnc" -H "X-TransactionId: csit-sdnc" -H "Accept: application/json" -H "Content-Type: application/json" http://$SDNC_HOST:$SDNC_PORT/restconf/operations/SLI-API:healthcheck );
23   echo $response
24
25   if [ "$response" == "200" ]; then
26     echo SDNC started in $TIME seconds
27     break;
28   fi
29
30   echo Sleep: $INTERVAL seconds before testing if SDNC is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
31   sleep $INTERVAL
32   TIME=$(($TIME+$INTERVAL))
33 done
34
35 if [ "$TIME" -ge "$TIME_OUT" ]; then
36    echo TIME OUT: karaf session not started in $TIME_OUT seconds... Could cause problems for testing activities...
37 fi
38
39 ###################### mount pnf-sim as PNFDemo ##########################
40 SDNC_TIME_OUT=250
41 SDNC_INTERVAL=10
42 SDNC_TIME=0
43
44 while [ "$SDNC_TIME" -le "$SDNC_TIME_OUT" ]; do
45
46   # Mount netconf node
47   curl --location --request PUT 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf/node/PNFDemo' \
48   --header 'Authorization: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==' \
49   --header 'Content-Type: application/json' \
50   --data-raw '{
51     "node": [
52     {
53       "node-id": "PNFDemo",
54       "netconf-node-topology:protocol": {
55       "name": "TLS"
56       },
57       "netconf-node-topology:host": "'$LOCAL_IP'",
58       "netconf-node-topology:key-based": {
59       "username": "netconf",
60       "key-id": "ODL_private_key_0"
61       },
62       "netconf-node-topology:port": 6512,
63       "netconf-node-topology:tcp-only": false,
64       "netconf-node-topology:max-connection-attempts": 5
65     }
66     ]
67   }'
68
69    # Verify node has been mounted
70
71   RESPONSE=$( curl --location --request GET 'http://'$SDNC_HOST:$SDNC_PORT'/restconf/config/network-topology:network-topology/topology/topology-netconf' --header 'Authorization: basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==')
72
73   if [[ "$RESPONSE" == *"PNFDemo"* ]]; then
74     echo "Node mounted in $SDNC_TIME"
75     sleep 10
76     break;
77   fi
78
79   sleep $SDNC_INTERVAL
80   SDNC_TIME=$((SDNC_TIME + SDNC_INTERVAL))
81
82 done