The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3175
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === lxc2 broke this feature for lxc-execute, and lxc3 broke it for lxc-attach. This adds a test making sure we don't do the same mistake a third time.
From 2c44fc3d0fdd006a93790fe43f4c3902c583a0b1 Mon Sep 17 00:00:00 2001 From: Florian Margaine <flor...@platform.sh> Date: Tue, 29 Oct 2019 10:53:17 +0100 Subject: [PATCH] tests: add tests making sure the exit code is appropriate. lxc2 broke this feature for lxc-execute, and lxc3 broke it for lxc-attach. This adds a test making sure we don't do the same mistake a third time. --- src/tests/Makefile.am | 1 + src/tests/lxc-test-exit-code | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 src/tests/lxc-test-exit-code diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 309212e9c9..6fad5c18ca 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -83,6 +83,7 @@ bin_PROGRAMS = lxc-test-api-reboot \ lxc-test-cve-2019-5736 \ lxc-test-destroytest \ lxc-test-device-add-remove \ + lxc-test-exit-code \ lxc-test-getkeys \ lxc-test-get_item \ lxc-test-list \ diff --git a/src/tests/lxc-test-exit-code b/src/tests/lxc-test-exit-code new file mode 100755 index 0000000000..21c6dc7f3d --- /dev/null +++ b/src/tests/lxc-test-exit-code @@ -0,0 +1,53 @@ +#!/bin/sh + +# lxc: linux Container library + +# Authors: +# Florian Margaine <flor...@platform.sh> +# +# This is a test script for the lxc-attach and lxc-execute +# programs. It tests whether the exit code is not 0 when a script +# fails to execute. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +set -e + +FAIL() { + echo -n "Failed " >&2 + echo "$*" >&2 + lxc-destroy -n busy -f + exit 1 +} + +# Create a container +lxc-create -t busybox -n busy || FAIL "creating busybox container" + +# Run lxc-execute to make sure it fails when the command fails, and +# succeed when the command succeeds. +lxc-execute -n busy -- sh -c 'exit 1' && FAIL "should be failing" || true +lxc-execute -n busy -- sh -c 'exit 0' || FAIL "should be succeeding" + +# Now, start the container and wait for it to be in running state. +lxc-start -n busy -d || FAIL "starting busybox container" +lxc-wait -n busy -s RUNNING || FAIL "waiting for busybox container to run" + +# And run the same tests on lxc-attach. +lxc-attach -n busy -- sh -c 'exit 1' && FAIL "should be failing" || true +lxc-attach -n busy -- sh -c 'exit 0' || FAIL "should be failing" + +lxc-destroy -n busy -f + +exit 0
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel