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 | # Wait for MSB initialization |
| 32 | echo Wait for MSB initialization |
| 33 | for i in {1..20}; do |
| 34 | curl -sS -m 1 $MSB_ADDR > /dev/null && break |
| 35 | sleep $i |
| 36 | done |
| 37 | #MSB initialized |
| 38 | ########################################### |
| 39 | ########################################### |
| 40 | ########################################### |
| 41 | ########################################### |
| 42 | ########################################### |
| 43 | ########################################### |
| 44 | ############UOLOAD PACKAGE to MARKET PLACE###################### |
| 45 | echo |
| 46 | echo "############## UOLOAD PACKAGE to MARKET PLACE STARTED ##############"; |
| 47 | UploadPackageResponse=$(curl -sS -X POST -H "Content-Type: multipart/form-data;" -F "file=@$CSAR_NAME" http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars) |
| 48 | if echo "$UploadPackageResponse" | grep -q "\"csarId\""; then |
| 49 | echo "UOLOAD PACKAGE TO MARKET PLACE SUCSSS !!!"; |
| 50 | else |
| 51 | echo "UploadPackageResponse :$UploadPackageResponse" |
| 52 | echo "UOLOAD PACKAGE TO MARKET PLACE FAILED !!!"; |
| 53 | exit 1; |
| 54 | fi |
| 55 | UploadCsarId=$(echo ${UploadPackageResponse:11:36}) |
| 56 | echo "PACKAGE ID:$UploadCsarId" |
| 57 | echo "############## 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######## |
| 67 | echo |
| 68 | echo "####################### GETTING ON-BOARDING STATUS ##################"; |
| 69 | #sleeping for 10 sec so thate ON Boarding operation should be happened at backend |
| 70 | for pc in $(seq 1 10); do |
| 71 | status=$((${pc}*10)); |
| 72 | echo -ne "ON_BOARDING Status (%): $status\033[0K\r" |
| 73 | sleep 1 |
| 74 | done |
| 75 | echo |
| 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 |
| 94 | echo "GET ON-BOARDING RESULT OPERATION SUCESS "; |
| 95 | echo "##################### GETTING ON-BOARDING STATUS END #################"; |
| 96 | ####################GET ON BOARD STATUS END############ |
| 97 | ########################################## |
| 98 | ########################################## |
| 99 | ########################################## |
| 100 | ########################################## |
| 101 | ########################################## |
| 102 | #################DOWNLOAD PACKAGE######### |
| 103 | echo |
| 104 | echo "############## DOWNLOADED PACKAGE FROM MARKET STARTED #################"; |
| 105 | PACKAGE_NAME=market_temp.csar |
| 106 | curl -sS -X GET "http://$MSB_ADDR/openoapi/vnfsdk-marketplace/v1/PackageResource/csars/$UploadCsarId/files" > $PACKAGE_NAME |
| 107 | fileSize=$(du -b $PACKAGE_NAME | cut -f 1) |
| 108 | if [ $fileSize -eq 0 ] |
| 109 | then |
| 110 | echo "DOWNLOADED PACKAGE FROM MARKET NOT PROPER, ON-BOARDING OPERATION FAILED !!!"; |
| 111 | exit 1; |
| 112 | fi |
| 113 | echo "DOWNLOADED PACKAGE FROM MARKET OPERATION SUCESS !!!"; |
| 114 | echo "MARKET PACKAGE NAME:$PACKAGE_NAME" |
| 115 | echo "##################### DOWNLOADED PACKAGE FROM MARKET ##################"; |
| 116 | ###################DOWNLOAD PACKAGE END##################### |
| 117 | ########################################## |
| 118 | ########################################## |
| 119 | ########################################## |
| 120 | ########################################## |
| 121 | ##########CATALOUGE START################# |
| 122 | echo |
| 123 | PACKAGE_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 |
| 129 | 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) |
| 130 | #getting csarId from the output of curl request |
| 131 | CsarId=$(echo ${CsarIdString:11:36}) |
| 132 | echo $CsarId |
| 133 | echo $CsarIdString |
| 134 | #csarid is sucessfully stored in CsarId variable |
| 135 | echo "====finished======" |
| 136 | ##########CATALOUGE END############ |
| 137 | echo "DELETING PACAKE LOCAL COPY:$PACKAGE_NAME"; |
| 138 | #rm $PACKAGE_NAME; |