diff --git a/subiquity/server/controllers/shutdown.py b/subiquity/server/controllers/shutdown.py index da4466f89..7cf053041 100644 --- a/subiquity/server/controllers/shutdown.py +++ b/subiquity/server/controllers/shutdown.py @@ -120,7 +120,10 @@ async def copy_logs_to_target(self, context): try: with open_perms(journal_txt) as output: await self.app.command_runner.run( - ["journalctl", "-b"], stdout=output, stderr=subprocess.STDOUT + ["journalctl", "-b"], + capture=True, + stdout=output, + stderr=subprocess.STDOUT, ) except Exception: log.exception("saving journal failed") diff --git a/subiquity/server/runner.py b/subiquity/server/runner.py index 8a4a95d57..a0cbb78f3 100644 --- a/subiquity/server/runner.py +++ b/subiquity/server/runner.py @@ -70,12 +70,17 @@ def _forge_systemd_cmd( return prefix + cmd async def start( - self, cmd: List[str], *, private_mounts: bool = False, capture: bool = False + self, + cmd: List[str], + *, + private_mounts: bool = False, + capture: bool = False, + **astart_kwargs, ) -> asyncio.subprocess.Process: forged: List[str] = self._forge_systemd_cmd( cmd, private_mounts=private_mounts, capture=capture ) - proc = await astart_command(forged) + proc = await astart_command(forged, **astart_kwargs) proc.args = forged return proc @@ -128,10 +133,17 @@ def _get_delay_for_cmd(self, cmd: List[str]) -> float: return self.delay async def start( - self, cmd: List[str], *, private_mounts: bool = False, capture: bool = False + self, + cmd: List[str], + *, + private_mounts: bool = False, + capture: bool = False, + **astart_kwargs, ) -> asyncio.subprocess.Process: delay = self._get_delay_for_cmd(cmd) - proc = await super().start(cmd, private_mounts=private_mounts, capture=capture) + proc = await super().start( + cmd, private_mounts=private_mounts, capture=capture, **astart_kwargs + ) await asyncio.sleep(delay) return proc diff --git a/subiquity/server/tests/test_runner.py b/subiquity/server/tests/test_runner.py index c975b082e..270bf87cd 100644 --- a/subiquity/server/tests/test_runner.py +++ b/subiquity/server/tests/test_runner.py @@ -14,7 +14,8 @@ # along with this program. If not, see . import os -from unittest.mock import patch +import subprocess +from unittest.mock import ANY, patch from subiquity.server.runner import DryRunCommandRunner, LoggedCommandRunner from subiquitycore.tests import SubiTestCase @@ -103,6 +104,15 @@ def test_forge_systemd_cmd(self): ] self.assertEqual(cmd, expected) + async def test_start(self): + runner = LoggedCommandRunner(ident="my-id", use_systemd_user=False) + + with patch("subiquity.server.runner.astart_command") as astart_mock: + await runner.start(["/bin/ls"], stdout=subprocess.PIPE) + + expected_cmd = ANY + astart_mock.assert_called_once_with(expected_cmd, stdout=subprocess.PIPE) + class TestDryRunCommandRunner(SubiTestCase): def setUp(self):