summaryrefslogtreecommitdiffstats
path: root/selftest/process_test.py
blob: 71523c9df26156324b75e7fc997d4e4f1e26a69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3

import _prep
import time
import os

from osmo_gsm_tester import process, util, log

tmpdir = util.Dir(util.get_tempdir())

dollar_path = '%s:%s' % (
    os.path.join(os.getcwd(), 'process_test'),
    os.getenv('PATH'))

p = process.Process('foo', tmpdir, ('foo.py', 'arg1', 'arg2'),
                    env={'PATH': dollar_path})

p.launch()
time.sleep(.5)
p.poll()
print('stdout:')
print(p.get_stdout())
print('stderr:')
print(p.get_stderr())

assert not p.terminated()
p.terminate()
assert p.terminated()
print('result: %r' % p.result)

print('stdout:')
print(p.get_stdout())
print('stderr:')
print(p.get_stderr())
print('done.')

test_ssh = True
test_ssh = False
if test_ssh:
    # this part of the test requires ability to ssh to localhost
    p = process.RemoteProcess('ssh-test', '/tmp', os.getenv('USER'), 'localhost', tmpdir,
                              ('ls', '-al'))
    p.launch()
    p.wait()
    assert p.terminated()
    print('stdout:')
    print(p.get_stdout())
    print('stderr:')
    print(p.get_stderr())

# vim: expandtab tabstop=4 shiftwidth=4