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