blob: 800f833dddeca9243a2a2f137159ef9fe546bb96 [file] [log] [blame]
Gary Wu9abb61c2018-09-27 10:38:50 -07001#!/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
32###########################################
33###########################################
34###########################################
35###########################################
36###########################################
37###########################################
38############UOLOAD PACKAGE to MARKET PLACE######################
39echo
40echo "############## UOLOAD PACKAGE to MARKET PLACE STARTED ##############";
41UploadPackageResponse=$(curl -sS -X POST -H "Content-Type: multipart/form-data;" -F "file=@$CSAR_NAME" http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars)
42if echo "$UploadPackageResponse" | grep -q "\"csarId\""; then
43 echo "UOLOAD PACKAGE TO MARKET PLACE SUCSSS !!!";
44else
45 echo "UploadPackageResponse :$UploadPackageResponse"
46 echo "UOLOAD PACKAGE TO MARKET PLACE FAILED !!!";
47 exit 1;
48fi
49UploadCsarId=$(echo ${UploadPackageResponse:11:36})
50echo "PACKAGE ID:$UploadCsarId"
51echo "############## UOLOAD PACKAGE to MARKET PLACE END ##################";
52#######UOLOAD PACKAGE to MARKET PLACE END#############
53###########################################
54###########################################
55###########################################
56###########################################
57###########################################
58###########################################
59###########################################
60################GET ON BOARD STATUS########
61echo
62echo "####################### GETTING ON-BOARDING STATUS ##################";
63#sleeping for 10 sec so thate ON Boarding operation should be happened at backend
64for pc in $(seq 1 10); do
65 status=$((${pc}*10));
66 echo -ne "ON_BOARDING Status (%): $status\033[0K\r"
67 sleep 1
68done
69echo
70
71#Three Retries for getting On Boarding Result
72#count=0
73#while [ $count -lt 3 ]
74#do
75# 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")
76# echo $OnBoardStatusResponse
77# if echo "$OnBoardStatusResponse" | grep -q "\"status\":0"; then
78# break;
79# else
80# if [ $count -eq 3 ]
81# then
82# echo "ON-BOARDING OPERATION FAILED !!!";
83# fi
84# count=`expr $count + 1`;
85# sleep 3;
86# fi
87#done
88echo "GET ON-BOARDING RESULT OPERATION SUCESS ";
89echo "##################### GETTING ON-BOARDING STATUS END #################";
90####################GET ON BOARD STATUS END############
91##########################################
92##########################################
93##########################################
94##########################################
95##########################################
96#################DOWNLOAD PACKAGE#########
97echo
98echo "############## DOWNLOADED PACKAGE FROM MARKET STARTED #################";
99PACKAGE_NAME=market_temp.csar
100curl -sS -X GET "http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars/$UploadCsarId/files" > $PACKAGE_NAME
101fileSize=$(du -b $PACKAGE_NAME | cut -f 1)
102if [ $fileSize -eq 0 ]
103then
104 echo "DOWNLOADED PACKAGE FROM MARKET NOT PROPER, ON-BOARDING OPERATION FAILED !!!";
105 exit 1;
106fi
107echo "DOWNLOADED PACKAGE FROM MARKET OPERATION SUCESS !!!";
108echo "MARKET PACKAGE NAME:$PACKAGE_NAME"
109echo "##################### DOWNLOADED PACKAGE FROM MARKET ##################";
110###################DOWNLOAD PACKAGE END#####################
111##########################################
112##########################################
113##########################################
114##########################################
115##########CATALOUGE START#################
116echo
117PACKAGE_NAME=$CSAR_NAME
118#Check if common-tosca-catalog is registered with MSB or not
119#curl -sS -X GET http://$MSB_ADDR/api/microservices/v1/services/catalog/version/v1 -H "Accept: application/json" -H "Content-Type: application/json"
120#check if common-tosca-aria is registered with MSB or not
121#curl -sS -X GET http://$MSB_ADDR/api/microservices/v1/services/tosca/version/v1 -H "Accept: application/json" -H "Content-Type: application/json"
122#echo Sending POST request to Catalog
123CsarIdString=$(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)
124#getting csarId from the output of curl request
125CsarId=$(echo ${CsarIdString:11:36})
126echo $CsarId
127echo $CsarIdString
128#csarid is sucessfully stored in CsarId variable
129echo "====finished======"
130##########CATALOUGE END############
131echo "DELETING PACAKE LOCAL COPY:$PACKAGE_NAME";
132#rm $PACKAGE_NAME;