Use correct hiera file for downgrade

During an upgrade abort scenario where both
controllers are already upgraded to release N+1,
a potential issue arises.
Release N+1 utilizes a new hieradata file named
hostname-X.yaml, while release N uses the older
ip.yaml.
Controller-0 must be downgraded first, making
controller-1 the active node.
However, controller-1 attempts to update the
hieradata file at
/opt/platform/puppet/<Release N>/.../controller-0.yaml
This file doesn't exist because release N uses ip.yaml
Solution:
The system needs to identify this downgrade scenario
and update the correct hieradata file for release N:
/opt/platform/puppet/<Release N>/hieradata/<ip>.yaml

Tests Done:
AIO-DX IPv6 fresh install
AIO-DX IPv6 upgrade abort


Story: 2010722
Task: 49692

Change-Id: I848543e7606ddc5bb24ddadb07a7a74d56126044
Signed-off-by: Fabiano Correa Mercer <fabiano.correamercer@windriver.com>
This commit is contained in:
Fabiano Correa Mercer 2024-03-08 16:19:48 -03:00
parent c24d0950bc
commit 8a18249fda
1 changed files with 31 additions and 3 deletions

View File

@ -183,6 +183,25 @@ class PuppetOperator(object):
LOG.exception("failed to read secure_system config")
raise
def _is_controller0_downgrade(self, host, hiera_file):
"""
check if controller-0 will execute a downgrade for a version
using mgmt_ip.yaml.
for AIO-SX it is not relevant
"""
if (tsc.system_mode != constants.SYSTEM_MODE_SIMPLEX and
host.hostname == constants.CONTROLLER_0_HOSTNAME and
not os.path.exists(hiera_file)):
try:
upgrade = self.dbapi.software_upgrade_get_one()
if (upgrade.state == constants.UPGRADE_ABORTING_ROLLBACK):
LOG.info("controller-0 downgrade for a version using <ip>.yaml")
return True
except Exception:
# upgrade not in progress
pass
return False
@puppet_context
def update_host_config(self, host, config_uuid=None):
"""Update the host hiera configuration files for the supplied host"""
@ -243,13 +262,21 @@ class PuppetOperator(object):
target_load,
'hieradata')
# for downgrade ( upgrade-abort ) to STX.8 the hieradata is
# still using <mgmt_ip>.yaml
hiera_file = os.path.join(path, filename)
if self._is_controller0_downgrade(host, hiera_file):
mgmt_address = self._get_address_by_name(
constants.CONTROLLER_0_HOSTNAME, constants.NETWORK_TYPE_MGMT)
filename = mgmt_address + ".yaml"
with io.open(os.path.join(path, filename), 'r',
encoding='utf-8') as yaml_file:
host_config = yaml.load(yaml_file, Loader=yaml.FullLoader)
host_config.update(config)
self._write_host_config(host, host_config, path)
self._write_host_config(host, host_config, path, filename)
def remove_host_config(self, host):
"""Remove the configuration for the supplied host"""
@ -259,9 +286,10 @@ class PuppetOperator(object):
except Exception:
LOG.exception("failed to remove host config: %s" % host.uuid)
def _write_host_config(self, host, config, path=None):
def _write_host_config(self, host, config, path=None, filename=None):
"""Update the configuration for a specific host"""
filename = "%s.yaml" % host.hostname
if filename is None:
filename = "%s.yaml" % host.hostname
self._write_config(filename, config, path)
def _read_host_config(self, host, path):