blob: 279912c35fd6439cf389929c33e704865b55f54b [file] [log] [blame]
Muralib149f632017-08-30 09:23:21 +00001#!/usr/bin/env bash
2###############################################################################
3# Copyright 2017 Huawei Technologies Co., Ltd.
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###############################################################################
17SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18echo $SCRIPT_DIR
19
20#CHECK IF MSB_ADDR IS GIVEN IN COMMAND
21if [ -z "$1" ]
22then
23 echo "There is no MSB_ADDR"
24 exit 1
25fi
26MSB_ADDR=$1
27CSAR_NAME=$2
28echo $MSB_ADDR
29echo $CSAR_NAME
30
31# Wait for MSB initialization
32echo Wait for MSB initialization
33for i in {1..20}; do
34 curl -sS -m 1 $MSB_ADDR > /dev/null && break
35 sleep $i
36done
37#MSB initialized
38###########################################
39###########################################
40###########################################
41###########################################
42###########################################
43###########################################
44############UOLOAD PACKAGE to MARKET PLACE######################
45echo
46echo "############## UOLOAD PACKAGE to MARKET PLACE STARTED ##############";
47UploadPackageResponse=$(curl -sS -X POST -H "Content-Type: multipart/form-data;" -F "file=@$CSAR_NAME" http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars)
48if echo "$UploadPackageResponse" | grep -q "\"csarId\""; then
49 echo "UOLOAD PACKAGE TO MARKET PLACE SUCSSS !!!";
50else
51 echo "UploadPackageResponse :$UploadPackageResponse"
52 echo "UOLOAD PACKAGE TO MARKET PLACE FAILED !!!";
53 exit 1;
54fi
55UploadCsarId=$(echo ${UploadPackageResponse:11:36})
56echo "PACKAGE ID:$UploadCsarId"
57echo "############## UOLOAD PACKAGE to MARKET PLACE END ##################";
58#######UOLOAD PACKAGE to MARKET PLACE END#############
59###########################################
60###########################################
61###########################################
62###########################################
63###########################################
64###########################################
65###########################################
66################GET ON BOARD STATUS########
67echo
68echo "####################### GETTING ON-BOARDING STATUS ##################";
69#sleeping for 10 sec so thate ON Boarding operation should be happened at backend
70for pc in $(seq 1 10); do
71 status=$((${pc}*10));
72 echo -ne "ON_BOARDING Status (%): $status\033[0K\r"
73 sleep 1
74done
75echo
76
77#Three Retries for getting On Boarding Result
78#count=0
79#while [ $count -lt 3 ]
80#do
81# OnBoardStatusResponse=$(curl -sS -X GET "http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars/$UploadCsarId/onboardstatus?operTypeId=functiontest&operId=functestexec" -H "Accept: application/json" -H "Content-Type: application/json")
82# echo $OnBoardStatusResponse
83# if echo "$OnBoardStatusResponse" | grep -q "\"status\":0"; then
84# break;
85# else
86# if [ $count -eq 3 ]
87# then
88# echo "ON-BOARDING OPERATION FAILED !!!";
89# fi
90# count=`expr $count + 1`;
91# sleep 3;
92# fi
93#done
94echo "GET ON-BOARDING RESULT OPERATION SUCESS ";
95echo "##################### GETTING ON-BOARDING STATUS END #################";
96####################GET ON BOARD STATUS END############
97##########################################
98##########################################
99##########################################
100##########################################
101##########################################
102#################DOWNLOAD PACKAGE#########
103echo
104echo "############## DOWNLOADED PACKAGE FROM MARKET STARTED #################";
105PACKAGE_NAME=market_temp.csar
106curl -sS -X GET "http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars/$UploadCsarId/files" > $PACKAGE_NAME
107fileSize=$(du -b $PACKAGE_NAME | cut -f 1)
108if [ $fileSize -eq 0 ]
109then
110 echo "DOWNLOADED PACKAGE FROM MARKET NOT PROPER, ON-BOARDING OPERATION FAILED !!!";
111 exit 1;
112fi
113echo "DOWNLOADED PACKAGE FROM MARKET OPERATION SUCESS !!!";
114echo "MARKET PACKAGE NAME:$PACKAGE_NAME"
115echo "##################### DOWNLOADED PACKAGE FROM MARKET ##################";
116###################DOWNLOAD PACKAGE END#####################
117##########################################
118##########################################
119##########################################
120##########################################
121##########CATALOUGE START#################
122echo
123PACKAGE_NAME=$CSAR_NAME
124#Check if common-tosca-catalog is registered with MSB or not
125#curl -sS -X GET http://$MSB_ADDR/api/microservices/v1/services/catalog/version/v1 -H "Accept: application/json" -H "Content-Type: application/json"
126#check if common-tosca-aria is registered with MSB or not
127#curl -sS -X GET http://$MSB_ADDR/api/microservices/v1/services/tosca/version/v1 -H "Accept: application/json" -H "Content-Type: application/json"
128#echo Sending POST request to Catalog
129CsarIdString=$(curl -sS -X POST -H "Content-Type: multipart/form-data; boundary=-WebKitFormBoundary7MA4YWxkTrZu0gW" -H "Cache-Control: no-cache" -H "Postman-Token: abcb6497-b225-c592-01be-e9ff460ca188" -F "file=@$PACKAGE_NAME" http://$MSB_ADDR/openoapi/catalog/v1/csars)
130#getting csarId from the output of curl request
131CsarId=$(echo ${CsarIdString:11:36})
132echo $CsarId
133echo $CsarIdString
134#csarid is sucessfully stored in CsarId variable
135echo "====finished======"
136##########CATALOUGE END############
137echo "DELETING PACAKE LOCAL COPY:$PACKAGE_NAME";
138#rm $PACKAGE_NAME;