From: Daan De Meyer Date: Fri, 17 Jun 2022 14:13:49 +0000 (-0400) Subject: Refactor command running in integration tests X-Git-Tag: v13~15^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea3d032e6c1760abc3d8e404f69c55dcfdc704e2;p=thirdparty%2Fmkosi.git Refactor command running in integration tests Let's move run_command_image() into Machine.run(), introduce run_systemd_cmdline() to get the systemd-run command line, and remove all arguments from run_ssh() that aren't required anymore now. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 071e2daee..fd5caf794 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -66,7 +66,6 @@ from typing import ( ) from .backend import ( - _FILE, ARG_DEBUG, Distribution, ManifestFormat, @@ -8059,14 +8058,8 @@ def find_address(args: MkosiArgs) -> Tuple[str, str]: die("Container/VM address not found") -def run_command_image(args: MkosiArgs, commands: Sequence[str], timeout: int, check: bool, stdout: _FILE = sys.stdout, stderr: _FILE = sys.stderr) -> CompletedProcess: - if args.verb == Verb.qemu: - return run_ssh(args, commands, check, stdout, stderr, timeout) - elif args.verb == Verb.boot: - cmdline = ["systemd-run", "--quiet", "--wait", "--pipe", "-M", machine_name(args), "/usr/bin/env", *commands] - return run(cmdline, check=check, stdout=stdout, stderr=stderr, text=True, timeout=timeout) - else: - return run(run_shell_cmdline(args, pipe=True, commands=commands), check=check, stdout=stdout, stderr=stderr, text=True, timeout=timeout) +def run_systemd_cmdline(args: MkosiArgs, commands: Sequence[str]) -> List[str]: + return ["systemd-run", "--quiet", "--wait", "--pipe", "-M", machine_name(args), "/usr/bin/env", *commands] def run_ssh_cmdline(args: MkosiArgs, commands: Optional[Sequence[str]] = None) -> Sequence[str]: @@ -8102,15 +8095,8 @@ def run_ssh_cmdline(args: MkosiArgs, commands: Optional[Sequence[str]] = None) - return cmd -def run_ssh( - args: MkosiArgs, - commands: Optional[Sequence[str]] = None, - check: bool = True, - stdout: _FILE = sys.stdout, - stderr: _FILE = sys.stderr, - timeout: Optional[int] = None, -) -> CompletedProcess: - return run(run_ssh_cmdline(args, commands), check=check, stdout=stdout, stderr=stderr, text=True, timeout=timeout) +def run_ssh(args: MkosiArgs) -> CompletedProcess: + return run(run_ssh_cmdline(args), stdout=sys.stdout, stderr=sys.stderr) def run_serve(args: MkosiArgs) -> None: diff --git a/mkosi/machine.py b/mkosi/machine.py index 6a6a810e5..956cc03d3 100644 --- a/mkosi/machine.py +++ b/mkosi/machine.py @@ -26,12 +26,13 @@ from . import ( parse_args, parse_boolean, prepend_to_environ_path, - run_command_image, run_qemu_cmdline, run_shell_cmdline, + run_ssh_cmdline, + run_systemd_cmdline, unlink_output, ) -from .backend import MkosiArgs, MkosiNotSupportedException, Verb, die +from .backend import MkosiArgs, MkosiNotSupportedException, Verb, die, run class LogfileAdapter: @@ -162,7 +163,14 @@ class Machine: stdout: Union[int, TextIO] = subprocess.PIPE if capture_output else sys.stdout stderr: Union[int, TextIO] = subprocess.PIPE if capture_output else sys.stderr - return run_command_image(self.args, commands, timeout, check, stdout, stderr) + if self.args.verb == Verb.qemu: + cmdline = run_ssh_cmdline(self.args, commands) + elif self.args.verb == Verb.boot: + cmdline = run_systemd_cmdline(self.args, commands) + else: + cmdline = run_shell_cmdline(self.args, pipe=True, commands=commands) + + return run(cmdline, check=check, stdout=stdout, stderr=stderr, text=True, timeout=timeout) def kill(self) -> None: self.__exit__(None, None, None)