Skip to content

Commit

Permalink
Merge pull request #66 from openshift-cherrypick-robot/cherry-pick-65…
Browse files Browse the repository at this point in the history
…-to-release-4.12

[release-4.12] OCPBUGS-5067: make coreos-installer output available in the logs
  • Loading branch information
openshift-merge-robot committed Dec 21, 2022
2 parents a4408de + c65ed25 commit fb675ba
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions hardware_manager/ironic_coreos_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import dbus

from ironic_lib import disk_utils
from ironic_lib import utils
from ironic_python_agent import efi_utils
from ironic_python_agent import errors
from ironic_python_agent import hardware
from oslo_log import log
import tenacity


LOG = log.getLogger()
LOG = log.getLogger(__name__)

ROOT_MOUNT_PATH = '/mnt/coreos'

Expand Down Expand Up @@ -150,11 +149,7 @@ def install_coreos(self, node, ports):
command = ['chroot', ROOT_MOUNT_PATH,
'coreos-installer', 'install', *args, root]
LOG.info('Executing CoreOS installer: %s', command)
try:
self._run_install(command)
except subprocess.CalledProcessError as exc:
raise errors.DeploymentError(
f"coreos-install returned error code {exc.returncode}")
self._run_install(command)

# Just in case: re-read disk information
disk_utils.trigger_device_rescan(root)
Expand All @@ -177,17 +172,32 @@ def install_coreos(self, node, ports):
root)

@tenacity.retry(
retry=tenacity.retry_if_exception_type(subprocess.CalledProcessError),
retry=tenacity.retry_if_exception_type(errors.DeploymentError),
stop=tenacity.stop_after_attempt(3),
reraise=True)
def _run_install(self, command):
last_line = None
try:
# NOTE(dtantsur): avoid utils.execute because it swallows output
subprocess.run(command, check=True)
# NOTE(dtantsur): we need to capture the output to be able to log
# it properly. However, we also want to see it in the logs as it is
# happening (to be able to debug hangs or performance problems).
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
errors='backslashreplace')
for line in proc.stdout:
line = line.strip()
if line:
last_line = line
LOG.debug("coreos-installer: %s", line)
except FileNotFoundError:
raise errors.DeploymentError(
"Cannot run coreos-installer, is it installed in "
f"{ROOT_MOUNT_PATH}?")
except subprocess.CalledProcessError as exc:
LOG.warning("coreos-installer failed: %s", exc)
raise

code = proc.wait()
if code:
LOG.error("coreos-installer failed with code %d", code)
error = f"coreos-installer failed with code {code}: {last_line}"
raise errors.DeploymentError(error)

0 comments on commit fb675ba

Please sign in to comment.