From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A8A1D5A027E for ; Wed, 31 May 2023 03:59:04 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QWC9S2wzZz4x4P; Wed, 31 May 2023 11:58:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1685498332; bh=0zKRgWHXoVZ4KeKHxRO3JjEhqbaUdlNbcNu9Z+y0bTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewQkOu+rYA+U37LIMhvwQBXiHzSdiyWHQGQju2MBfD8lO9BBgENybKho3y6aJ1Qw/ DxnDKwDadwyJSrt4/Z0UGbtzPiMM0GUUpoBIuDNTC29RtG7RNbBEAW6uUCJC9lmVrw R+JKnL8gRVJHln/IO6gIbeISsHZ3rSBYBDpcV66M= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v3 07/20] avocado/tasst: Add helpers for running background commands on sites Date: Wed, 31 May 2023 11:58:36 +1000 Message-Id: <20230531015849.3229596-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531015849.3229596-1-david@gibson.dropbear.id.au> References: <20230531015849.3229596-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GREODT4XRUOGTUXIKLI47S7OVG4SM5SL X-Message-ID-Hash: GREODT4XRUOGTUXIKLI47S7OVG4SM5SL X-MailFrom: dgibson@gandalf.ozlabs.org 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: Cleber Rosa , jarichte@redhat.com, David Gibson 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: Signed-off-by: David Gibson --- avocado/tasst/site.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/avocado/tasst/site.py b/avocado/tasst/site.py index 415a953..6aa83c4 100644 --- a/avocado/tasst/site.py +++ b/avocado/tasst/site.py @@ -40,6 +40,9 @@ class Site(contextlib.AbstractContextManager): def fg(self, cmd, **kwargs): self.output(cmd, **kwargs) + def bg(self, cmd, **kwargs): + raise NotImplementedError + def require_cmds(self, *cmds): missing = [c for c in cmds if self.fg('type {}'.format(c), ignore_status=True) != 0] @@ -75,6 +78,18 @@ class SiteTasst(Tasst): out = site.output('echo {}'.format(s)) self.assertEquals(out, s.encode('utf-8')) + def test_bg_true(self): + with self.setup_site() as site: + with site.bg('true') as proc: + status = proc.wait() + self.assertEquals(status, 0) + + def test_bg_false(self): + with self.setup_site() as site: + with site.bg('false') as proc: + status = proc.wait() + self.assertNotEquals(status, 0) + # Represents the host on which the tests are running, as opposed to # some simulated host created by the tests @@ -96,6 +111,16 @@ class RealHost(Site): assert not sudo, "BUG: Shouldn't run commands with privilege on host" return avocado.utils.process.system(cmd, **kwargs) + @contextlib.contextmanager + def bg(self, cmd, sudo=False, **kwargs): + assert not sudo, "BUG: Shouldn't run commands with privilege on host" + try: + proc = avocado.utils.process.SubProcess(cmd, **kwargs) + proc.start() + yield proc + finally: + proc.stop() + REAL_HOST = RealHost() -- 2.40.1