CSIT Support for ServiceLevel PNF Software Upgrade
[integration/csit.git] / plans / usecases-pnf-sw-upgrade / pnf-sw-upgrade / sorch / config / populate-aai-simulator.sh
1 #!/bin/bash
2 #
3 # ============LICENSE_START=======================================================
4 #  Copyright (C) 2019 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 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
20 #
21
22 # @author Gareth Roper (gareth.roper@est.tech)
23 # @auther Waqas Ikram (waqas.ikram@est.tech)
24
25 SCRIPT_NAME=$(basename $0)
26 SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
27 WAIT_FOR_SCRIPT=$SCRIPT_HOME/wait-for.sh
28
29 current_timestamp()
30 {
31  date +"%Y-%m-%d %H:%M:%S"
32 }
33
34 populate_aai_simulator()
35 {
36  $WAIT_FOR_SCRIPT -t "$TIMEOUT_IN_SECONDS" -h "$AAI_SIMULATOR_HOST" -p "$AAI_SIMULATOR_PORT"
37
38  if [ $?  -eq 0 ]
39  then
40      echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is Running."
41  else
42      echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator could not be found. Exiting..."
43      exit 1
44  fi
45
46  BASE_URL="https://$AAI_SIMULATOR_HOST:$AAI_SIMULATOR_PORT/aai/v15"
47  BASIC_AUTHORIZATION_HEADER="Authorization: Basic YWFpOmFhaS5vbmFwLm9yZzpkZW1vMTIzNDU2IQ=="
48  APPICATION_JSON="application/json"
49  ACCEPT_HEADER="Accept: $APPICATION_JSON"
50  CONTENT_TYPE_HEADER="Content-Type: $APPICATION_JSON"
51  CURL_COMMAND="curl -k -H $BASIC_AUTHORIZATION_HEADER -H $ACCEPT_HEADER -H $CONTENT_TYPE_HEADER"
52
53  AAI_SIMULATOR_DATA_DIR=$SCRIPT_HOME/aai-simulator-populate-data
54  CUSTOMER_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/customer.json
55  PROJECT_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/project.json
56  OWNING_ENTITY_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/owning-entity.json
57  LINE_OF_BUSINESS_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/line-of-business.json
58  PLATFORM_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/platform.json
59  CLOUD_REGION_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/cloud-region.json
60  TENANT_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/tenant.json
61  ESR_VNFM_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/esr-vnfm.json
62  ESR_SYSTEM_INFO_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/esr-system-info.json
63  CLOUD_ESR_SYSTEM_INFO_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/cloud-esr-system-info.json
64  PNF_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/pnf.json
65  PNF2_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/pnf2.json
66  SERVICE_INSTANCE_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/service-instance-aai.json
67  STATUS_CODE_ACCEPTED="202"
68
69  echo "$SCRIPT_NAME $(current_timestamp): checking health of AAI Simulator"
70  response=$(curl -k $BASE_URL/healthcheck)
71
72  if [[ "$response" -ne "healthy" ]] ; then
73        echo "$SCRIPT_NAME $(current_timestamp) ERROR: AAI Simulator health check failed. Response: $response"
74        exit 1
75  fi
76
77  echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is healthy"
78
79  echo "$SCRIPT_NAME $(current_timestamp): Populating AAI Simulator"
80
81  echo "$SCRIPT_NAME $(current_timestamp): Adding Project"
82  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/projects/project/PnfSwUCsitProject -X PUT -d @"$PROJECT_JSON_FILE")
83
84  if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
85      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put project data in AAI Simulator. Status code received: $status_code"
86      exit 1
87  fi
88
89   echo "$SCRIPT_NAME $(current_timestamp): Adding Owning-Entity"
90   status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/owning-entities/owning-entity/f2e1071e-3d47-4a65-94d4-e473ec03326a -X PUT -d @$"$OWNING_ENTITY_JSON_FILE")
91
92   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
93      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put owning entity data in AAI Simulator. Status code received: $status_code"
94      exit 1
95  fi
96
97  echo "$SCRIPT_NAME $(current_timestamp): Adding Line Of Business"
98  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/lines-of-business/line-of-business/PnfSwUCsitLineOfBusiness -X PUT -d @$"$LINE_OF_BUSINESS_JSON_FILE")
99
100  if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
101      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put line of business data in AAI Simulator. Status code received: $status_code"
102      exit 1
103  fi
104
105  echo "$SCRIPT_NAME $(current_timestamp): Adding Platform"
106  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/platforms/platform/PnfSwUCsitPlatform -X PUT -d @$"$PLATFORM_JSON_FILE")
107
108  if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
109      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put platform data in AAI Simulator. Status code received: $status_code"
110      exit 1
111  fi
112
113  echo "$SCRIPT_NAME $(current_timestamp): Adding Cloud Region"
114  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/PnfSwUCloudRegion -X PUT -d @$"$CLOUD_REGION_JSON_FILE")
115
116   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
117      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put Cloud Region data in AAI Simulator. Status code received: $status_code"
118      exit 1
119  fi
120
121  echo "$SCRIPT_NAME $(current_timestamp): Adding Tenant"
122   status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/PnfSwUCloudRegion/tenants/tenant/693c7729b2364a26a3ca602e6f66187d -X PUT -d @$"$TENANT_JSON_FILE")
123
124   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
125      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put Tenant data in AAI Simulator. Status code received: $status_code"
126      exit 1
127  fi
128
129  echo "$SCRIPT_NAME $(current_timestamp): Adding esr-vnfm"
130  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/external-system/esr-vnfm-list/esr-vnfm/c5e99cee-1996-4606-b697-838d51d4e1a3 -X PUT -d @$"$ESR_VNFM_JSON_FILE")
131
132   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
133      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put esr-vnfm data in AAI Simulator. Status code received: $status_code"
134      exit 1
135  fi
136
137   echo "$SCRIPT_NAME $(current_timestamp): Adding esr-system-info"
138  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/external-system/esr-vnfm-list/esr-vnfm/c5e99cee-1996-4606-b697-838d51d4e1a3/esr-system-info-list/esr-system-info/5c067098-f2e3-40f7-a7ba-155e7c61e916 -X PUT -d @$"$ESR_SYSTEM_INFO_JSON_FILE")
139
140   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
141      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put esr-system-info data in AAI Simulator. Status code received: $status_code"
142      exit 1
143  fi
144
145   echo "$SCRIPT_NAME $(current_timestamp): Adding cloud esr-system-info"
146  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/PnfSwUCloudRegion/esr-system-info-list/esr-system-info/e6a0b318-9756-4f11-94e8-919312d6c2bd -X PUT -d @$"$CLOUD_ESR_SYSTEM_INFO_JSON_FILE")
147
148   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
149      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put cloud esr-system-info data in AAI Simulator. Status code received: $status_code"
150      exit 1
151  fi
152
153   echo "$SCRIPT_NAME $(current_timestamp): Adding PNF"
154  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/network/pnfs/pnf/PNFDemo -X PUT -d @$"$PNF_JSON_FILE")
155
156   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
157      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put PNF data in AAI Simulator. Status code received: $status_code"
158      exit 1
159  fi
160
161   echo "$SCRIPT_NAME $(current_timestamp): Adding PNF_2.0"
162  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/network/pnfs/pnf/PNFDemo1 -X PUT -d @$"$PNF2_JSON_FILE")
163
164   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
165      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put PNF data in AAI Simulator. Status code received: $status_code"
166      exit 1
167  fi
168
169   echo "$SCRIPT_NAME $(current_timestamp): Adding ServiceInstance"
170  status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/customers/customer/807c7a02-249c-4db8-9fa9-bee973fe08ce/service-subscriptions/service-subscription/pNF/service-instances/service-instance/cd4decf6-4f27-4775-9561-0e683ed43635 -X PUT -d @$"$SERVICE_INSTANCE_JSON_FILE")
171
172   if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
173      echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put ServiceInstance data in AAI Simulator. Status code received: $status_code"
174      exit 1
175  fi
176
177  echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator Populated Successfully"
178 }
179
180 # main body
181 populate_aai_simulator