|
24 | 24 | class BaseFunctionalTest(utils.BaseTestCase): |
25 | 25 |
|
26 | 26 | def _run(self, executable, action, |
27 | | - flags='', params='', fmt='-f json', has_output=True): |
| 27 | + flags='', params='', fmt='-f json', stdin=None, has_output=True): |
28 | 28 | if not has_output: |
29 | 29 | fmt = '' |
30 | 30 | cmd = ' '.join([executable, flags, action, params, fmt]) |
31 | 31 | cmd = shlex.split(cmd) |
32 | | - p = subprocess.Popen(cmd, env=os.environ.copy(), shell=False, |
33 | | - stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
34 | | - stdout, stderr = p.communicate() |
| 32 | + p = subprocess.Popen( |
| 33 | + cmd, env=os.environ.copy(), shell=False, |
| 34 | + stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 35 | + stdin=subprocess.PIPE if stdin else None, |
| 36 | + ) |
| 37 | + stdout, stderr = p.communicate(input=stdin) |
35 | 38 | if p.returncode != 0: |
36 | 39 | raise RuntimeError('"{cmd}" returned {val}: {msg}'.format( |
37 | 40 | cmd=' '.join(cmd), val=p.returncode, msg=stderr)) |
38 | 41 | return json.loads(stdout) if has_output else None |
39 | 42 |
|
40 | 43 | def openstack(self, action, |
41 | | - flags='', params='', fmt='-f json', has_output=True): |
| 44 | + flags='', params='', fmt='-f json', |
| 45 | + stdin=None, has_output=True): |
42 | 46 | return self._run('openstack rating', action, |
43 | | - flags, params, fmt, has_output) |
| 47 | + flags, params, fmt, stdin, has_output) |
44 | 48 |
|
45 | 49 | def cloudkitty(self, action, |
46 | | - flags='', params='', fmt='-f json', has_output=True): |
47 | | - return self._run('cloudkitty', action, flags, params, fmt, has_output) |
| 50 | + flags='', params='', fmt='-f json', |
| 51 | + stdin=None, has_output=True): |
| 52 | + return self._run('cloudkitty', action, flags, params, fmt, |
| 53 | + stdin, has_output) |
0 commit comments