Commit 2a0ab295 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add start-task and finish-task events

This commit extendes the monitoring mechanism to include events from
snf-image-helper.
parent 9c76962d
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
# 02110-1301, USA. # 02110-1301, USA.
RESULT=/dev/ttyS1 RESULT=/dev/ttyS1
MONITOR=/dev/ttyS2
FLOPPY_DEV=/dev/fd0 FLOPPY_DEV=/dev/fd0
PROGNAME=$(basename $0) PROGNAME=$(basename $0)
...@@ -35,6 +37,8 @@ REGLOOKUP=reglookup ...@@ -35,6 +37,8 @@ REGLOOKUP=reglookup
CHNTPW=chntpw CHNTPW=chntpw
CLEANUP=( ) CLEANUP=( )
ERRORS=( )
WARNINGS=( )
add_cleanup() { add_cleanup() {
local cmd="" local cmd=""
...@@ -43,14 +47,83 @@ add_cleanup() { ...@@ -43,14 +47,83 @@ add_cleanup() {
} }
log_error() { log_error() {
ERRORS+=("$@")
echo "ERROR: $@" | tee $RESULT >&2 echo "ERROR: $@" | tee $RESULT >&2
exit 1 exit 1
} }
warn() { warn() {
WARNINGS+=("$@")
echo "Warning: $@" >&2 echo "Warning: $@" >&2
} }
report_start_task() {
local id="$SNF_IMAGE_HOSTNAME"
local type="ganeti-start-task"
local timestamp=$(date +%s)
local name="${PROGNAME}"
report="{\"id\":\"$id\","
report+="\"type\":\"$type\"," \
report+="\"timestamp\":$(date +%s)," \
report+="\"name\":\"$name\"}"
echo "$report" > "$MONITOR"
}
json_list() {
declare -a items=("${!1}")
report="["
for item in "${items[@]}"; do
report+="\"$(sed 's/"/\\"/g' <<< "$item")\","
done
if [ ${#report} -gt 1 ]; then
# remove last comma(,)
report="${report%?}"
fi
report+="]"
echo "$report"
}
report_end_task() {
local id="$SNF_IMAGE_HOSTNAME"
local type="ganeti-end-task"
local timestam=$(date +%s)
local name=${PROGNAME}
local warnings=$(json_list WARNINGS[@])
report="{\"id\":\"$id\","
report+="\"type\":\"$type\"," \
report+="\"timestamp\":$(date +%s)," \
report+="\"name\":\"$name\"," \
report+="\"warnings\":\"$warnings\"}"
echo "$report" > "$MONITOR"
}
report_error() {
local id="$SNF_IMAGE_HOSTNAME"
local type="ganeti-error"
local timestamp=$(date +%s)
local location="${PROGNAME}"
local errors=$(json_list ERRORS[@])
local warnings=$(json_list WARNINGS[@])
local stderr="$(cat "$STDERR_FILE" | sed 's/"/\\"/g')"
report="{\"id\":\"$id\","
report+="\"type\":\"$type\"," \
report+="\"timestamp\":$(date +%s)," \
report+="\"location\":\"$location\"," \
report+="\"errors\":$errors," \
report+="\"warnings\":$warnings," \
report+="\"stderr\":\"$stderr\"}"
echo "$report" > "$MONITOR"
}
get_base_distro() { get_base_distro() {
local root_dir=$1 local root_dir=$1
...@@ -329,6 +402,18 @@ cleanup() { ...@@ -329,6 +402,18 @@ cleanup() {
fi fi
} }
task_cleanup() {
rc=$?
if [ $rc -eq 0 ]; then
report_end_task
else
report_error
fi
cleanup
}
check_if_excluded() { check_if_excluded() {
local exclude=SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${PROGNAME:2} local exclude=SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${PROGNAME:2}
...@@ -343,4 +428,8 @@ check_if_excluded() { ...@@ -343,4 +428,8 @@ check_if_excluded() {
trap cleanup EXIT trap cleanup EXIT
set -o pipefail set -o pipefail
STDERR_FILE=$(mktemp)
add_cleanup rm -f "$STDERR_FILE"
exec 2> >(tee -a "$STDERR_FILE" >&2)
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
if [ ! -d "$SNF_IMAGE_TARGET" ]; then if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing" log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing"
fi fi
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
if [ -z "$SNF_IMAGE_TARGET" ]; then if [ -z "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi fi
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -28,6 +28,9 @@ set -e ...@@ -28,6 +28,9 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
set -e set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT
report_start_task
if [ ! -d "$SNF_IMAGE_TARGET" ]; then if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing" log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing"
fi fi
......
...@@ -149,7 +149,8 @@ echo "$(date +%Y:%m:%d-%H:%M:%S.%N) Starting helper VM..." ...@@ -149,7 +149,8 @@ echo "$(date +%Y:%m:%d-%H:%M:%S.%N) Starting helper VM..."
$TIMELIMIT -t "$HELPER_SOFT_TIMEOUT" -T "$HELPER_HARD_TIMEOUT" \ $TIMELIMIT -t "$HELPER_SOFT_TIMEOUT" -T "$HELPER_HARD_TIMEOUT" \
kvm -runas "$HELPER_USER" -drive file="$snapshot" \ kvm -runas "$HELPER_USER" -drive file="$snapshot" \
-drive file="$blockdev",format=raw,if=virtio,cache=none \ -drive file="$blockdev",format=raw,if=virtio,cache=none \
-boot c -serial stdio -serial file:"$result_file" \ -boot c -serial stdio -serial "file:$(printf "%q" "$result_file")" \
-serial "file:$(printf "%q" "$monitor_pipe")" \
-fda "$floppy" -vga none -nographic -parallel none -monitor null \ -fda "$floppy" -vga none -nographic -parallel none -monitor null \
-kernel "$HELPER_KERNEL" -initrd "$HELPER_INITRD" \ -kernel "$HELPER_KERNEL" -initrd "$HELPER_INITRD" \
-append "quiet ro root=/dev/sda1 console=ttyS0,9600n8 snf_image_activate_helper" \ -append "quiet ro root=/dev/sda1 console=ttyS0,9600n8 snf_image_activate_helper" \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment