From 1590e39e195d4e0f79f8de7ac9061f2242ec9208 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Mon, 13 Jan 2025 15:30:56 +0000 Subject: [PATCH] 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] https://github.com/openstack/openstack-ansible/commit/d74d03803242ae1fb0137db4cf95def5b50474ca Change-Id: I20967f1b6e26977a64ec338780cc85006bc1f846 --- osa_toolkit/generate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osa_toolkit/generate.py b/osa_toolkit/generate.py index 117d14e6de..cfa89c556f 100755 --- a/osa_toolkit/generate.py +++ b/osa_toolkit/generate.py @@ -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",