#!/bin/bash
#---------------------
# Testing nova-compute
#---------------------
set -e
DAEMONS=('nova-compute-kvm' 'nova-compute-lxc' 'nova-compute-qemu')

for daemon in "${DAEMONS[@]}"; do
    apt-get install -y nova-compute $daemon 2>&1

    TIMEOUT=50
    while [ "$TIMEOUT" -gt 0 ]; do
        if pidof -x nova-compute > /dev/null; then
            echo "OK"
            break
        fi
        TIMEOUT=$((TIMEOUT - 1))
        sleep 0.1
    done

    if [ "$TIMEOUT" -le 0 ]; then
        echo "ERROR: NOVA-COMPUTE FOR $daemon IS NOT RUNNING"
        exit 1
    fi

    apt-get remove -y $daemon nova-compute 2>&1
done
