blob: fe5d29f48ba6f29a2ec055d2b0ed9616884e529c [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
Fatih Degirmenci552a75b2020-02-02 09:01:17 +010011/bin/rm -rf /opt/engine $NOLABS_VENV
12mkdir -p $NOLABS_VENV
Fatih Degirmencie9217382019-10-01 16:41:46 +020013virtualenv -p python3 $NOLABS_VENV > /dev/null
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020014set +u
Fatih Degirmencie9217382019-10-01 16:41:46 +020015source $NOLABS_VENV/bin/activate > /dev/null
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020016set -u
Fatih Degirmencie9217382019-10-01 16:41:46 +020017pip install httpie > /dev/null
18
19# check if the booking is cancelled or not
Fatih Degirmencic4e45492019-10-01 18:30:27 +020020echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text'"
Fatih Degirmencie9217382019-10-01 16:41:46 +020021BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text')
22if [[ $BOOKING_STATUS != 'new' ]]; then
23 echo "Info: Booking is either cancelled or not valid! Exiting!"
24 exit 0;
25fi
26
27# get authentication token
Fatih Degirmencic4e45492019-10-01 18:30:27 +020028echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
29NOLABS_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 +020030echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\""
31http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020032 "Authorization:Bearer $NOLABS_TOKEN"
Fatih Degirmencic4e45492019-10-01 18:30:27 +020033
Fatih Degirmencie9217382019-10-01 16:41:46 +020034# get ssh public key of the user
35echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'"
36NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id')
37echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'"
38http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID "Authorization:Bearer $NOLABS_TOKEN" | jq -r '.ssh_public_key' > $NOLABS_USER_SSHPUBKEY
Fatih Degirmencie9217382019-10-01 16:41:46 +020039
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020040set +u
Fatih Degirmencie9217382019-10-01 16:41:46 +020041deactivate
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020042set -u
Fatih Degirmencie9217382019-10-01 16:41:46 +020043# get the specific patch
44cd $WORKSPACE
45git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD
46
47export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}"
48echo "Info: STACK_NAME is set to $STACK_NAME"
49cd engine
50./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE"
51
52cd $WORKSPACE
53
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020054set +u
Fatih Degirmencie9217382019-10-01 16:41:46 +020055source $NOLABS_VENV/bin/activate > /dev/null
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020056set -u
Fatih Degirmencie9217382019-10-01 16:41:46 +020057ENGINE_VERSION=$(git rev-parse HEAD)
Fatih Degirmenci552a75b2020-02-02 09:01:17 +010058cd /opt/engine/.cache/repos/swconfig
Fatih Degirmencie9217382019-10-01 16:41:46 +020059SCENARIO_VERSION=$(git rev-parse HEAD)
60cd $WORKSPACE
Fatih Degirmenci552a75b2020-02-02 09:01:17 +010061FLOATING_IP=$(cat /opt/engine/.cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2)
Fatih Degirmencie9217382019-10-01 16:41:46 +020062
63# get authentication token
Fatih Degirmencid35fd4a2019-10-01 18:37:32 +020064echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
65NOLABS_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 +020066
67# update booking
68echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020069 \"Authorization:Bearer DUMMY_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"
76http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020077 "Authorization:Bearer $NOLABS_TOKEN" \
78 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020079 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