blob: fa37ee2696769a278b005d1aa6c3eb87f2d5b1e8 [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
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020013set +u
Fatih Degirmencie9217382019-10-01 16:41:46 +020014source $NOLABS_VENV/bin/activate > /dev/null
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020015set -u
Fatih Degirmencie9217382019-10-01 16:41:46 +020016pip install httpie > /dev/null
17
18# check if the booking is cancelled or not
Fatih Degirmencic4e45492019-10-01 18:30:27 +020019echo "API Request: http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text'"
Fatih Degirmencie9217382019-10-01 16:41:46 +020020BOOKING_STATUS=$(http --ignore-stdin GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.status_text')
21if [[ $BOOKING_STATUS != 'new' ]]; then
22 echo "Info: Booking is either cancelled or not valid! Exiting!"
23 exit 0;
24fi
25
26# get authentication token
Fatih Degirmencic4e45492019-10-01 18:30:27 +020027echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
28NOLABS_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 +020029echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \"status_text=deploying\" \"Authorization:Bearer DUMMY_TOKEN\""
30http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID "status_text=deploying" \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020031 "Authorization:Bearer $NOLABS_TOKEN"
Fatih Degirmencic4e45492019-10-01 18:30:27 +020032
Fatih Degirmencie9217382019-10-01 16:41:46 +020033# get ssh public key of the user
34echo "API Request: http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id'"
35NOLABS_USER_ID=$(http GET $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID | jq -r '.user_id')
36echo "API Request: http --ignore-stdin GET $NOLABS_API_USERS_ENDPOINT/$NOLABS_USER_ID \"Authorization:Bearer DUMMY_TOKEN\" | jq -r '.ssh_public_key'"
37http --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 +020038
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020039set +u
Fatih Degirmencie9217382019-10-01 16:41:46 +020040deactivate
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020041set -u
Fatih Degirmencie9217382019-10-01 16:41:46 +020042# get the specific patch
43cd $WORKSPACE
44git fetch "https://gerrit.nordix.org/infra/engine" $GERRIT_REFSPEC && git checkout FETCH_HEAD
45
46export STACK_NAME="nordix-nolabs-booking${BOOKING_ID}-${DEPLOY_SCENARIO}"
47echo "Info: STACK_NAME is set to $STACK_NAME"
48cd engine
49./deploy.sh -c -r heat -u /tmp/openrc -s $DEPLOY_SCENARIO -e "$HEAT_ENVIRONMENT_FILE"
50
51cd $WORKSPACE
52
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020053set +u
Fatih Degirmencie9217382019-10-01 16:41:46 +020054source $NOLABS_VENV/bin/activate > /dev/null
Fatih Degirmenci165f3f32019-10-02 08:14:38 +020055set -u
Fatih Degirmencie9217382019-10-01 16:41:46 +020056ENGINE_VERSION=$(git rev-parse HEAD)
57cd $WORKSPACE/.cache/repos/swconfig
58SCENARIO_VERSION=$(git rev-parse HEAD)
59cd $WORKSPACE
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020060FLOATING_IP=$(cat .cache/config/inventory.ini | grep 'jumphost ansible_host' | awk '{print $2}' | cut -d'=' -f2)
Fatih Degirmencie9217382019-10-01 16:41:46 +020061
62# get authentication token
Fatih Degirmencid35fd4a2019-10-01 18:37:32 +020063echo "API Request: http --ignore-stdin POST $NOLABS_API_TOKENS_ENDPOINT --auth dummy@dummy.com:dummy | jq -r '.token'"
64NOLABS_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 +020065
66# update booking
67echo "API Request: http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020068 \"Authorization:Bearer DUMMY_TOKEN\" \
69 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020070 floating_ip=$FLOATING_IP \
71 heat_stack_name=$STACK_NAME \
72 scenario_deploy_log_url=${BUILD_URL}consoleFull \
73 engine_version=$ENGINE_VERSION \
74 scenario_version=$SCENARIO_VERSION"
75http --ignore-stdin PUT $NOLABS_API_BOOKINGS_ENDPOINT/$BOOKING_ID \
Fatih Degirmenci02ae5ec2019-10-01 19:14:56 +020076 "Authorization:Bearer $NOLABS_TOKEN" \
77 status_text=active \
Fatih Degirmencie9217382019-10-01 16:41:46 +020078 floating_ip=$FLOATING_IP \
79 heat_stack_name=$STACK_NAME \
80 scenario_deploy_log_url=${BUILD_URL}consoleFull \
81 engine_version=$ENGINE_VERSION \
82 scenario_version=$SCENARIO_VERSION