From a8a437abd6c03161c0d7430f969f6a32d046dc29 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Mon, 12 Sep 2022 20:56:21 +1000 Subject: test: Extend context system to run commands in namespace for pasta tests Extend the context system to allow commands to be run in a namespace created with unshare, and use it for the namespace used in the pasta tests. Signed-off-by: David Gibson --- test/lib/context | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test/lib/context') diff --git a/test/lib/context b/test/lib/context index babf59a..0d92d8f 100644 --- a/test/lib/context +++ b/test/lib/context @@ -13,13 +13,32 @@ # Copyright Red Hat # Author: David Gibson +# context_setup_common() - Create outline of a new context +# $1: Context name +context_setup_common() { + __name="$1" + __prefix="${LOGDIR}/context_${__name}" + echo -n "${__name}$ " > "${__prefix}.log" +} + # context_setup_host() - Create a new context for running commands on the host # $1: Context name context_setup_host() { __name="$1" __prefix="${LOGDIR}/context_${__name}" + context_setup_common "${__name}" echo sh -c > "${__prefix}.enter" - echo -n "${__name}$ " > "${__prefix}.log" +} + +# context_setup_nsenter() - Create a new context for running commands in a namespace +# $1: Context name +# $2: Namespace PID +context_setup_nsenter() { + __name="$1" + shift + __prefix="${LOGDIR}/context_${__name}" + context_setup_common "${__name}" + echo "nsenter $@ sh -c" > "${__prefix}.enter" } # context_teardown() - Remove a context (leave log files intact) -- cgit v1.2.3