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