#!/bin/bash

set -e

export OSSTEST_CONFIG=local-production-config 

if [ $# -ne 1 ] ; then
    echo "usage:"
    echo "  test-alloc-executive.sh -          create a new flight to use"
    echo "  test-alloc-executive.sh NNNNN      test using flight NNNNN"
    exit 1
fi

if [ "x$1" = "x-" ] ; then
    echo "Creating a flight to use"

    flight=`./cs-flight-create adhoc xen-unstable`

    common_hostflags=arch-amd64,arch-xen-amd64,suite-wheezy,purpose-test

    ./cs-job-create $flight debug-host-alloc-noexpr nop \
        all_hostflags=$common_hostflags

    ./cs-job-create $flight debug-host-alloc-expr nop \
        all_hostflags=$common_hostflags,PropMinVer:linux-kernel-min:3.4
    
    echo "Flight is $flight"

    exit 0
else
    flight=$1
    #job=debug-host-alloc-noexpr
    job=debug-host-alloc-expr
fi


export OSSTEST_FLIGHT=$flight
export OSSTEST_JOB=$job

debug=/home/osstest/logs/${flight}/${job}/hosts-allocate.debug # .gz

rm -f ${debug}.10
for i in $(seq 9 -1 1) ; do
    [ -f ${debug}.$i ] || continue
    mv ${debug}.$i ${debug}.$(($i+1))
done
if [ -f ${debug} ] ; then
    mv ${debug} ${debug}.1
fi

exec ./ts-hosts-allocate -Un host
