tripleo-incubator/scripts/wait_for_hypervisor_stats
Ben Nemec a5ff205814 Calculate expected number of vcpus/mem
Rather than just wait for a single vcpu or a non-zero amount of
memory to be available, we should look at the baremetal flavor and
figure out how many of each we should expect.

Closes-Bug: #1341634

Change-Id: I9d9ce55de3b9ad0f94d087179b9432e9e9e50d74
2014-07-22 19:56:45 -05:00

51 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -eu
set -o pipefail
SCRIPT_NAME=$(basename $0)
function show_options () {
echo "Usage: $SCRIPT_NAME [<nodes>] [options]"
echo
echo "Waits for \`nova hypervisor-stats\` to show some memory + vcpus are available."
echo
echo "Positional arguments:"
echo " nodes -- The number of nodes to wait for, defaults to 1."
echo
echo "Options:"
echo " -h / --help -- this help"
echo
exit $1
}
TEMP=$(getopt -o h -l help -n $SCRIPT_NAME -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true ; do
case "$1" in
-h | --help) show_options 0;;
--) shift ; break ;;
*) echo "Error: unsupported option $1." ; exit 1 ;;
esac
done
EXPECTED_NODES=${1:-1}
# NOTE(bnemec): If/when we have more flavors, this will need
# to be expanded.
FLAVOR=$(nova flavor-show baremetal)
VCPUS=$(echo "$FLAVOR" | awk '$2=="vcpus" { print $4 }')
EXPECTED_VCPUS=$(($VCPUS*$EXPECTED_NODES))
MEM=$(echo "$FLAVOR" | awk '$2=="ram" { print $4 }')
EXPECTED_MEM=$(($MEM*$EXPECTED_NODES))
nova hypervisor-stats | awk '
$2=="count" && $4 >= '"$EXPECTED_NODES"' { c++ };
$2=="memory_mb" && $4 >= '"$EXPECTED_MEM"' { c++ };
$2=="vcpus" && $4 >= '"$EXPECTED_VCPUS"' { c++ };
END { if (c != 3) exit 1 }'