# If old environment exists, remove it
if [ -d hummingbird_client_env ]; then
    rm -rf hummingbird_client_env
fi

# Make clean environment
virtualenv -p python3.6 hummingbird_client_env

# Activate hummingbird env
. hummingbird_client_env/bin/activate

# Force reinstall newest version of hummingbird from pypi
python -m pip install hummingbird \
    --index-url https://pypi.zooxlabs.com/simple \
    --extra-index-url https://pypi.python.org/simple \
    --force-reinstall

# CLI tool takes in Bamboo variable as CLI input argument and converts it to a float to use with
# hummingbird CLI tool
start_time=$(convert_timestamp $bamboo_buildTimeStamp)

# Get end time in the same format as $bamboo_buildTimeStamp
# and then convert it using the same utility script as the above
end_datetime=`date "+%Y-%m-%dT%T.%3N%:z"`
end_time=$(convert_timestamp $end_datetime)

# Determine Bamboo status
# Variables from bamboo listed here:
# https://bamboo.zooxlabs.com/build/admin/ajax/viewAvailableVariables.action
if [ -f "$bamboo_build_working_directory/github.sentinel" ]; then
    test_result="PASS"
else
    test_result="FAIL"
fi

# Which node is this running on?
nodename=`hostname`

# CLI tool takes in Bamboo variable as CLI input argument and converts it to a float to use with
# hummingbird CLI tool
hummingbird \
    --remotehost hummingbird.zooxlabs.com \
    --port 32100 \
    --username postgres \
    --databasename fwval \
    --result $test_result \
    --criticality NONE \
    --start_time $start_time \
    --end_time $end_time \
    --other ''  \
    --fw_hash ${bamboo_planRepository_revision} \
    --test_id ${bamboo_buildResultKey} \
    --tester ${nodename} \
    smoketest emu

