From 8d46ed884232d3f9a09f7feb92468bb2cd699871 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 12 Jan 2024 14:31:42 +0100 Subject: [PATCH] Allow env.d to contain underscores in physical_skel At the moment our dynamic_inventory does have assumption that group names defined in env.d will not contain underscores, except when it's ending with `_hosts` or `_containers` since inventory script uses split on `_` and taking the last argument. So in cases when underscore was used elsewhere in the group name it will result in unexpected behaviour. Instead of this approach we now use regexp which replaces the last octet separated with underscore with intended suffix to preserve rest behaviour. Change-Id: Id9ba56292972b8b52b4786c78684f2d6f289d88a --- osa_toolkit/generate.py | 18 +++++++++++++++--- ..._underscore_in_groups-354544f068878621.yaml | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/inventory_underscore_in_groups-354544f068878621.yaml diff --git a/osa_toolkit/generate.py b/osa_toolkit/generate.py index ef50f198b1..8f052c7927 100755 --- a/osa_toolkit/generate.py +++ b/osa_toolkit/generate.py @@ -252,7 +252,11 @@ def _append_to_host_groups(inventory, container_type, assignment, host_type, :param host_type: ``str`` Name of the host type :param type_and_name: ``str`` Combined name of host and container name """ - physical_group_type = '{}_all'.format(container_type.split('_')[0]) + physical_group_type = re.sub( + r"(?P.*)_(?P.*)$", + r'\g_all', + container_type + ) if physical_group_type not in inventory: logger.debug("Added %s group to inventory", physical_group_type) inventory[physical_group_type] = {'hosts': []} @@ -336,7 +340,11 @@ def _add_container_hosts(assignment, config, container_group, container_type, :param inventory: ``dict`` Living dictionary of inventory :param properties: ``dict`` Dict of container properties """ - physical_host_type = '{}_hosts'.format(container_type.split('_')[0]) + physical_host_type = re.sub( + r"(?P.*)_(?P.*)$", + r'\g_hosts', + container_type + ) container_name = re.sub(r'_', '-', f'{container_group}') # If the physical host type is not in config return if physical_host_type not in config: @@ -733,7 +741,11 @@ def container_skel_load(container_skel, inventory, config): inventory=inventory ) if properties.get('is_nest', False): - physical_host_type = '{}_hosts'.format(key.split('_')[0]) + physical_host_type = re.sub( + r"(?P.*)_(?P.*)$", + r'\g_hosts', + key + ) for host_type in inventory[physical_host_type]['hosts']: container_mapping = inventory[key]['children'] host_type_containers = '{}-host_containers'.format(host_type) diff --git a/releasenotes/notes/inventory_underscore_in_groups-354544f068878621.yaml b/releasenotes/notes/inventory_underscore_in_groups-354544f068878621.yaml new file mode 100644 index 0000000000..eb60553b87 --- /dev/null +++ b/releasenotes/notes/inventory_underscore_in_groups-354544f068878621.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Limitation on group naming in `physical_skel` section of env.d files + regarding usage of underscore symbol was released.