#5 Add support to run commands in background
Merged by spoore. Opened by mrniranjan.
mrniranjan/python-pytest-multihost master  into  master

Download 5.patch

Currently this patch adds support to run command when Transport class is Paramiko .

Test case added:

# py.test -s -v test_localhost.py::TestLocalhost::test_background[paramiko]
==================  test session starts  =======================
platform linux2 -- Python 2.7.11, pytest-2.9.1, py-1.4.31, pluggy-0.3.1 -- /home/mniranja  /python_proj/bin/python
cachedir: ../.cache
ansible: 2.2.1.0
rootdir: /home/mniranja/source/pagure/python-pytest-multihost, inifile:
plugins: modifyjunit-1.0, ansible-2.0.0, multihost-1.1 collected 23 items
test_localhost.py::TestLocalhost::test_background[paramiko] PASSED
================== 1 passed in 0.54 seconds =======================

Can we simplify this? Maybe:

if not bg:
    command.wait(raiseonerr=raiseonerr)
return command

rebased onto 34529cd92268339c4d46f78bc3b4e457d9f31683

Thanks spoore, added updated patch.

Some more comments about this option. when a command is run with bg=True, there will be no stderr, stdout or returncode . And it's up the user to make sure that the command being run in background is killed in the test case.

We in sssd qe team need this as we would like to run tcpdump and capture packets over ldap to verify certain things. Grepping of logs have never been reliable.

Example:

tcpdump_cmd = 'tcpdump -s0 -w %s port 389' % pcapfile
multihost.master[0].run_command(tcpdump_cmd, bg=True)
pid_cmd = 'pidof tcpdump'
cmd = multihost.master[0].run_command(pid_cmd, raiseonerr=False)
kill_cmd = 'kill -9 %s' % cmd.stdout_text
multihost.master[0].run_command(kill_cmd)
multihost.master[0].transport.get_file(pcapfile, pcapfile)

if the command run in background is not killed , pytest would hang

Pull-Request has been merged by spoore

Metadata