Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 1 | #!/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 | ############################################################################### |
| 17 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 18 | echo $SCRIPT_DIR |
| 19 | |
| 20 | #CHECK IF MSB_ADDR IS GIVEN IN COMMAND |
| 21 | if [ -z "$1" ] |
| 22 | then |
| 23 | echo "There is no MSB_ADDR" |
| 24 | exit 1 |
| 25 | fi |
| 26 | MSB_ADDR=$1 |
| 27 | CSAR_NAME=$2 |
| 28 | echo $MSB_ADDR |
| 29 | echo $CSAR_NAME |
| 30 | |
| 31 | |
| 32 | ########################################### |
| 33 | ########################################### |
| 34 | ########################################### |
| 35 | ########################################### |
| 36 | ########################################### |
| 37 | ########################################### |
| 38 | ############UOLOAD PACKAGE to MARKET PLACE###################### |
| 39 | echo |
| 40 | echo "############## UOLOAD PACKAGE to MARKET PLACE STARTED ##############"; |
| 41 | UploadPackageResponse=$(curl -sS -X POST -H "Content-Type: multipart/form-data;" -F "file=@$CSAR_NAME" http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars) |
| 42 | if echo "$UploadPackageResponse" | grep -q "\"csarId\""; then |
| 43 | echo "UOLOAD PACKAGE TO MARKET PLACE SUCSSS !!!"; |
| 44 | else |
| 45 | echo "UploadPackageResponse :$UploadPackageResponse" |
| 46 | echo "UOLOAD PACKAGE TO MARKET PLACE FAILED !!!"; |
| 47 | exit 1; |
| 48 | fi |
| 49 | UploadCsarId=$(echo ${UploadPackageResponse:11:36}) |
| 50 | echo "PACKAGE ID:$UploadCsarId" |
| 51 | echo "############## 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######## |
| 61 | echo |
| 62 | echo "####################### GETTING ON-BOARDING STATUS ##################"; |
| 63 | #sleeping for 10 sec so thate ON Boarding operation should be happened at backend |
| 64 | for pc in $(seq 1 10); do |
| 65 | status=$((${pc}*10)); |
| 66 | echo -ne "ON_BOARDING Status (%): $status\033[0K\r" |
| 67 | sleep 1 |
| 68 | done |
| 69 | echo |
| 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 |
| 88 | echo "GET ON-BOARDING RESULT OPERATION SUCESS "; |
| 89 | echo "##################### GETTING ON-BOARDING STATUS END #################"; |
| 90 | ####################GET ON BOARD STATUS END############ |
| 91 | ########################################## |
| 92 | ########################################## |
| 93 | ########################################## |
| 94 | ########################################## |
| 95 | ########################################## |
| 96 | #################DOWNLOAD PACKAGE######### |
| 97 | echo |
| 98 | echo "############## DOWNLOADED PACKAGE FROM MARKET STARTED #################"; |
| 99 | PACKAGE_NAME=market_temp.csar |
| 100 | curl -sS -X GET "http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars/$UploadCsarId/files" > $PACKAGE_NAME |
| 101 | fileSize=$(du -b $PACKAGE_NAME | cut -f 1) |
| 102 | if [ $fileSize -eq 0 ] |
| 103 | then |
| 104 | echo "DOWNLOADED PACKAGE FROM MARKET NOT PROPER, ON-BOARDING OPERATION FAILED !!!"; |
| 105 | exit 1; |
| 106 | fi |
| 107 | echo "DOWNLOADED PACKAGE FROM MARKET OPERATION SUCESS !!!"; |
| 108 | echo "MARKET PACKAGE NAME:$PACKAGE_NAME" |
| 109 | echo "##################### DOWNLOADED PACKAGE FROM MARKET ##################"; |
| 110 | ###################DOWNLOAD PACKAGE END##################### |
| 111 | ########################################## |
| 112 | ########################################## |
| 113 | ########################################## |
| 114 | ########################################## |
| 115 | ##########CATALOUGE START################# |
| 116 | echo |
| 117 | PACKAGE_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 |
| 123 | CsarIdString=$(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 |
| 125 | CsarId=$(echo ${CsarIdString:11:36}) |
| 126 | echo $CsarId |
| 127 | echo $CsarIdString |
| 128 | #csarid is sucessfully stored in CsarId variable |
| 129 | echo "====finished======" |
| 130 | ##########CATALOUGE END############ |
| 131 | echo "DELETING PACAKE LOCAL COPY:$PACKAGE_NAME"; |
| 132 | #rm $PACKAGE_NAME; |