pacemaker: add cluster maintenance mode checks (#10194)

* feat(maintenance): Add cluster maintenance mode checks for pacemaker

* bug(fix): Correct substring typo and unit test

This commit corrects a substring check for determining if the pacemaker
cluster is in maintenance mode. Additionally, unit test is corrected
with correct output from pacemaker when in maintenance mode.

* feat(maintenance): Add force argument for absent resources

This commit adds in --force argument for resources intended to be absent
within a cluster that is in maintenance mode. Without this argument, the
cluster will not attempt to remove the resource due to maintenance mode.
The resource will be declared as orphaned and exiting maintenance mode
will allow the cluster to remove the resource completely.

* refactor(review): Apply code review changes

This commit adds refactors to enhance code quality.

* doc(changelog): Add fragment for maintenance mode addition
This commit is contained in:
Dexter 2025-06-07 11:52:32 -04:00 committed by GitHub
parent 928622703d
commit 6bbd1dd7f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 142 additions and 9 deletions

View file

@ -37,10 +37,20 @@ def fmt_resource_argument(value):
return ['--group' if value['argument_action'] == 'group' else value['argument_action']] + value['argument_option']
def pacemaker_runner(module, cli_action, **kwargs):
def get_pacemaker_maintenance_mode(runner):
with runner("config") as ctx:
rc, out, err = ctx.run()
maintenance_mode_output = list(filter(lambda string: "maintenance-mode=true" in string.lower(), out.splitlines()))
return bool(maintenance_mode_output)
def pacemaker_runner(module, cli_action=None, **kwargs):
runner_command = ['pcs']
if cli_action:
runner_command.append(cli_action)
runner = CmdRunner(
module,
command=['pcs', cli_action],
command=runner_command,
arg_formats=dict(
state=cmd_runner_fmt.as_map(_state_map),
name=cmd_runner_fmt.as_list(),
@ -50,6 +60,8 @@ def pacemaker_runner(module, cli_action, **kwargs):
resource_meta=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("meta"),
resource_argument=cmd_runner_fmt.as_func(fmt_resource_argument),
wait=cmd_runner_fmt.as_opt_eq_val("--wait"),
config=cmd_runner_fmt.as_fixed("config"),
force=cmd_runner_fmt.as_bool("--force"),
),
**kwargs
)