From 70de7882d12f5915d031797758387c770350c418 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Tue, 8 Oct 2024 11:23:40 -0400 Subject: [PATCH] Adjust a couple of migrations I had forgot the include logic to not run some migrations if the changes have already taken place. This skip is just the "naive" approach instead of doing a complete validation that the previous fields have migrated. --- broker/config_migrations/v0_6_0.py | 9 +++++++-- broker/helpers.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/broker/config_migrations/v0_6_0.py b/broker/config_migrations/v0_6_0.py index 080f4d2..72e464c 100644 --- a/broker/config_migrations/v0_6_0.py +++ b/broker/config_migrations/v0_6_0.py @@ -37,7 +37,10 @@ def remove_test_nick(config_dict): def move_ssh_settings(config_dict): - """Move SSH settings from the top leve into its own chunk.""" + """Move SSH settings from the top level into its own chunk.""" + # Check if the migration has already been performed + if "ssh" in config_dict: + return config_dict logger.debug("Moving SSH settings into their own section.") ssh_settings = { "backend": config_dict.pop("ssh_backend", "ssh2-python312"), @@ -57,7 +60,7 @@ def move_ssh_settings(config_dict): def add_thread_limit(config_dict): """Add a thread limit to the config.""" logger.debug("Adding a thread limit to the config.") - config_dict["thread_limit"] = None + config_dict["thread_limit"] = config_dict.get("thread_limit") return config_dict @@ -73,6 +76,8 @@ def add_inventory_fields(config_dict): Action: $action # some special field values are possible, check the wiki OS: os_distribution os_distribution_version # you can combine multiple values with a space between """ + if "inventory_fields" in config_dict: + return config_dict logger.debug("Adding inventory fields to the config.") config_dict["inventory_fields"] = { "Host": "hostname", diff --git a/broker/helpers.py b/broker/helpers.py index 6d1e32f..707fe9f 100644 --- a/broker/helpers.py +++ b/broker/helpers.py @@ -328,7 +328,7 @@ def _resolve_inv_field(field, host_dict, **extras): if "|" in field: resolved = [_resolve_inv_field(f.strip(), host_dict, **extras) for f in field.split("|")] for val in resolved: - if val: + if val and val != "Unknown": return val return "Unknown" # Users can combine multiple values in a single field, so evaluate each