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

@ -135,7 +135,7 @@ cluster_resources:
'''
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
from ansible_collections.community.general.plugins.module_utils.pacemaker import pacemaker_runner
from ansible_collections.community.general.plugins.module_utils.pacemaker import pacemaker_runner, get_pacemaker_maintenance_mode
class PacemakerResource(StateModuleHelper):
@ -168,6 +168,7 @@ class PacemakerResource(StateModuleHelper):
def __init_module__(self):
self.runner = pacemaker_runner(self.module, cli_action='resource')
self._maintenance_mode_runner = pacemaker_runner(self.module, cli_action='property')
self.vars.set('previous_value', self._get())
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
@ -184,8 +185,10 @@ class PacemakerResource(StateModuleHelper):
return ctx.run(state='status')
def state_absent(self):
with self.runner('state name', output_process=self._process_command_output(True, "does not exist"), check_mode_skip=True) as ctx:
ctx.run()
runner_args = ['state', 'name', 'force']
force = get_pacemaker_maintenance_mode(self._maintenance_mode_runner)
with self.runner(runner_args, output_process=self._process_command_output(True, "does not exist"), check_mode_skip=True) as ctx:
ctx.run(force=force)
self.vars.set('value', self._get())
self.vars.stdout = ctx.results_out
self.vars.stderr = ctx.results_err
@ -194,7 +197,7 @@ class PacemakerResource(StateModuleHelper):
def state_present(self):
with self.runner(
'state name resource_type resource_option resource_operation resource_meta resource_argument wait',
output_process=self._process_command_output(True, "already exists"),
output_process=self._process_command_output(not get_pacemaker_maintenance_mode(self._maintenance_mode_runner), "already exists"),
check_mode_skip=True) as ctx:
ctx.run()
self.vars.set('value', self._get())