Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure journalctl -b is properly captured on shutdown #1755

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion subiquity/server/controllers/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 16 additions & 4 deletions subiquity/server/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion subiquity/server/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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
Expand Down Expand Up @@ -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):
Expand Down
Loading