1
0
mirror of https://git.yoctoproject.org/meta-arm synced 2026-05-07 04:58:57 +00:00

arm-autonomy/xenguest-manager: improved logging

Introduced logging functions to unite logging to the console and to
the logfile with different filterable log levels. Also introduced
logrotate to ensure the size of the log does not become excessive.

The Log levels introduced are:
ERROR INFO VERBOSE

By default, both the terminal and the logfile will receive ERROR logs.
More verbose logs can be written to the logfile in two ways:
- passing the parameter "-v" or "-vv" to write info and verbose respectively
- modifying the value of "XENGUEST_MANAGER_LOG_LEVEL" in the host conf file,
  or updating the entry it creates in the config file
  /etc/xenguest/xenguest-manager.conf

The order of precedence is as listed above

Issue-Id: SCM-1516
Signed-off-by: Nathan Dunne <Nathan.Dunne@arm.com>
Change-Id: I47f74802ed31a5bff12305eab707e009af7e5398
Signed-off-by: Jon Mason <jon.mason@arm.com>
This commit is contained in:
Nathan Dunne
2020-12-16 11:45:07 +00:00
committed by Jon Mason
parent 35adaace0e
commit 7a3e9d5087
6 changed files with 435 additions and 219 deletions
@@ -23,7 +23,7 @@ Usage
-----
xenguest-manager must be called like this:
`xenguest-manager OPERATION [OPTIONS]`
`xenguest-manager [-v(v)] OPERATION [OPTIONS]`
The following operations are available:
- create XENGUEST_IMAGE [GUESTNAME]: create a guest from a xenguest image file
as guest GUESTNAME. If GUESTNAME is not given the image file name is used
@@ -37,6 +37,9 @@ The following operations are available:
- status [GUESTNAME]: print the current status of GUESTNAME. If GUESTNAME is
not given, print the status of all guests.
Passing -v or -vv will increase the logging written to the logfile.
The terminal will always show only error messages, regardless of the logfile.
For a detailed help on available options please use:
`xenguest-manager --help`
@@ -65,6 +68,13 @@ The following parameters are available:
name).
This is set by default to "/usr/share/guests".
- XENGUEST_MANAGER_LOG_LEVEL: Set the default log level for xenguest manager. Must
be one of ERROR, INFO, VERBOSE (default: ERROR). The extra will be
written to /var/log/xenguest.
If a verbosity argument (-v or -vv) is passed to xenguest-manager directly, it
will override the setting in xenguest-manager.conf
Init scripts
------------
@@ -80,7 +90,7 @@ directory on the target:
Inside the directory, scripts will be executed in alphabetical order.
Since these scripts are sourced by xenguest-manager they can acccess functions
Since these scripts are sourced by xenguest-manager, they can acccess functions
and variables from the parent file's scope, including:
- ${guestname} : The name of the guest being created
@@ -89,12 +99,31 @@ and variables from the parent file's scope, including:
- ${guestcfgfile} : The name of the config file for the starting guest
- ${LOGFILE} : The file to append any logging to, e.g.
echo "Hello, World" >> ${LOGFILE}
- log() : Used to write a log to the logfile, default level INFO.
Takes an optional log level and a message body
e.g. log ERROR "blah"
Options for log level: ERROR, INFO, VERBOSE, and FATAL, which
will call exit 1 immediately after logging the message
- log_command() : Used to call a shell command and log that it has been
called, as well as capturing both stdout and stderr.
By default the command output is dumped to the logfile as an error
if the command returns a status > 0, or as a verbose message if the
whole script is running in verbose mode. An optional log level can
be passed to alter the level the log should be if the command returns
a status >0,
e.g. log_command INFO "ls -lh ~"
Options for log level: ERROR, INFO, and VERBOSE
Attempting to call any other functions from xenguest_manager in an init script may
result in a fatal error, from which cleanup is not guarenteed.
Sourcing also allows the script to access params.cfg.
An example of how to create the directory and install an init shell script can
be found in:
recipes-extended/xenguest/xenguest-network.bb
@@ -0,0 +1,6 @@
/var/log/xenguest {
missingok
size 10k
copytruncate
rotate 2
}
@@ -11,11 +11,13 @@ BRIDGE_NAME="###BRIDGE_NAME###"
case "${XENGUEST_NETWORK_TYPE:=}" in
nat)
echo "vif = ['script=vif-nat']" >> ${guestcfgfile}
log info "Network type is NAT"
;;
bridge)
echo "vif = ['script=vif-bridge,bridge=${BRIDGE_NAME}']" >> ${guestcfgfile}
log info "Network type is bridge: ${BRIDGE_NAME}"
;;
*)
echo "${@}: XENGUEST_NETWORK_TYPE=$XENGUEST_NETWORK_TYPE invalid"
log error "XENGUEST_NETWORK_TYPE=$XENGUEST_NETWORK_TYPE invalid"
;;
esac
File diff suppressed because it is too large Load Diff
@@ -31,15 +31,14 @@ case "${XENGUEST_NETWORK_TYPE:-}" in
release_lock "vif-nat-kea"
exit 0
fi
echo "Waiting for ${vif_name} - network interface is not ready..."\
" try #${try}" >> "${LOGFILE}" 2>&1
log info "Waiting for ${vif_name} - network interface is not ready..."
log info "try #${try}"
sleep 1
done
echo "ERROR: Failed to get ${vif_name} "\
"network interface ready!" >> "${LOGFILE}" 2>&1
log error "Failed to get ${vif_name}. network interface ready!"
exit 1
;;
*)
echo "No action needed" >> "${LOGFILE}" 2>&1
log verbose "No action needed"
;;
esac
@@ -9,6 +9,7 @@ LICENSE = "MIT"
SRC_URI = " \
file://xenguest-manager \
file://xenguest-init \
file://logrotate-xenguest \
"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
@@ -19,6 +20,7 @@ S = "${WORKDIR}"
XENGUEST_MANAGER_VOLUME_DEVICE ?= "/dev/sda2"
XENGUEST_MANAGER_VOLUME_NAME ?= "vg-xen-$(basename ${XENGUEST_MANAGER_VOLUME_DEVICE})"
XENGUEST_MANAGER_GUEST_DIR ?= "${datadir}/guests/"
XENGUEST_MANAGER_LOG_LEVEL ?= "ERROR"
# We add an init script to create and start guests automatically
# run start script after xen-tools and run stop script before xen-tools
@@ -34,6 +36,8 @@ do_compile() {
xenguest-manager.conf
echo "XENGUEST_GUEST_DIR=\"${XENGUEST_MANAGER_GUEST_DIR}\"" >> \
xenguest-manager.conf
echo "XENGUEST_LOG_LEVEL=\"${XENGUEST_MANAGER_LOG_LEVEL}\"" >> \
xenguest-manager.conf
}
do_install() {
@@ -44,10 +48,13 @@ do_install() {
install -d -m 755 ${D}${sysconfdir}/init.d
install -m 755 xenguest-init ${D}${sysconfdir}/init.d/${INITSCRIPT_NAME}
install -d -m 755 ${D}${XENGUEST_GUEST_DIR}
install -d -m 755 ${D}${sysconfdir}/logrotate.d
install -m 644 logrotate-xenguest ${D}${sysconfdir}/logrotate.d/xenguest
}
# Things that we need on the target
RDEPENDS_${PN} += "bash tar xenguest-mkimage lvm2 xen-tools parted e2fsprogs dosfstools"
RDEPENDS_${PN} += "bash tar xenguest-mkimage lvm2 xen-tools parted e2fsprogs \
dosfstools logrotate"
FILES_${PN} += "${bindir}/xenguest-manager \
${sysconfdir}/xenguest"