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