Skip to content

[th/execute-step] commands: use context.process.run_stdout() in "Execute" step

Thomas Haller requested to merge th/execute-step into main

We should not use the deprecated context.command*() and context.run() methods. Instead, use "context.process.run_stdout(). It should behave roughly the same (still igoring stderr by redirecting to stdout, and ignoring any encoding errors).

Still, aside not using a discouraged method, the error message is better too:

Previous:

       * Execute "hostnamectl set-hostname """ ... failed in 0.009s
   Traceback (most recent call last):
     File "/usr/lib/python3.10/site-packages/behave/model.py", line 1329, in run
       match.run(runner.context)
     File "/usr/lib/python3.10/site-packages/behave/matchers.py", line 98, in run
       self.func(context, *args, **kwargs)
     File "features/steps/commands.py", line 57, in execute_command
       assert context.command_code(command) == 0
   AssertionError

Now:

        * Execute "hostnamectl set-hostname """ ... failed in 0.010s
    Traceback (most recent call last):
      File "/usr/lib/python3.10/site-packages/behave/model.py", line 1329, in run
        match.run(runner.context)
      File "/usr/lib/python3.10/site-packages/behave/matchers.py", line 98, in run
        self.func(context, *args, **kwargs)
      File "features/steps/commands.py", line 58, in execute_command
        context.process.run_stdout(
      File "/data/src/NetworkManager-ci/nmci/ctx.py", line 665, in run_stdout
        return process.run_stdout(*a, context_hook=self.context_hook, **kw)
      File "/data/src/NetworkManager-ci/nmci/process.py", line 259, in run_stdout
        return _run(
      File "/data/src/NetworkManager-ci/nmci/process.py", line 187, in _run
        raise Exception(
    Exception: `hostnamectl set-hostname ""` returned exit code 1
    STDOUT:
    Could not set static hostname: Failed to set static hostname: Device or resource busy

    STDERR:
    

Merge request reports