mirror of
https://passt.top/passt
synced 2025-05-23 17:55:34 +02:00
test: Use context system for guest commands
Extends the context system in the test scripts to allow executing commands within a guest. Do this without requiring an existing network in the guest by using socat to run ssh via a vsock connection. We do need some additional "sleep"s in the tests, because the new faster dispatch means that sometimes we attempt to connect before socat has managed to listen. For now, only use this for the plain "passt" tests. The "passt_in_ns" and other tests have additional complications we still need to deal with. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
a8a437abd6
commit
56e755ba11
10 changed files with 90 additions and 16 deletions
|
@ -41,12 +41,38 @@ context_setup_nsenter() {
|
|||
echo "nsenter $@ sh -c" > "${__prefix}.enter"
|
||||
}
|
||||
|
||||
# context_setup_guest() - Create a new context for running commands in a guest
|
||||
# $1: Context name
|
||||
# $2: CID to use for vsock
|
||||
context_setup_guest() {
|
||||
__name="$1"
|
||||
__cid="$2"
|
||||
__prefix="${LOGDIR}/context_${__name}"
|
||||
context_setup_common "${__name}"
|
||||
|
||||
cat > "${__prefix}.ssh" <<EOF
|
||||
Host ${__name}
|
||||
User root
|
||||
UserKnownHostsFile ${__prefix}.hosts
|
||||
StrictHostKeyChecking no
|
||||
IdentityFile ${BASEPATH}/guest-key
|
||||
IdentityAgent none
|
||||
ProxyCommand socat - VSOCK-CONNECT:${__cid}:22
|
||||
EOF
|
||||
echo "ssh -F ${__prefix}.ssh ${__name}" > "${__prefix}.enter"
|
||||
|
||||
# Wait for the guest to be booted and accepting connections
|
||||
while ! ssh -F "${__prefix}.ssh" "${__name}" :; do
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
# context_teardown() - Remove a context (leave log files intact)
|
||||
# $1: Context name
|
||||
context_teardown() {
|
||||
__name="$1"
|
||||
__prefix="${LOGDIR}/context_${__name}"
|
||||
rm -f "${__prefix}.enter"
|
||||
rm -f "${__prefix}.enter" "${__prefix}.ssh" "${__prefix}.hosts"
|
||||
}
|
||||
|
||||
# context_exists() - Test if a context currently exists
|
||||
|
|
|
@ -92,15 +92,13 @@ layout_passt() {
|
|||
|
||||
get_info_cols
|
||||
|
||||
tmux pipe-pane -O -t ${PANE_GUEST} "cat >> ${LOGDIR}/pane_guest.log"
|
||||
tmux select-pane -t ${PANE_GUEST} -T "guest"
|
||||
|
||||
tmux send-keys -l -t ${PANE_INFO} 'while cat /tmp/.passt_test_log_pipe; do :; done'
|
||||
tmux send-keys -t ${PANE_INFO} -N 100 C-m
|
||||
tmux select-pane -t ${PANE_INFO} -T "test log"
|
||||
|
||||
pane_watch_contexts ${PANE_HOST} host host
|
||||
pane_watch_contexts ${PANE_PASST} passt passt
|
||||
pane_watch_contexts ${PANE_GUEST} guest qemu guest
|
||||
|
||||
info_layout "single passt instance with guest"
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ setup_distro() {
|
|||
setup_passt() {
|
||||
context_setup_host host
|
||||
context_setup_host passt
|
||||
context_setup_host qemu
|
||||
|
||||
layout_passt
|
||||
|
||||
|
@ -55,7 +56,8 @@ setup_passt() {
|
|||
context_run_bg passt "valgrind --max-stackframe=$((4 * 1024 * 1024)) --trace-children=yes --vgdb=no --error-exitcode=1 --suppressions=test/valgrind.supp ./passt ${__opts} -f -t 10001 -u 10001 -P passt.pid"
|
||||
sleep 5
|
||||
|
||||
pane_run GUEST './qrap 5 qemu-system-$(uname -m)' \
|
||||
GUEST_CID=94557
|
||||
context_run_bg qemu './qrap 5 qemu-system-$(uname -m)' \
|
||||
' -machine accel=kvm' \
|
||||
' -m '${VMEM}' -cpu host -smp '${VCPUS} \
|
||||
' -kernel ' "/boot/vmlinuz-$(uname -r)" \
|
||||
|
@ -65,8 +67,10 @@ setup_passt() {
|
|||
'virtio-net.napi_tx=1"' \
|
||||
" -device virtio-net-pci,netdev=hostnet0,x-txburst=16384" \
|
||||
" -netdev socket,fd=5,id=hostnet0" \
|
||||
' -pidfile passt_qemu.pid'
|
||||
pane_status GUEST
|
||||
" -pidfile passt_qemu.pid" \
|
||||
" -device vhost-vsock-pci,guest-cid=$GUEST_CID"
|
||||
|
||||
context_setup_guest guest $GUEST_CID
|
||||
}
|
||||
|
||||
# setup_pasta() - Create a network and user namespace, connect pasta to it
|
||||
|
@ -307,11 +311,12 @@ teardown_distro() {
|
|||
# teardown_passt() - Kill qemu, remove passt PID file
|
||||
teardown_passt() {
|
||||
kill $(cat passt_qemu.pid)
|
||||
pane_wait GUEST
|
||||
|
||||
rm passt.pid
|
||||
|
||||
teardown_context_watch ${PANE_HOST} host
|
||||
teardown_context_watch ${PANE_PASST} passt
|
||||
teardown_context_watch ${PANE_GUEST} qemu guest
|
||||
}
|
||||
|
||||
# teardown_passt() - Exit namespace, kill pasta process
|
||||
|
|
|
@ -266,7 +266,8 @@ pane_or_context_run() {
|
|||
__name="${1}"
|
||||
shift
|
||||
if context_exists "${__name}"; then
|
||||
context_run "${__name}" "$@" >/dev/null 2>&1
|
||||
# Redirect stdin to stop ssh from eating the test instructions file we have on stdin
|
||||
context_run "${__name}" "$@" >/dev/null 2>&1 < /dev/null
|
||||
else
|
||||
__uc="$(echo "${__name}" | tr [a-z] [A-Z])"
|
||||
pane_run "${__uc}" "$@"
|
||||
|
@ -281,7 +282,8 @@ pane_or_context_run_bg() {
|
|||
__name="${1}"
|
||||
shift
|
||||
if context_exists "${__name}"; then
|
||||
context_run_bg "${__name}" "$@" >/dev/null 2>&1
|
||||
# Redirect stdin to stop ssh from eating the test instructions file we have on stdin
|
||||
context_run_bg "${__name}" "$@" >/dev/null 2>&1 < /dev/null
|
||||
else
|
||||
__uc="$(echo "${__name}" | tr [a-z] [A-Z])"
|
||||
pane_run "${__uc}" "$@"
|
||||
|
@ -295,7 +297,8 @@ pane_or_context_output() {
|
|||
__name="${1}"
|
||||
shift
|
||||
if context_exists "${__name}"; then
|
||||
__output=$(context_run "${__name}" "$@" 2>/dev/null)
|
||||
# Redirect stdin to stop ssh from eating the test instructions file we have on stdin
|
||||
__output=$(context_run "${__name}" "$@" 2>/dev/null </dev/null)
|
||||
if [ -z "${__output}" ]; then
|
||||
echo "@EMPTY@"
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue