Skip to content

Commit

Permalink
Merge pull request #108 from openshift-cherrypick-robot/cherry-pick-1…
Browse files Browse the repository at this point in the history
…06-to-release-4.15

[release-4.15] OCPBUGS-28756: Always add ignition to set hostname on /etc/hostname
  • Loading branch information
openshift-merge-bot[bot] committed Feb 14, 2024
2 parents 0145f7a + af83ec1 commit cd0769a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hardware_manager/ironic_coreos_install.py
Expand Up @@ -41,7 +41,7 @@ class CoreOSInstallHardwareManager(hardware.HardwareManager):
HARDWARE_MANAGER_NAME = 'CoreOSInstallHardwareManager'
HARDWARE_MANAGER_VERSION = '1'

_fixed_hostname = None
_firstboot_hostname = None
_dbus = None

def evaluate_hardware_support(self):
Expand Down Expand Up @@ -86,6 +86,10 @@ def _fix_hostname(self):
current = current.strip()
LOG.debug('The current hostname is %s', current)
if current not in ('localhost', 'localhost.localdomain'):
# Regardless of whether the hostname had been previously set or it gets set below
# we need to make sure if matches the name when the node boot so always set firstboot
# in ignition
self._firstboot_hostname = current
return

new = os.getenv('IPA_DEFAULT_HOSTNAME')
Expand All @@ -103,7 +107,7 @@ def _fix_hostname(self):
# IPA is run in a container, /etc/hostname is not updated there
with open('/etc/hostname', 'wt') as fp:
fp.write(new)
self._fixed_hostname = new
self._firstboot_hostname = new

@property
def dbus(self):
Expand Down Expand Up @@ -156,15 +160,15 @@ def start_assisted_install(self, node, ports):
LOG.info('Succesfully installed using the assisted agent')

def _add_firstboot_hostname_fix(self, ignition):
if not self._fixed_hostname:
if not self._firstboot_hostname:
return ignition

if isinstance(ignition, str):
ignition = json.loads(ignition)
elif not ignition:
ignition = {}

encoded = urlparse.quote(self._fixed_hostname)
encoded = urlparse.quote(self._firstboot_hostname)

files = ignition.setdefault('storage', {}).setdefault('files', [])
files.append({
Expand Down

0 comments on commit cd0769a

Please sign in to comment.