blob: e0096a959ef3a877429bd650403544add3900a3c [file] [log] [blame]
Fatih Degirmencie9217382019-10-01 16:41:46 +02001#!/bin/bash
2
3cd $WORKSPACE
4
5# install dependencies
Fatih Degirmenci346bfa82019-10-01 20:13:47 +02006sudo 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 +02007sudo apt install -y virtualenv jq > /dev/null
8/bin/rm -rf $NOLABS_VENV && mkdir -p $NOLABS_VENV
9virtualenv -p python3 $NOLABS_VENV > /dev/null
10source $NOLABS_VENV/bin/activate > /dev/null
11pip install httpie > /dev/null
12
13# check if the booking is cancelled or not
Fatih Degirmencic4e45492019-10-01 18:30:27 +020014echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text'"
Fatih Degirmencie9217382019-10-01 16:41:46 +020015BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text')
16if [[ $BOOKING_STATUS != 'new' ]]; then
17 echo "Info: Booking is either cancelled or not valid! Exiting!"
18 exit 0;
19fi
20
21# get authentication token
Fatih Degirmencic4e45492019-10-01 18:30:27 +020022echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
23NOLABS_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 +020024echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\""
25http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020026 "Authorization:Bearer $NOLABS_TOKEN"
Fatih Degirmencic4e45492019-10-01 18:30:27 +020027
Fatih Degirmencie9217382019-10-01 16:41:46 +020028# get ssh public key of the user
29echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'"
30NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id')
31echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'"
32http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID "Authorization:Bearer $NOLABS_TOKEN" | jq -r '.ssh_public_key' > $NOLABS_USER_SSHPUBKEY
33echo "-------------------------------------------------"
34cat $NOLABS_USER_SSHPUBKEY
35echo "-------------------------------------------------"
36
37deactivate
38# get the specific patch
39cd $WORKSPACE
40git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD
41
42export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}"
43echo "Info: STACK_NAME is set to $STACK_NAME"
44cd engine
45./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE"
46
47cd $WORKSPACE
48
49source $NOLABS_VENV/bin/activate > /dev/null
50ENGINE_VERSION=$(git rev-parse HEAD)
51cd $WORKSPACE/.cache/repos/swconfig
52SCENARIO_VERSION=$(git rev-parse HEAD)
53cd $WORKSPACE
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020054FLOATING_IP=$(cat .cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2)
Fatih Degirmencie9217382019-10-01 16:41:46 +020055
56# get authentication token
Fatih Degirmencid35fd4a2019-10-01 18:37:32 +020057echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
58NOLABS_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 +020059
60# update booking
61echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020062 \"Authorization:Bearer DUMMY_TOKEN\" \
63 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020064 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"
69http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020070 "Authorization:Bearer $NOLABS_TOKEN" \
71 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020072 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