blob: 4b011027d49ced4005531d6e39e081fa60cc3f4d [file] [log] [blame]
Fatih Degirmencie9217382019-10-01 16:41:46 +02001#!/bin/bash
2
3cd $WORKSPACE
4
5# install dependencies
6sudo apt install -y virtualenv jq > /dev/null
7/bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV
8virtualenv -p python3 $NOLABS_VENV > /dev/null
9source $NOLABS_VENV/bin/activate > /dev/null
10pip install httpie > /dev/null
11
12# check if the booking is cancelled or not
Fatih Degirmencic4e45492019-10-01 18:30:27 +020013echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text'"
Fatih Degirmencie9217382019-10-01 16:41:46 +020014BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text')
15if [[ $BOOKING_STATUS != 'new' ]]; then
16 echo "Info: Booking is either cancelled or not valid! Exiting!"
17 exit 0;
18fi
19
20# get authentication token
Fatih Degirmencic4e45492019-10-01 18:30:27 +020021echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
22NOLABS_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 +020023echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\""
24http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020025 "Authorization:Bearer $NOLABS_TOKEN"
Fatih Degirmencic4e45492019-10-01 18:30:27 +020026
Fatih Degirmencie9217382019-10-01 16:41:46 +020027# get ssh public key of the user
28echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'"
29NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id')
30echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'"
31http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID "Authorization:Bearer $NOLABS_TOKEN" | jq -r '.ssh_public_key' > $NOLABS_USER_SSHPUBKEY
32echo "-------------------------------------------------"
33cat $NOLABS_USER_SSHPUBKEY
34echo "-------------------------------------------------"
35
36deactivate
37# get the specific patch
38cd $WORKSPACE
39git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD
40
41export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}"
42echo "Info: STACK_NAME is set to $STACK_NAME"
43cd engine
44./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE"
45
46cd $WORKSPACE
47
48source $NOLABS_VENV/bin/activate > /dev/null
49ENGINE_VERSION=$(git rev-parse HEAD)
50cd $WORKSPACE/.cache/repos/swconfig
51SCENARIO_VERSION=$(git rev-parse HEAD)
52cd $WORKSPACE
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020053FLOATING_IP=$(cat .cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2)
Fatih Degirmencie9217382019-10-01 16:41:46 +020054
55# get authentication token
Fatih Degirmencid35fd4a2019-10-01 18:37:32 +020056echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
57NOLABS_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 +020058
59# update booking
60echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020061 \"Authorization:Bearer DUMMY_TOKEN\" \
62 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020063 floating_ip=$FLOATING_IP \
64 heat_stack_name=$STACK_NAME \
65 scenario_deploy_log_url=${BUILD_URL}consoleFull \
66 engine_version=$ENGINE_VERSION \
67 scenario_version=$SCENARIO_VERSION"
68http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020069 "Authorization:Bearer $NOLABS_TOKEN" \
70 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020071 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