Add mechanism to send error messages to helper.

Adds a new err_msg function which is used to:

-echo feedback to the deploy ramdisk console
-keep track of the first error message we hit so
 that we can send it along to the baremetal-deploy-helper.

Also, updates our wget request back to baremetal-deploy-helper
to include the first the first error message (if any) as
the 'e' parameter.

The err_msg uses a new simple safe_url_encode function to ensure
we don't send invalid characters in our HTTP post requests.

Change-Id: I5a623a6f66cde8d81ff1e75800dc2953ca2703a8
This commit is contained in:
Dan Prince 2013-06-17 16:38:12 -04:00
parent 0ff82aff46
commit 04bfd491ad
3 changed files with 37 additions and 6 deletions

View file

@ -1,5 +1,5 @@
if [ -z "$ISCSI_TARGET_IQN" ]; then
echo "iscsi_target_iqn is not defined"
err_msg "iscsi_target_iqn is not defined"
troubleshoot
fi
@ -13,19 +13,19 @@ while ! target_disk=$(find_disk "$DISK"); do
done
if [ -z "$target_disk" ]; then
echo "Could not find disk to use."
err_msg "Could not find disk to use."
troubleshoot
fi
echo "start iSCSI target on $target_disk"
start_iscsi_target "$ISCSI_TARGET_IQN" "$target_disk" ALL
if [ $? -ne 0 ]; then
echo "Failed to start iscsi target."
err_msg "Failed to start iscsi target."
troubleshoot
fi
echo "request boot server to deploy image"
d="i=$DEPLOYMENT_ID&k=$DEPLOYMENT_KEY&a=$BOOT_IP_ADDRESS&n=$ISCSI_TARGET_IQN"
d="i=$DEPLOYMENT_ID&k=$DEPLOYMENT_KEY&a=$BOOT_IP_ADDRESS&n=$ISCSI_TARGET_IQN&e=$FIRST_ERR_MSG"
wget --post-data "$d" "http://$BOOT_SERVER:10000"
echo "waiting for notice of complete"

View file

@ -195,3 +195,33 @@ function troubleshoot() {
fi
}
function safe_url_encode() {
local str=$1
local out=""
for (( i=0; i<${#str}; i++ )); do
c=${str:$i:1}
case $c in
[a-zA-Z0-9.-_] )
out+="$c"
;;
' ' )
out+="+"
;;
*)
#skip it
;;
esac
done
echo "$out"
}
function err_msg() {
message=$1
if [ -z "$FIRST_ERR_MSG" ]; then
FIRST_ERR_MSG=$(safe_url_encode "$message")
fi
echo "$message"
}

View file

@ -48,6 +48,7 @@ readonly DEPLOYMENT_ID=$(get_kernel_parameter deployment_id)
readonly DEPLOYMENT_KEY=$(get_kernel_parameter deployment_key)
readonly ISCSI_TARGET_IQN=$(get_kernel_parameter iscsi_target_iqn)
readonly TROUBLESHOOT=$(get_kernel_parameter troubleshoot)
FIRST_ERR_MSG=
mount -t sysfs none /sys
@ -110,7 +111,7 @@ while ! BOOT_INTERFACE=$(find_interface "$BOOT_MAC_ADDRESS"); do
sleep 5
done
if [ -z "$BOOT_INTERFACE" ]; then
echo "could not find an interface owns MAC=$BOOT_MAC_ADDRESS"
err_msg "Could not find an interface that owns MAC: $BOOT_MAC_ADDRESS"
troubleshoot
fi
@ -122,7 +123,7 @@ if [ $? -ne 0 ]; then
sleep 10
ifconfig "$BOOT_INTERFACE" up
if [ $? -ne 0 ]; then
echo "Failed to up $BOOT_INTERFACE"
err_msg "Failed to ifconfig up $BOOT_INTERFACE"
troubleshoot
fi
fi