aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2017-01-17 11:24:41 -0500
committerGreg Hudson <ghudson@mit.edu>2017-01-19 18:16:55 -0500
commit8bb5fce69a4aa6c3082fa7def66a93974e10e17a (patch)
tree2fbd10454171b51fd826fc6444d96cd9bf7c0a8e /src/util
parent7ad7eb7fd591e6c789ea24b94eccbf74ee4d79f8 (diff)
downloadkrb5-8bb5fce69a4aa6c3082fa7def66a93974e10e17a.zip
krb5-8bb5fce69a4aa6c3082fa7def66a93974e10e17a.tar.gz
krb5-8bb5fce69a4aa6c3082fa7def66a93974e10e17a.tar.bz2
Add k5test expected_msg, expected_trace
In k5test.py, add the optional keyword argument "expected_msg" to methods that run commands, to make it easier to look for substrings in the command output. Add the optional keyword "expected_trace" to run the command with KRB5_TRACE enabled and look for an ordered series of substrings in the trace output.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/k5test.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/util/k5test.py b/src/util/k5test.py
index c3d0263..4d30baf 100644
--- a/src/util/k5test.py
+++ b/src/util/k5test.py
@@ -223,8 +223,11 @@ Scripts may use the following realm methods and attributes:
command-line debugging options. Fail if the command does not return
0. Log the command output appropriately, and return it as a single
multi-line string. Keyword arguments can contain input='string' to
- send an input string to the command, and expected_code=N to expect a
- return code other than 0.
+ send an input string to the command, expected_code=N to expect a
+ return code other than 0, expected_msg=MSG to expect a substring in
+ the command output, and expected_trace=('a', 'b', ...) to expect an
+ ordered series of line substrings in the command's KRB5_TRACE
+ output.
* realm.kprop_port(): Returns a port number based on realm.portbase
intended for use by kprop and kpropd.
@@ -647,10 +650,31 @@ def _stop_or_shell(stop, shell, env, ind):
subprocess.call(os.getenv('SHELL'), env=env)
-def _run_cmd(args, env, input=None, expected_code=0):
+# Read tracefile and look for the expected strings in successive lines.
+def _check_trace(tracefile, expected):
+ output('*** Trace output for previous command:\n')
+ i = 0
+ with open(tracefile, 'r') as f:
+ for line in f:
+ output(line)
+ if i < len(expected) and expected[i] in line:
+ i += 1
+ if i < len(expected):
+ fail('Expected string not found in trace output: ' + expected[i])
+
+
+def _run_cmd(args, env, input=None, expected_code=0, expected_msg=None,
+ expected_trace=None):
global null_input, _cmd_index, _last_cmd, _last_cmd_output, _debug
global _stop_before, _stop_after, _shell_before, _shell_after
+ if expected_trace is not None:
+ tracefile = 'testtrace'
+ if os.path.exists(tracefile):
+ os.remove(tracefile)
+ env = env.copy()
+ env['KRB5_TRACE'] = tracefile
+
if (_match_cmdnum(_debug, _cmd_index)):
return _debug_cmd(args, env, input)
@@ -679,6 +703,13 @@ def _run_cmd(args, env, input=None, expected_code=0):
# Check the return code and return the output.
if code != expected_code:
fail('%s failed with code %d.' % (args[0], code))
+
+ if expected_msg is not None and expected_msg not in outdata:
+ fail('Expected string not found in command output: ' + expected_msg)
+
+ if expected_trace is not None:
+ _check_trace(tracefile, expected_trace)
+
return outdata