Skip to content

Commit

Permalink
tests: API extension "console"
Browse files Browse the repository at this point in the history
Closes canonical#1129.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Nov 14, 2017
1 parent fed48e4 commit f3097a6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/main.sh
Expand Up @@ -189,6 +189,7 @@ run_test test_storage_driver_ceph "ceph storage driver"
run_test test_resources "resources"
run_test test_kernel_limits "kernel limits"
run_test test_macaroon_auth "macaroon authentication"
run_test test_console "console"

# shellcheck disable=SC2034
TEST_RESULT=success
83 changes: 83 additions & 0 deletions test/suites/console.sh
@@ -0,0 +1,83 @@
test_console() {
ensure_import_testimage

lxc init testimage cons1

# 1. Set a console log file but no ringbuffer.

# Test the console log file requests.
lxc start cons1

# No console log file set so this should return an error.
! lxc console cons1 --show-log
lxc stop --force cons1

# Set a console log file but no ringbuffer.
# shellcheck disable=SC2034
CONSOLE_LOGFILE="$(mktemp -p "${LXD_DIR}" XXXXXXXXX)"
lxc config set cons1 raw.lxc "lxc.console.logfile=${CONSOLE_LOGFILE}"
lxc start cons1

# Let the container come up. Two seconds should be fine.
sleep 2

# Make sure there's something in the console ringbuffer.
echo 'some content' | lxc exec cons1 -- tee /dev/console

# Console log file set so this should return without an error.
lxc console cons1 --show-log

lxc stop --force cons1

# 2. Set a console ringbuffer but no log file.

# remove logfile
lxc config unset cons1 raw.lxc

# set console ringbuffer
lxc config set cons1 raw.lxc "lxc.console.logsize=auto"

lxc start cons1

# Let the container come up. Two seconds should be fine.
sleep 2

# Make sure there's something in the console ringbuffer.
echo 'some content' | lxc exec cons1 -- tee /dev/console
echo 'some more content' | lxc exec cons1 -- tee /dev/console

# Retrieve the ringbuffer contents.
lxc console cons1 --show-log

# 3. Set a console ringbuffer and a log file.

lxc stop --force cons1

lxc config unset cons1 raw.lxc

rm -f "${CONSOLE_LOGFILE}"
printf "lxc.console.logsize=auto\nlxc.console.logfile=%s" "${CONSOLE_LOGFILE}" | lxc config set cons1 raw.lxc -

lxc start cons1

# Let the container come up. Two seconds should be fine.
sleep 2

# Make sure there's something in the console ringbuffer.
echo 'Ringbuffer contents and log file contents must match' | lxc exec cons1 -- tee /dev/console

# Retrieve the ringbuffer contents.
RINGBUFFER_CONTENT=$(lxc console cons1 --show-log)
# Strip prefix added by the client tool.
RINGBUFFER_CONTENT="${RINGBUFFER_CONTENT#
Console log:
}"
# Give kernel time to sync data to disk
sleep 2
LOGFILE_CONTENT=$(cat "${CONSOLE_LOGFILE}")

[ "${RINGBUFFER_CONTENT}" = "${LOGFILE_CONTENT}" ]

lxc delete --force cons1
}

0 comments on commit f3097a6

Please sign in to comment.