From bc355b8ecf444d7372724d62081457a73ed0cda8 Mon Sep 17 00:00:00 2001 From: Solomon Jacobs Date: Thu, 9 Jan 2025 18:32:30 +0100 Subject: [PATCH] 17221 FIX omd update: Do not trigger conflicts during stateful update SUP-21895 CMK-20945 Change-Id: I7641aa27cac2dd5ce083f681bb1dbf24b2889412 --- .werks/17221.md | 39 +++++++++++++++++++ cmk/update_config/main.py | 3 +- .../pre_actions/agent_based_plugins.py | 2 + .../plugins/pre_actions/autochecks.py | 2 + .../pre_actions/legacy_check_plugins.py | 2 + .../plugins/pre_actions/rulesets.py | 6 +++ .../plugins/pre_actions/ui_extensions.py | 2 + .../plugins/pre_actions/utils.py | 3 ++ .../update-pre-hooks/02_cmk-update-config | 2 +- 9 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .werks/17221.md diff --git a/.werks/17221.md b/.werks/17221.md new file mode 100644 index 00000000000..c8e6dd8c1de --- /dev/null +++ b/.werks/17221.md @@ -0,0 +1,39 @@ +[//]: # (werk v2) +# omd update: Do not trigger conflicts during stateful update + +key | value +---------- | --- +date | 2025-01-13T08:16:03+00:00 +version | 2.3.0p25 +class | fix +edition | cre +component | omd +level | 2 +compatible | yes + +This change affects users, who run into conflicts while updating their site. + +With this Werk, `omd` will automatically choose to continue the update once it is no longer safe to abort the update. + +**Background** + +In [#Werk 16408](https://checkmk.com/werk/16408), it was made possible to safely abort the update if a conflict occurs. +A conflict can occur due to different reasons, for example: + +* An enabled MKPs raises an exception during the update. +* A ruleset is present, which cannot be loaded anymore. +* Files are installed in `local/lib/check_mk/plugins/agent_based`, and they will no longer be loaded in 2.4.0. + +These conflicts need to be resolved, and will prompt the user on whether to continue the update (this behaviour can be changed by selecting a conflict mode). + +However, the update should only be aborted, before the following message is shown: +``` +Completed verifying site configuration. Your site now has version {version}. +``` +This message marks the beginning of the stateful update. +If such a stateful update does not complete, it creates a broken site. + +The verification steps, which detect conflicts, are executed a second time during the stateful update. + +Previously, the verification steps would offer to abort the update. +This would happen even if the user confirmed to continue the update previously and despite the fact that it was no longer safe to abort the update. diff --git a/cmk/update_config/main.py b/cmk/update_config/main.py index 92bb278b0f6..0b77a37a562 100644 --- a/cmk/update_config/main.py +++ b/cmk/update_config/main.py @@ -133,7 +133,8 @@ def _parse_arguments(args: Sequence[str]) -> argparse.Namespace: type=ConflictMode, help=( f"If you choose '{ConflictMode.ASK}', you will need to manually answer all upcoming questions. " - f"With '{ConflictMode.INSTALL}' or '{ConflictMode.KEEP_OLD}' no interaction is needed. " + f"With '{ConflictMode.FORCE}', '{ConflictMode.INSTALL}' or '{ConflictMode.KEEP_OLD}' no interaction is needed. " + f"'{ConflictMode.FORCE}' continues the update even if errors occur during the pre-flight checks. " f"If you choose '{ConflictMode.ABORT}', the update will be aborted if interaction is needed." ), ) diff --git a/cmk/update_config/plugins/pre_actions/agent_based_plugins.py b/cmk/update_config/plugins/pre_actions/agent_based_plugins.py index 49833e8b086..c98cfeb561a 100644 --- a/cmk/update_config/plugins/pre_actions/agent_based_plugins.py +++ b/cmk/update_config/plugins/pre_actions/agent_based_plugins.py @@ -90,6 +90,8 @@ def _disable_failure_and_reload_plugins( def _continue_on_incomp_local_file(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: diff --git a/cmk/update_config/plugins/pre_actions/autochecks.py b/cmk/update_config/plugins/pre_actions/autochecks.py index 7d721c1aa04..7ddc5f86b90 100644 --- a/cmk/update_config/plugins/pre_actions/autochecks.py +++ b/cmk/update_config/plugins/pre_actions/autochecks.py @@ -67,6 +67,8 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: def _continue_on_failed_to_migrate(prompt: str, conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: diff --git a/cmk/update_config/plugins/pre_actions/legacy_check_plugins.py b/cmk/update_config/plugins/pre_actions/legacy_check_plugins.py index 9073c62a168..dcba5c60d73 100644 --- a/cmk/update_config/plugins/pre_actions/legacy_check_plugins.py +++ b/cmk/update_config/plugins/pre_actions/legacy_check_plugins.py @@ -38,6 +38,8 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: def _continue_on_incomp_legacy_check(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: diff --git a/cmk/update_config/plugins/pre_actions/rulesets.py b/cmk/update_config/plugins/pre_actions/rulesets.py index 69755f035fe..fc5c6748b15 100644 --- a/cmk/update_config/plugins/pre_actions/rulesets.py +++ b/cmk/update_config/plugins/pre_actions/rulesets.py @@ -71,6 +71,8 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: def _continue_on_broken_ruleset(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.UPDATE case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: @@ -83,6 +85,8 @@ def _continue_on_broken_ruleset(conflict_mode: ConflictMode) -> Resume: def _continue_on_invalid_rule(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: @@ -95,6 +99,8 @@ def _continue_on_invalid_rule(conflict_mode: ConflictMode) -> Resume: def _continue_on_ruleset_exception(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: diff --git a/cmk/update_config/plugins/pre_actions/ui_extensions.py b/cmk/update_config/plugins/pre_actions/ui_extensions.py index a0c2c05b707..dc130d7e53b 100644 --- a/cmk/update_config/plugins/pre_actions/ui_extensions.py +++ b/cmk/update_config/plugins/pre_actions/ui_extensions.py @@ -98,6 +98,8 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: def _continue_on_incomp_local_file(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: diff --git a/cmk/update_config/plugins/pre_actions/utils.py b/cmk/update_config/plugins/pre_actions/utils.py index fbe133cf15e..7bf2b2bf513 100644 --- a/cmk/update_config/plugins/pre_actions/utils.py +++ b/cmk/update_config/plugins/pre_actions/utils.py @@ -98,6 +98,7 @@ class ConflictMode(enum.StrEnum): INSTALL = "install" KEEP_OLD = "keepold" ABORT = "abort" + FORCE = "force" _USER_INPUT_ABORT: Final = ("a", "abort") @@ -147,6 +148,8 @@ def disable_incomp_mkp( def _request_user_input_on_incompatible_file(conflict_mode: ConflictMode) -> Resume: match conflict_mode: + case ConflictMode.FORCE: + return Resume.UPDATE case ConflictMode.ABORT: return Resume.ABORT case ConflictMode.INSTALL | ConflictMode.KEEP_OLD: diff --git a/omd/packages/check_mk/scripts/update-pre-hooks/02_cmk-update-config b/omd/packages/check_mk/scripts/update-pre-hooks/02_cmk-update-config index 4ed9e047d59..bf7dd99e435 100644 --- a/omd/packages/check_mk/scripts/update-pre-hooks/02_cmk-update-config +++ b/omd/packages/check_mk/scripts/update-pre-hooks/02_cmk-update-config @@ -1,2 +1,2 @@ #!/bin/bash -cmk-update-config "--conflict" "$OMD_CONFLICT_MODE" +cmk-update-config "--conflict" force