mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-04 07:24:00 -07:00
pacemaker_cluster: enhancements and add unit tests (#10227)
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.16) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.16) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
* feat(initial): Add unit tests and rewrite pacemaker_cluster This commit introduces unit tests and pacemaker_cluster module rewrite to use the pacemaker module utils. * feat(cleanup): Various fixes and add resource state This commit migrates the pacemaker_cluster's cleanup state to the pacemaker_resource module. Additionally, the unit tests for pacemaker_cluster have been corrected to proper mock run command order. * doc(botmeta): Add author to pacemaker_cluster * style(whitespace): Cleanup test files * refactor(cleanup): Remove unused state value * bug(fix): Parse apply_all as separate option * refactor(review): Apply code review suggestions This commit refactors breaking changes in pacemaker_cluster module into deprecated features. The following will be scheduled for deprecation: `state: cleanup` and `state: None`. * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * refactor(review): Additional review suggestions * refactor(deprecations): Remove all deprecation changes * refactor(review): Enhance rename changelog entry and fix empty string logic * refactor(cleanup): Remove from pacemaker_resource * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * refactor(review): Add changelog and revert required name * revert(default): Use default state=present * Update changelogs/fragments/10227-pacemaker-cluster-and-resource-enhancement.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelog fragment. --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
4801b0fc00
commit
283d947f17
8 changed files with 695 additions and 156 deletions
|
@ -163,13 +163,15 @@ class PacemakerResource(StateModuleHelper):
|
|||
required_if=[('state', 'present', ['resource_type', 'resource_option'])],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
default_state = "present"
|
||||
|
||||
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.runner = pacemaker_runner(self.module)
|
||||
self.vars.set('previous_value', self._get()['out'])
|
||||
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
|
||||
self.module.params['name'] = self.module.params['name'] or None
|
||||
|
||||
def __quit_module__(self):
|
||||
self.vars.set('value', self._get()['out'])
|
||||
|
||||
def _process_command_output(self, fail_on_err, ignore_err_msg=""):
|
||||
def process(rc, out, err):
|
||||
|
@ -180,45 +182,31 @@ class PacemakerResource(StateModuleHelper):
|
|||
return process
|
||||
|
||||
def _get(self):
|
||||
with self.runner('state name', output_process=self._process_command_output(False)) as ctx:
|
||||
return ctx.run(state='status')
|
||||
with self.runner('cli_action state name') as ctx:
|
||||
result = ctx.run(cli_action="resource", state='status')
|
||||
return dict([('rc', result[0]),
|
||||
('out', result[1] if result[1] != "" else None),
|
||||
('err', result[2])])
|
||||
|
||||
def state_absent(self):
|
||||
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
|
||||
self.vars.cmd = ctx.cmd
|
||||
force = get_pacemaker_maintenance_mode(self.runner)
|
||||
with self.runner('cli_action state name force', output_process=self._process_command_output(True, "does not exist"), check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='resource', force=force)
|
||||
|
||||
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(not get_pacemaker_maintenance_mode(self._maintenance_mode_runner), "already exists"),
|
||||
'cli_action state name resource_type resource_option resource_operation resource_meta resource_argument wait',
|
||||
output_process=self._process_command_output(not get_pacemaker_maintenance_mode(self.runner), "already exists"),
|
||||
check_mode_skip=True) as ctx:
|
||||
ctx.run()
|
||||
self.vars.set('value', self._get())
|
||||
self.vars.stdout = ctx.results_out
|
||||
self.vars.stderr = ctx.results_err
|
||||
self.vars.cmd = ctx.cmd
|
||||
ctx.run(cli_action='resource')
|
||||
|
||||
def state_enabled(self):
|
||||
with self.runner('state name', output_process=self._process_command_output(True, "Starting"), check_mode_skip=True) as ctx:
|
||||
ctx.run()
|
||||
self.vars.set('value', self._get())
|
||||
self.vars.stdout = ctx.results_out
|
||||
self.vars.stderr = ctx.results_err
|
||||
self.vars.cmd = ctx.cmd
|
||||
with self.runner('cli_action state name', output_process=self._process_command_output(True, "Starting"), check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='resource')
|
||||
|
||||
def state_disabled(self):
|
||||
with self.runner('state name', output_process=self._process_command_output(True, "Stopped"), check_mode_skip=True) as ctx:
|
||||
ctx.run()
|
||||
self.vars.set('value', self._get())
|
||||
self.vars.stdout = ctx.results_out
|
||||
self.vars.stderr = ctx.results_err
|
||||
self.vars.cmd = ctx.cmd
|
||||
with self.runner('cli_action state name', output_process=self._process_command_output(True, "Stopped"), check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='resource')
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue