blob: 30f82d5f5cd21196be85fb55aeec941f8e7e38ed [file] [log] [blame]
Fatih Degirmencie9217382019-10-01 16:41:46 +02001#!/bin/bash
Fatih Degirmencif5e2b332019-10-02 07:38:02 +02002set -o errexit
3set -o nounset
4set -o pipefail
Fatih Degirmencie9217382019-10-01 16:41:46 +02005
6cd $WORKSPACE
7
8# install dependencies
Fatih Degirmenci346bfa82019-10-01 20:13:47 +02009sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse" > /dev/null
Fatih Degirmencie9217382019-10-01 16:41:46 +020010sudo apt install -y virtualenv jq > /dev/null
11/bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV
12virtualenv -p python3 $NOLABS_VENV > /dev/null
13source $NOLABS_VENV/bin/activate > /dev/null
14pip install httpie > /dev/null
15
16# check if the booking is cancelled or not
Fatih Degirmencic4e45492019-10-01 18:30:27 +020017echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text'"
Fatih Degirmencie9217382019-10-01 16:41:46 +020018BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text')
19if [[ $BOOKING_STATUS != 'new' ]]; then
20 echo "Info: Booking is either cancelled or not valid! Exiting!"
21 exit 0;
22fi
23
24# get authentication token
Fatih Degirmencic4e45492019-10-01 18:30:27 +020025echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
26NOLABS_TOKEN=$(http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token')
Fatih Degirmencie9217382019-10-01 16:41:46 +020027echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\""
28http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020029 "Authorization:Bearer $NOLABS_TOKEN"
Fatih Degirmencic4e45492019-10-01 18:30:27 +020030
Fatih Degirmencie9217382019-10-01 16:41:46 +020031# get ssh public key of the user
32echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'"
33NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id')
34echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'"
35http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID "Authorization:Bearer $NOLABS_TOKEN" | jq -r '.ssh_public_key' > $NOLABS_USER_SSHPUBKEY
36echo "-------------------------------------------------"
37cat $NOLABS_USER_SSHPUBKEY
38echo "-------------------------------------------------"
39
40deactivate
41# get the specific patch
42cd $WORKSPACE
43git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD
44
45export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}"
46echo "Info: STACK_NAME is set to $STACK_NAME"
47cd engine
48./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE"
49
50cd $WORKSPACE
51
52source $NOLABS_VENV/bin/activate > /dev/null
53ENGINE_VERSION=$(git rev-parse HEAD)
54cd $WORKSPACE/.cache/repos/swconfig
55SCENARIO_VERSION=$(git rev-parse HEAD)
56cd $WORKSPACE
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020057FLOATING_IP=$(cat .cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2)
Fatih Degirmencie9217382019-10-01 16:41:46 +020058
59# get authentication token
Fatih Degirmencid35fd4a2019-10-01 18:37:32 +020060echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
61NOLABS_TOKEN=$(http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth $NOLABS_API_USERNAME:$NOLABS_API_PASSWORD | jq -r '.token')
Fatih Degirmencie9217382019-10-01 16:41:46 +020062
63# update booking
64echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020065 \"Authorization:Bearer DUMMY_TOKEN\" \
66 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020067 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"
72http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020073 "Authorization:Bearer $NOLABS_TOKEN" \
74 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020075 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