X-Git-Url: https://gerrit.nordix.org/gitweb?a=blobdiff_plain;f=jjb%2Fnolabs%2Fhandle-booking.sh;fp=jjb%2Fnolabs%2Fhandle-booking.sh;h=15630106886da698d66035deafb36a7ef9c0b88a;hb=e921738689626876f05977326bb267e139617b22;hp=0000000000000000000000000000000000000000;hpb=6868b00beb4d90e0312493e167b339d6ebcc2648;p=infra%2Fcicd.git diff --git a/jjb/nolabs/handle-booking.sh b/jjb/nolabs/handle-booking.sh new file mode 100644 index 00000000..15630106 --- /dev/null +++ b/jjb/nolabs/handle-booking.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +cd $WORKSPACE + +# install dependencies +sudo apt install -y virtualenv jq > /dev/null +/bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV +virtualenv -p python3 $NOLABS_VENV > /dev/null +source $NOLABS_VENV/bin/activate > /dev/null +pip install httpie > /dev/null + +# check if the booking is cancelled or not +echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text" +BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text') +if [[ $BOOKING_STATUS != 'new' ]]; then + echo "Info: Booking is either cancelled or not valid! Exiting!" + exit 0; +fi + +# get authentication token +echo "API Request: http --ignore-stdin POST http://188.212.108.245/api/tokens --auth dummy@dummy.com:dummy | jq -r '.token'" +NOLABS_TOKEN=$(http --ignore-stdin POST http://188.212.108.245/api/tokens --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token') +echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\"" +http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \ + "Authorization:Bearer $NOLABS_TOKEN" + +# get ssh public key of the user +echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'" +NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id') +echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'" +http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID "Authorization:Bearer $NOLABS_TOKEN" | jq -r '.ssh_public_key' > $NOLABS_USER_SSHPUBKEY +echo "-------------------------------------------------" +cat $NOLABS_USER_SSHPUBKEY +echo "-------------------------------------------------" + +deactivate +# get the specific patch +cd $WORKSPACE +git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD + +export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}" +echo "Info: STACK_NAME is set to $STACK_NAME" +cd engine +./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE" + +cd $WORKSPACE + +source $NOLABS_VENV/bin/activate > /dev/null +ENGINE_VERSION=$(git rev-parse HEAD) +cd $WORKSPACE/.cache/repos/swconfig +SCENARIO_VERSION=$(git rev-parse HEAD) +cd $WORKSPACE +#FLOATING_IP=$(cat .cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2) +FLOATING_IP=10.10.10.10 + +# get authentication token +echo "API Request: http --ignore-stdin POST http://188.212.108.245/api/tokens --auth dummy@dummy.com:dummy | jq -r '.token'" +NOLABS_TOKEN=$(http --ignore-stdin POST http://188.212.108.245/api/tokens --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token') + +# update booking +echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \ + \"Authorization:Bearer DUMMY_TOKEN\" \ + status_text=active \ + floating_ip=$FLOATING_IP \ + heat_stack_name=$STACK_NAME \ + scenario_deploy_log_url=${BUILD_URL}consoleFull \ + engine_version=$ENGINE_VERSION \ + scenario_version=$SCENARIO_VERSION" +http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \ + "Authorization:Bearer $NOLABS_TOKEN" \ + status_text=active \ + floating_ip=$FLOATING_IP \ + heat_stack_name=$STACK_NAME \ + scenario_deploy_log_url=${BUILD_URL}consoleFull \ + engine_version=$ENGINE_VERSION \ + scenario_version=$SCENARIO_VERSION