Fix inventory adjustment for legacy container naming

Patch [1] adjusted the default container names to contain dashes
rather than underscores. Inventories created prior to this patch
will still have container names with underscores, and these
are not handled correctly when making adjustments to env.d as the
"type_and_name" variable in the inventory generator will always
contain dashes in recent releases. This results in the legacy
container name never matching the new type_and_name, so components
added to, or moved between host groups in env.d will never be
assigned to those hosts.

[1] d74d038032

Change-Id: I20967f1b6e26977a64ec338780cc85006bc1f846
This commit is contained in:
Jonathan Rosser 2025-01-13 15:30:56 +00:00
parent 1fd3d0f1c6
commit 1590e39e19

View File

@ -290,13 +290,14 @@ def _append_to_host_groups(inventory, container_type, assignment, host_type,
container = hdata['container_name'] = hname
else:
container = hdata['container_name']
container_name = re.sub(r'_', '-', f'{container}')
component = hdata.get('component')
if container.startswith(host_type):
if 'physical_host' not in hdata:
hdata['physical_host'] = host_type
if container.startswith('{}-'.format(type_and_name)):
if container_name.startswith('{}-'.format(type_and_name)):
appended = du.append_if(array=iah, item=container)
if appended:
logger.debug("Added host %s to %s hosts",
@ -307,7 +308,7 @@ def _append_to_host_groups(inventory, container_type, assignment, host_type,
if appended:
logger.debug("Added is_metal host %s to %s hosts",
container, assignment)
if container.startswith('{}-'.format(type_and_name)):
if container_name.startswith('{}-'.format(type_and_name)):
appended = du.append_if(array=iph, item=container)
if appended:
logger.debug("Added host %s to %s hosts",