Fatih Degirmenci | e921738 | 2019-10-01 16:41:46 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | cd $WORKSPACE |
| 4 | |
| 5 | # install dependencies |
| 6 | sudo apt install -y virtualenv jq > /dev/null |
| 7 | /bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV |
| 8 | virtualenv -p python3 $NOLABS_VENV > /dev/null |
| 9 | source $NOLABS_VENV/bin/activate > /dev/null |
| 10 | pip install httpie > /dev/null |
| 11 | |
| 12 | # check if the booking is cancelled or not |
Fatih Degirmenci | c4e4549 | 2019-10-01 18:30:27 +0200 | [diff] [blame^] | 13 | echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text'" |
Fatih Degirmenci | e921738 | 2019-10-01 16:41:46 +0200 | [diff] [blame] | 14 | BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text') |
| 15 | if [[ $BOOKING_STATUS != 'new' ]]; then |
| 16 | echo "Info: Booking is either cancelled or not valid! Exiting!" |
| 17 | exit 0; |
| 18 | fi |
| 19 | |
| 20 | # get authentication token |
Fatih Degirmenci | c4e4549 | 2019-10-01 18:30:27 +0200 | [diff] [blame^] | 21 | echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'" |
| 22 | NOLABS_TOKEN=$(http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token') |
Fatih Degirmenci | e921738 | 2019-10-01 16:41:46 +0200 | [diff] [blame] | 23 | echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\"" |
| 24 | http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \ |
Fatih Degirmenci | c4e4549 | 2019-10-01 18:30:27 +0200 | [diff] [blame^] | 25 | "Authorization:Bearer $NOLABS_TOKEN" |
| 26 | |
Fatih Degirmenci | e921738 | 2019-10-01 16:41:46 +0200 | [diff] [blame] | 27 | # get ssh public key of the user |
| 28 | echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'" |
| 29 | NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id') |
| 30 | echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'" |
| 31 | http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID "Authorization:Bearer $NOLABS_TOKEN" | jq -r '.ssh_public_key' > $NOLABS_USER_SSHPUBKEY |
| 32 | echo "-------------------------------------------------" |
| 33 | cat $NOLABS_USER_SSHPUBKEY |
| 34 | echo "-------------------------------------------------" |
| 35 | |
| 36 | deactivate |
| 37 | # get the specific patch |
| 38 | cd $WORKSPACE |
| 39 | git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD |
| 40 | |
| 41 | export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}" |
| 42 | echo "Info: STACK_NAME is set to $STACK_NAME" |
| 43 | cd engine |
| 44 | ./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE" |
| 45 | |
| 46 | cd $WORKSPACE |
| 47 | |
| 48 | source $NOLABS_VENV/bin/activate > /dev/null |
| 49 | ENGINE_VERSION=$(git rev-parse HEAD) |
| 50 | cd $WORKSPACE/.cache/repos/swconfig |
| 51 | SCENARIO_VERSION=$(git rev-parse HEAD) |
| 52 | cd $WORKSPACE |
| 53 | #FLOATING_IP=$(cat .cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2) |
| 54 | FLOATING_IP=10.10.10.10 |
| 55 | |
| 56 | # get authentication token |
| 57 | echo "API Request: http --ignore-stdin POST http://188.212.108.245/api/tokens --auth dummy@dummy.com:dummy | jq -r '.token'" |
| 58 | NOLABS_TOKEN=$(http --ignore-stdin POST http://188.212.108.245/api/tokens --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token') |
| 59 | |
| 60 | # update booking |
| 61 | echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \ |
| 62 | \"Authorization:Bearer DUMMY_TOKEN\" \ |
| 63 | status_text=active \ |
| 64 | floating_ip=$FLOATING_IP \ |
| 65 | heat_stack_name=$STACK_NAME \ |
| 66 | scenario_deploy_log_url=${BUILD_URL}consoleFull \ |
| 67 | engine_version=$ENGINE_VERSION \ |
| 68 | scenario_version=$SCENARIO_VERSION" |
| 69 | http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \ |
| 70 | "Authorization:Bearer $NOLABS_TOKEN" \ |
| 71 | status_text=active \ |
| 72 | floating_ip=$FLOATING_IP \ |
| 73 | heat_stack_name=$STACK_NAME \ |
| 74 | scenario_deploy_log_url=${BUILD_URL}consoleFull \ |
| 75 | engine_version=$ENGINE_VERSION \ |
| 76 | scenario_version=$SCENARIO_VERSION |