use nmci.process in lib.py and tags.py
Use new nmci.process
functions (or their context.process
equivalent) in nmci/tags.py
and nmci/lib.py
.
Here follows the summary of the MR, as some diffs might be large. Dividing it to multiple MRs would be possible, but many changes were revealed during the rewrite process.
Summary of changes:
- rename
run_check()
->run_stdout()
asrun_check
was returning STDOUT already. This was relaxed byignore_stderr
,shell
orignore_returncode / run()
only on necessary occurrences (e.g. some tags delete non-existing connections or interfaces to make sure cleanup is done,systemctl
likes to print info messages to STDERR etc.). - rename
run_match_stdout()
->run_search_stdout()
and usere.search
instead ofre.match
as it is more convenient in testing, also usere.DOTALL | re.MULTILINE
flags as default (pattern_flags
have to be unset explicitly when using with pre-compiled pattern). - add
nmci.util.set_file_content(f_name, data)
which replaces many useless subprocess calls, e.g.ctx.run("echo $option >> $conf")
- this can be used to touch a file:
nmci.util.set_file_content(f_name)
- if
data
is iterable (tuple, list, generator, etc.),\n
is appended to each item,\n
is NOT appended if data is of type string or bytes.
- this can be used to touch a file:
- each process call has timeout, timeouts are adjusted in most cases to be sufficiently high, and if there is
TimeoutException
, something is out of ordinary and should be investigated. - some tags were reordered (mainly
eth0
related), so the process calls in other tags were not failing - add
cleanup
tag, which callsnmci.lib.cleanup
, so we can make sure some tags are executed afternmci.lib.cleanup
. -
gsm_sim
andcaptive_portal
prepare scrips were made blocking, or there was hang probably onSTDIN
. To start themcontext.pexpect_service
is used, and they exit cleanly once called with argumentteardown
from the main thread. Old subprocess wrapper supported STDIN redirect, but this solution is much cleaner than adding the support fornmci.process
.
Things to be done and are not part of this MR, as it is huge already:
- use
nmci.ip
instead ofnmci.process
, but that requires some enrichment ofnmci.ip
- add special wrapper for
nmcli
calls, maybesystemctl
too, as we haveignore_stderr
in most cases, maybe that should be treated better (usingsystemctl --quiet ...
, but maybe that also mutes error messages, not sure). - use
nmci.process
in steps
@RunTests:*
@RunFeatures:all
Edited by Filip Pokryvka