Skip to content

use nmci.process in lib.py and tags.py

Filip Pokryvka requested to merge fp/process into main

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() as run_check was returning STDOUT already. This was relaxed by ignore_stderr, shell or ignore_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 use re.search instead of re.match as it is more convenient in testing, also use re.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.
  • 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 calls nmci.lib.cleanup, so we can make sure some tags are executed after nmci.lib.cleanup.
  • gsm_sim and captive_portal prepare scrips were made blocking, or there was hang probably on STDIN. To start them context.pexpect_service is used, and they exit cleanly once called with argument teardown from the main thread. Old subprocess wrapper supported STDIN redirect, but this solution is much cleaner than adding the support for nmci.process.

Things to be done and are not part of this MR, as it is huge already:

  • use nmci.ip instead of nmci.process, but that requires some enrichment of nmci.ip
  • add special wrapper for nmcli calls, maybe systemctl too, as we have ignore_stderr in most cases, maybe that should be treated better (using systemctl --quiet ..., but maybe that also mutes error messages, not sure).
  • use nmci.process in steps

@RunTests:*

@RunFeatures:all

Edited by Filip Pokryvka

Merge request reports