Skip to content

Commit

Permalink
Merge pull request #86 from dtantsur/OCPBUGS-17372
Browse files Browse the repository at this point in the history
OCPBUGS-17372: fallback to /etc/hostname of hostnamectl fails
  • Loading branch information
openshift-merge-robot committed Aug 9, 2023
2 parents a977ef4 + 6b1e5f1 commit 9c7199e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions hardware_manager/ironic_coreos_install.py
Expand Up @@ -68,9 +68,20 @@ def get_deploy_steps(self, node, ports):
]

def _fix_hostname(self):
current = subprocess.check_output(
['chroot', ROOT_MOUNT_PATH, 'hostnamectl', 'hostname'],
encoding='utf-8').strip()
try:
current = subprocess.check_output(
['chroot', ROOT_MOUNT_PATH, 'hostnamectl', 'hostname'],
encoding='utf-8',
stderr=subprocess.PIPE)
except (OSError, subprocess.SubprocessError) as exc:
error = getattr(exc, 'stderr', None) or str(exc)
LOG.warning("Failed to call hostnamectl, will use /etc/hostname "
"instead. Error: %s", error.strip())
with open('/etc/hostname', 'rt') as hostfile:
current = hostfile.read()

current = current.strip()
LOG.debug('The current hostname is %s', current)
if current not in ('localhost', 'localhost.localdomain'):
return

Expand Down

0 comments on commit 9c7199e

Please sign in to comment.