Commit a50a2bff authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

cleanup! cleanup! cleanup! cleanup!

 * Change the monitor message type names once again (hope this is
   the final version)
 * Pass -u (unbuffered) to sed to retain the actual output order in
   the log file
 * Fix a bug in helper code where the starting `{' was missing from
   the monitoring messages
parent 44038aae
...@@ -40,6 +40,10 @@ CLEANUP=( ) ...@@ -40,6 +40,10 @@ CLEANUP=( )
ERRORS=( ) ERRORS=( )
WARNINGS=( ) WARNINGS=( )
MSG_TYPE_ERROR="error"
MSG_TYPE_TASK_START="task-start"
MSG_TYPE_TASK_END="task-end"
add_cleanup() { add_cleanup() {
local cmd="" local cmd=""
for arg; do cmd+=$(printf "%q " "$arg"); done for arg; do cmd+=$(printf "%q " "$arg"); done
...@@ -57,13 +61,13 @@ warn() { ...@@ -57,13 +61,13 @@ warn() {
echo "Warning: $@" >&2 echo "Warning: $@" >&2
} }
report_start_task() { report_task_start() {
local type="start-task" local type="$MSG_TYPE_TASK_START"
local timestamp=$(date +%s.%N) local timestamp=$(date +%s.%N)
local name="${PROGNAME}" local name="${PROGNAME}"
report+="\"type\":\"$type\"," report+="{\"type\":\"$type\","
report+="\"timestamp\":$(date +%s.%N)," report+="\"timestamp\":$(date +%s.%N),"
report+="\"name\":\"$name\"}" report+="\"name\":\"$name\"}"
...@@ -85,15 +89,14 @@ json_list() { ...@@ -85,15 +89,14 @@ json_list() {
echo "$report" echo "$report"
} }
report_end_task() { report_task_end() {
local type="$MSG_TYPE_TASK_END"
local type="end-task"
local timestam=$(date +%s.%N) local timestam=$(date +%s.%N)
local name=${PROGNAME} local name=${PROGNAME}
local warnings=$(json_list WARNINGS[@]) local warnings=$(json_list WARNINGS[@])
report="\"type\":\"$type\"," report="{\"type\":\"$type\","
report+="\"timestamp\":$(date +%s)," report+="\"timestamp\":$(date +%s.%N),"
report+="\"name\":\"$name\"," report+="\"name\":\"$name\","
report+="\"warnings\":\"$warnings\"}" report+="\"warnings\":\"$warnings\"}"
...@@ -101,14 +104,14 @@ report_end_task() { ...@@ -101,14 +104,14 @@ report_end_task() {
} }
report_error() { report_error() {
local type="ganeti-error" local type="$MSG_TYPE_ERROR"
local timestamp=$(date +%s.%N) local timestamp=$(date +%s.%N)
local location="${PROGNAME}" local location="${PROGNAME}"
local errors=$(json_list ERRORS[@]) local errors=$(json_list ERRORS[@])
local warnings=$(json_list WARNINGS[@]) local warnings=$(json_list WARNINGS[@])
local stderr="$(cat "$STDERR_FILE" | sed 's/"/\\"/g')" local stderr="$(cat "$STDERR_FILE" | sed 's/"/\\"/g')"
report="\"type\":\"$type\"," report="{\"type\":\"$type\","
report+="\"timestamp\":$(date +%s)," report+="\"timestamp\":$(date +%s),"
report+="\"location\":\"$location\"," report+="\"location\":\"$location\","
report+="\"errors\":$errors," report+="\"errors\":$errors,"
...@@ -400,7 +403,7 @@ task_cleanup() { ...@@ -400,7 +403,7 @@ task_cleanup() {
rc=$? rc=$?
if [ $rc -eq 0 ]; then if [ $rc -eq 0 ]; then
report_end_task report_task_end
else else
report_error report_error
fi fi
......
...@@ -27,7 +27,7 @@ set -e ...@@ -27,7 +27,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +27,7 @@ set -e ...@@ -27,7 +27,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
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"
......
...@@ -28,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -35,7 +35,7 @@ set -e ...@@ -35,7 +35,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
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"
......
...@@ -28,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# Check if the task should be prevented from running. # Check if the task should be prevented from running.
check_if_excluded check_if_excluded
......
...@@ -29,7 +29,7 @@ set -e ...@@ -29,7 +29,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
# 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,7 +28,7 @@ set -e ...@@ -28,7 +28,7 @@ set -e
. "@commondir@/common.sh" . "@commondir@/common.sh"
trap task_cleanup EXIT trap task_cleanup EXIT
report_start_task report_task_start
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"
......
...@@ -27,7 +27,7 @@ CURL="curl" ...@@ -27,7 +27,7 @@ CURL="curl"
network_backend_support="@network_backend_support@" network_backend_support="@network_backend_support@"
ERROR_TYPE="ganeti-error" MSG_TYPE_ERROR="error"
CLEANUP=( ) CLEANUP=( )
ERROR_MSGS=( ) ERROR_MSGS=( )
...@@ -52,7 +52,7 @@ report_error() { ...@@ -52,7 +52,7 @@ report_error() {
local error_file=$1 local error_file=$1
local monitor_fd=$2 local monitor_fd=$2
local type="$ERROR_TYPE" local type="$MSG_TYPE_ERROR"
local location="host" local location="host"
local msg="[" local msg="["
......
...@@ -32,6 +32,7 @@ import prctl ...@@ -32,6 +32,7 @@ import prctl
import signal import signal
import socket import socket
MSG_TYPE="copy-progress"
def parse_arguments(args): def parse_arguments(args):
from optparse import OptionParser from optparse import OptionParser
...@@ -122,7 +123,7 @@ def main(): ...@@ -122,7 +123,7 @@ def main():
(sys.argv[0], pid, iofname)) (sys.argv[0], pid, iofname))
message = {} message = {}
message['type'] = 'copy-progress' message['type'] = MSG_TYPE
message['total'] = opts.read_bytes message['total'] = opts.read_bytes
while True: while True:
......
...@@ -35,7 +35,7 @@ if [ -n "$PROGRESS_MONITOR" ]; then ...@@ -35,7 +35,7 @@ if [ -n "$PROGRESS_MONITOR" ]; then
{ sleep 1; $PROGRESS_MONITOR "$instance" < "$monitor_pipe" ; } & { sleep 1; $PROGRESS_MONITOR "$instance" < "$monitor_pipe" ; } &
monitor_pid="$!" monitor_pid="$!"
else else
cat "$monitor_pipe" & sed -u 's|^|MONITOR MSG: |g' < "$monitor_pipe" &
monitor_pid="$!" monitor_pid="$!"
fi fi
...@@ -161,7 +161,7 @@ $TIMEOUT -k "$HELPER_HARD_TIMEOUT" "$HELPER_SOFT_TIMEOUT" \ ...@@ -161,7 +161,7 @@ $TIMEOUT -k "$HELPER_HARD_TIMEOUT" "$HELPER_SOFT_TIMEOUT" \
-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" \
2>&1 | sed 's|^|HELPER: |g' 2>&1 | sed -u 's|^|HELPER: |g'
rc=$? rc=$?
set -e set -e
if [ $rc -ne 0 ]; then if [ $rc -ne 0 ]; then
......
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