Print logs if vm create will fail

Just to debug some bugs like 409 error

Change-Id: Ibb2c496cafe0f8062e7d14f0aaa18624337ca689
This commit is contained in:
Artur Zarzycki 2016-11-25 10:39:57 +01:00
parent 99334bd4d9
commit 4d71150ad0

View File

@ -14,6 +14,7 @@ usage() {
-k Kubernetes namespace (optional)
-i Image to boot VMs from (optional, will upload Cirros if ommited)
-f Allocate floating IPs and associate with VMs (optional)
-d Print debug to stdout
EOF
}
@ -28,6 +29,14 @@ do
fi
done
vm_error_logs() {
for v in `openstack server list -f value | awk '/ERROR/ { print $1 }'`; do
echo "-------------- ${f} ---------------"
set +e
kubectl --namespace "${K8S_NAMESPACE}" logs "${f}" | grep "${v}"
set -e
done
}
create() {
if [ -z "${NUMBER}" ]; then
@ -49,22 +58,30 @@ create() {
done
fi
openstack server list
if openstack server list | grep ERROR; then
echo "Error while creating vm"
if [ -n "${PRINT_STD}" ]; then
for f in `kubectl --namespace=${K8S_NAMESPACE} get pods -o go-template --template="{{ range .items }}{{ println .metadata.name}}{{end}}"`; do
vm_error_logs
done
fi
fi
for vm in $(openstack server list -f value -c Name | grep test_vm); do
echo "Console for $vm:"
openstack console url show $vm
echo "Console for ${vm}:"
openstack console url show "${vm}"
done
}
destroy() {
for vm in $(openstack server list -f value -c Name | grep test_vm); do
echo "Destroying $vm..."
openstack server delete --wait $vm
openstack server delete --wait "${vm}"
done
echo "Destroying cirros image..."
openstack image delete cirros
}
while getopts ":a:n:k:i:fh" opt; do
while getopts ":a:n:k:i:fhd" opt; do
case $opt in
a)
ACTION="$OPTARG"
@ -81,6 +98,9 @@ while getopts ":a:n:k:i:fh" opt; do
f)
ADD_FLOATING="yes"
;;
d)
PRINT_STD="yes"
;;
h)
usage
exit 1
@ -98,6 +118,11 @@ while getopts ":a:n:k:i:fh" opt; do
esac
done
if [ -z "${K8S_NAMESPACE}" ] && [ -n "${PRINT_STD}"]; then
echo "To print debug to stdout you need to set K8S namespace with -k parameter"
exit 1
fi
if [ -z "$ACTION" ]; then
usage
exit 1