Skip to content

command exection embedding fixes

Filip Pokryvka requested to merge fp/embed into master

Unify subprocess calls and pexpects. Embed stdout stderr and exitcode only if test fails (to save space). Subprocess.Popen with redirected output sometimes creates zombie processes, use pexpect instead. For pexpect there is context.pexpect_spawn which creates process that does not survive to the next step (gets killed in after_step). To avoid this, use context.pexpect_service, which survives to the end of the test (and gets killed in after_scenario). In subprocess there is context.run, which returns triple (stdou, stderr, exitcode), by default stderr is None because it is redirected to stdout. There is also context.command_output which returns just stdout (again by default merged with stderr), and asserts if exitcode is non-zero. context.command_code jut returns exitcode. There are equivalent calls from nmci library (nmci.run, nmci.command_code, nmci.command_output), that do the same except their output is not embedded to the html (use only if output is never interesting, e.g. being embedded afterwards by other function, or if context is not available - e.g. unit test).

Rework embedding: tweak embed function to suit our needs, create "Before/After Scenario" step in HTML if embed happens there. Add fail_only arg to embed function, which causes embed only if fail.

Add NMCI_DEBUG detection, which if set as environment variable to non-false value ("n", "no", "f", "false", "0" are false values), all embeds with fail_only=True are embedded even if scenario passes (usefull during tests development to check if commands produce expected outputs).

Remove old logs (caption MAIN) and prints, use new embed syntax (with fail_only attribute). Split it to "Status before", "Status after" and "Status after clean" (and command calls embedded to steps). Also, embed "Status after clean" status by default, instead of "Status Before".

@RunTests:*

Edited by Filip Pokryvka

Merge request reports