Merge pull request #1799 from ogayot/chreipl-earlier

s390x: ensure chreipl is called before unmounting /target
This commit is contained in:
Dan Bungert 2023-09-19 18:28:24 -06:00 committed by GitHub
commit 21e6b1ebfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import glob
import json import json
import logging import logging
import os import os
import platform
import re import re
import shlex import shlex
import shutil import shutil
@ -666,6 +667,17 @@ class InstallController(SubiquityController):
) )
raise raise
async def platform_postinstall(self):
"""Run architecture specific commands/quirks"""
if platform.machine() == "s390x":
try:
# Ensure we boot from the installed system.
await arun_command(["chreipl", "/target/boot"])
except subprocess.CalledProcessError as cpe:
if cpe.stderr is not None:
log.warning("chreipl stderr:\n%s", cpe.stderr)
raise
@with_context( @with_context(
description="final system configuration", level="INFO", childlevel="DEBUG" description="final system configuration", level="INFO", childlevel="DEBUG"
) )
@ -700,6 +712,7 @@ class InstallController(SubiquityController):
hostname = f.read().strip() hostname = f.read().strip()
await self.app.controllers.Ad.join_domain(hostname, context) await self.app.controllers.Ad.join_domain(hostname, context)
await self.platform_postinstall()
self.model.filesystem.copy_artifacts_to_target() self.model.filesystem.copy_artifacts_to_target()
@with_context(description="configuring cloud-init") @with_context(description="configuring cloud-init")

View File

@ -16,7 +16,6 @@
import asyncio import asyncio
import logging import logging
import os import os
import platform
import subprocess import subprocess
from subiquity.common.apidef import API from subiquity.common.apidef import API
@ -137,11 +136,6 @@ class ShutdownController(SubiquityController):
if self.opts.dry_run: if self.opts.dry_run:
self.app.exit() self.app.exit()
else: else:
# On shutdown, it seems that the asynchronous command runners are not
# reliable. Best to keep using the traditional sort.
if self.app.state == ApplicationState.DONE:
if platform.machine() == "s390x":
run_command(["chreipl", "/target/boot"])
if self.mode == ShutdownMode.REBOOT: if self.mode == ShutdownMode.REBOOT:
run_command(["/sbin/reboot"]) run_command(["/sbin/reboot"])
elif self.mode == ShutdownMode.POWEROFF: elif self.mode == ShutdownMode.POWEROFF:

View File

@ -350,3 +350,41 @@ class TestInstallController(unittest.IsolatedAsyncioTestCase):
self.assertIn("--fs-uuid fsuuid", cfg) self.assertIn("--fs-uuid fsuuid", cfg)
self.assertIn("rp-partuuid=partuuid", cfg) self.assertIn("rp-partuuid=partuuid", cfg)
self.assertIn("uuid=casper-uuid", cfg) self.assertIn("uuid=casper-uuid", cfg)
@patch("platform.machine", return_value="s390x")
@patch("subiquity.server.controllers.install.arun_command")
async def test_postinstall_platform_s390x(self, arun, machine):
await self.controller.platform_postinstall()
arun.assert_called_once_with(["chreipl", "/target/boot"])
@patch("platform.machine", return_value="s390x")
async def test_postinstall_platform_s390x_fail(self, machine):
cpe = subprocess.CalledProcessError(
cmd=["chreipl", "/target/boot"],
returncode=1,
stderr="chreipl: No valid target specified",
)
arun_patch = patch(
"subiquity.server.controllers.install.arun_command", side_effect=cpe
)
assert_logs = self.assertLogs(
"subiquity.server.controllers.install", level="WARNING"
)
assert_raises = self.assertRaises(subprocess.CalledProcessError)
with assert_logs as errors, assert_raises, arun_patch as arun:
await self.controller.platform_postinstall()
arun.assert_called_once_with(["chreipl", "/target/boot"])
self.assertIn(
("chreipl stderr:\n%s", ["chreipl: No valid target specified"]),
[(record.msg, list(record.args)) for record in errors.records],
)
@patch("platform.machine", return_value="amd64")
@patch("subiquity.server.controllers.install.arun_command")
async def test_postinstall_platform_amd64(self, arun, machine):
await self.controller.platform_postinstall()
arun.assert_not_called()