add ccsdk-sli-northbound
[infra/cicd.git] / jjb / nolabs / handle-booking.sh
index b6b9066b1bbff5239446c82126024c7cb2227c14..fe5d29f48ba6f29a2ec055d2b0ed9616884e529c 100644 (file)
@@ -1,12 +1,19 @@
 #!/bin/bash
+set -o errexit
+set -o nounset
+set -o pipefail
 
 cd $WORKSPACE
 
 # install dependencies
+sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse" > /dev/null
 sudo apt install -y virtualenv jq > /dev/null
-/bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV
+/bin/rm -rf /opt/engine $NOLABS_VENV
+mkdir -p $NOLABS_VENV
 virtualenv -p python3 $NOLABS_VENV > /dev/null
+set +u
 source $NOLABS_VENV/bin/activate > /dev/null
+set -u
 pip install httpie > /dev/null
 
 # check if the booking is cancelled or not
@@ -22,18 +29,17 @@ echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth d
 NOLABS_TOKEN=$(http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --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"
+    "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 "-------------------------------------------------"
 
+set +u
 deactivate
+set -u
 # get the specific patch
 cd $WORKSPACE
 git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD
@@ -45,30 +51,31 @@ cd engine
 
 cd $WORKSPACE
 
+set +u
 source $NOLABS_VENV/bin/activate > /dev/null
+set -u
 ENGINE_VERSION=$(git rev-parse HEAD)
-cd $WORKSPACE/.cache/repos/swconfig
+cd /opt/engine/.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
+FLOATING_IP=$(cat /opt/engine/.cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2)
 
 # 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 POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
+NOLABS_TOKEN=$(http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --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 \
+    \"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 \
+    "Authorization:Bearer $NOLABS_TOKEN" \
+    status_text=active \
     floating_ip=$FLOATING_IP \
     heat_stack_name=$STACK_NAME \
     scenario_deploy_log_url=${BUILD_URL}consoleFull \