From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 517845A026D for ; Wed, 5 Apr 2023 13:59:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680695956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SPRBnvuoavn8xHIxP2yuMAOW8XSrHyV6bbZ3dJjqHMg=; b=UNU50ZITJ10YJHXCr7VW3KSnUP/ajDy6G9Tb5utYM0C8/KgIG5i/9FzDf2Sm/N+WnsXxL0 OmM802JqJd6vnST/uQEt1Z3rxeFIgE+CIoxAmAJvjXILSW+plN2wlsPa7ZhRQpzkLWf2JC O4yz9iO+WEV9VrQH5MDtlKizpbKAEps= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-130-U3mx5Uc6N-uEzzHIPyCUxg-1; Wed, 05 Apr 2023 07:59:15 -0400 X-MC-Unique: U3mx5Uc6N-uEzzHIPyCUxg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06CBA3847083; Wed, 5 Apr 2023 11:59:15 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E7741121314; Wed, 5 Apr 2023 11:59:14 +0000 (UTC) Date: Wed, 5 Apr 2023 13:59:12 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 12/14] test: Use "nstool exec" to slightly simplify tests Message-ID: <20230405135912.4b40c5a0@elisabeth> In-Reply-To: <20230404014638.3225556-13-david@gibson.dropbear.id.au> References: <20230404014638.3225556-1-david@gibson.dropbear.id.au> <20230404014638.3225556-13-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: RWPXXLPSKCTJMEYEKVFM7J2WKXVFW4WP X-Message-ID-Hash: RWPXXLPSKCTJMEYEKVFM7J2WKXVFW4WP X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 4 Apr 2023 11:46:36 +1000 David Gibson wrote: > Using this, rather than using "nstool info" to get the pid then manually > connecting with nsenter makes things a little simpler. > > Signed-off-by: David Gibson > --- > test/lib/context | 14 +++++++++----- > test/lib/setup | 33 +++++++++++++-------------------- > test/run | 2 +- > 3 files changed, 23 insertions(+), 26 deletions(-) > > diff --git a/test/lib/context b/test/lib/context > index ee6b683..d9d8260 100644 > --- a/test/lib/context > +++ b/test/lib/context > @@ -13,6 +13,8 @@ > # Copyright Red Hat > # Author: David Gibson > > +NSTOOL="${BASEPATH}/nstool" > + > # context_setup_common() - Create outline of a new context > # $1: Context name > context_setup_common() { > @@ -30,15 +32,17 @@ context_setup_host() { > echo sh -c > "${__enter}" > } > > -# context_setup_nsenter() - Create a new context for running commands in a namespace > +# context_setup_nstool() - Create a new context for running commands with nstool exec > # $1: Context name > -# $2: Namespace PID > -context_setup_nsenter() { > +# $2: nstool control socket > +context_setup_nstool() { > __name="$1" > - shift > + __sock="$2" > __enter="${STATESETUP}/context_${__name}.enter" > + # Wait for the ns to be ready > + ${NSTOOL} info -w "${__sock}" > /dev/null Bad indentation here. > context_setup_common "${__name}" > - echo "nsenter $@ sh -c" > "${__enter}" > + echo "${NSTOOL} exec ${__sock} -- sh -c" > "${__enter}" > } > > # context_setup_guest() - Create a new context for running commands in a guest > diff --git a/test/lib/setup b/test/lib/setup > index 6d7644a..7b17336 100755 > --- a/test/lib/setup > +++ b/test/lib/setup > @@ -17,7 +17,6 @@ INITRAMFS="${BASEPATH}/mbuto.img" > VCPUS="$( [ $(nproc) -ge 8 ] && echo 6 || echo $(( $(nproc) / 2 + 1 )) )" > __mem_kib="$(sed -n 's/MemTotal:[ ]*\([0-9]*\) kB/\1/p' /proc/meminfo)" > VMEM="$((${__mem_kib} / 1024 / 4))" > -NSTOOL="${BASEPATH}/nstool" > > # setup_build() - Set up pane layout for build tests > setup_build() { > @@ -78,9 +77,8 @@ setup_pasta() { > layout_pasta > > context_run_bg unshare "unshare -rUnpf ${NSTOOL} hold ${STATESETUP}/ns.hold" > - __target_pid=$(${NSTOOL} info -pw ${STATESETUP}/ns.hold) > > - context_setup_nsenter ns -U -n -p --preserve-credentials -t ${__target_pid} > + context_setup_nstool ns ${STATESETUP}/ns.hold > > # Ports: > # > @@ -94,7 +92,7 @@ setup_pasta() { > [ ${DEBUG} -eq 1 ] && __opts="${__opts} -d" > [ ${TRACE} -eq 1 ] && __opts="${__opts} --trace" > > - context_run_bg passt "./pasta ${__opts} -f -t 10002 -T 10003 -u 10002 -U 10003 -P ${STATESETUP}/passt.pid ${__target_pid}" > + context_run_bg passt "./pasta ${__opts} -f -t 10002 -T 10003 -u 10002 -U 10003 -P ${STATESETUP}/passt.pid $(${NSTOOL} info -pw ${STATESETUP}/ns.hold)" > > # pidfile isn't created until pasta is ready > wait_for [ -f "${STATESETUP}/passt.pid" ] > @@ -128,11 +126,10 @@ setup_passt_in_ns() { > > context_run_bg pasta "./pasta ${__opts} -t 10001,10002,10011,10012 -T 10003,10013 -u 10001,10002,10011,10012 -U 10003,10013 -P ${STATESETUP}/pasta.pid --config-net ${NSTOOL} hold ${STATESETUP}/ns.hold" > wait_for [ -f "${STATESETUP}/pasta.pid" ] > - __ns_pid=$(${NSTOOL} info -pw ${STATESETUP}/ns.hold) > > - context_setup_nsenter qemu "-t ${__ns_pid} -U -n -p --preserve-credentials" > - context_setup_nsenter ns "-t ${__ns_pid} -U -n -p --preserve-credentials" > - context_setup_nsenter passt "-t ${__ns_pid} -U -n -p --preserve-credentials" > + context_setup_nstool qemu ${STATESETUP}/ns.hold > + context_setup_nstool ns ${STATESETUP}/ns.hold > + context_setup_nstool passt ${STATESETUP}/ns.hold > > __opts= > [ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/passt_in_pasta.pcap" > @@ -190,19 +187,17 @@ setup_two_guests() { > [ ${DEBUG} -eq 1 ] && __opts="${__opts} -d" > [ ${TRACE} -eq 1 ] && __opts="${__opts} --trace" > context_run_bg pasta_1 "./pasta ${__opts} --trace -l /tmp/pasta1.log -P ${STATESETUP}/pasta_1.pid -t 10001,10002 -T 10003,10004 -u 10001,10002 -U 10003,10004 --config-net ${NSTOOL} hold ${STATESETUP}/ns1.hold" > - __ns1_pid=$(${NSTOOL} info -pw ${STATESETUP}/ns1.hold) > - context_setup_nsenter passt_1 -U -n -p --preserve-credentials -t ${__ns1_pid} > + context_setup_nstool passt_1 ${STATESETUP}/ns1.hold > > __opts= > [ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_2.pcap" > [ ${DEBUG} -eq 1 ] && __opts="${__opts} -d" > [ ${TRACE} -eq 1 ] && __opts="${__opts} --trace" > context_run_bg pasta_2 "./pasta ${__opts} --trace -l /tmp/pasta2.log -P ${STATESETUP}/pasta_2.pid -t 10004,10005 -T 10003,10001 -u 10004,10005 -U 10003,10001 --config-net ${NSTOOL} hold ${STATESETUP}/ns2.hold" > - __ns2_pid=$(${NSTOOL} info -pw ${STATESETUP}/ns2.hold) > - context_setup_nsenter passt_2 -U -n -p --preserve-credentials -t ${__ns2_pid} > + context_setup_nstool passt_2 ${STATESETUP}/ns2.hold > > - context_setup_nsenter qemu_1 -U -n -p --preserve-credentials -t ${__ns1_pid} > - context_setup_nsenter qemu_2 -U -n -p --preserve-credentials -t ${__ns2_pid} > + context_setup_nstool qemu_1 ${STATESETUP}/ns1.hold > + context_setup_nstool qemu_2 ${STATESETUP}/ns2.hold > > __ifname="$(context_run qemu_1 "ip -j link show | jq -rM '.[] | select(.link_type == \"ether\").ifname'")" > > @@ -310,15 +305,13 @@ teardown_passt_in_ns() { > > # teardown_two_guests() - Exit namespaces, kill qemu processes, passt and pasta > teardown_two_guests() { > - __ns1_pid=$(${NSTOOL} info -pw "${STATESETUP}/ns1.hold") > - __ns2_pid=$(${NSTOOL} info -pw "${STATESETUP}/ns2.hold") > - nsenter -U -p --preserve-credentials -t ${__ns1_pid} kill $(cat "${STATESETUP}/qemu_1.pid") > - nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/qemu_2.pid") > + ${NSTOOL} exec ${STATESETUP}/ns1.hold -- kill $(cat "${STATESETUP}/qemu_1.pid") > + ${NSTOOL} exec ${STATESETUP}/ns2.hold -- kill $(cat "${STATESETUP}/qemu_2.pid") > context_wait qemu_1 > context_wait qemu_2 > > - nsenter -U -p --preserve-credentials -t ${__ns1_pid} kill $(cat "${STATESETUP}/passt_1.pid") > - nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/passt_2.pid") > + ${NSTOOL} exec ${STATESETUP}/ns1.hold -- kill $(cat "${STATESETUP}/passt_1.pid") > + ${NSTOOL} exec ${STATESETUP}/ns2.hold -- kill $(cat "${STATESETUP}/passt_2.pid") ...and here. -- Stefano