[PR #10195/e4373565 backport][stable-11] pacemaker_stonith: new module (#10719)

pacemaker_stonith: new module (#10195)

* feat(initial): Add pacemaker_stonith module and unit tests

* feat(initial): Add working changes to pacemaker_stonith

* refactor(review): Apply code review suggestions

* Apply suggestions from code review




* refactor(review): Additional code review items

* bug(cli_action): Add missing runner arguments

* Apply code review suggestions

* Apply suggestions from code review



* Apply suggestions from code review



* WIP

* Apply doc changes to pacemaker stonith

* Update plugins/modules/pacemaker_stonith.py

---------



(cherry picked from commit e43735659a)

Co-authored-by: Dexter <45038532+munchtoast@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-08-23 19:44:54 +02:00 committed by GitHub
commit 148c133248
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 458 additions and 0 deletions

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Author: Dexter Le (dextersydney2001@gmail.com)
# Largely adapted from test_redhat_subscription by
# Jiri Hnidek (jhnidek@redhat.com)
#
# Copyright (c) Dexter Le (dextersydney2001@gmail.com)
# Copyright (c) Jiri Hnidek (jhnidek@redhat.com)
#
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.plugins.modules import pacemaker_stonith
from .uthelper import UTHelper, RunCommandMock
UTHelper.from_module(pacemaker_stonith, __name__, mocks=[RunCommandMock])

View file

@ -0,0 +1,216 @@
# -*- coding: utf-8 -*-
# Copyright (c) Dexter Le (dextersydney2001@gmail.com)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
---
anchors:
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
test_cases:
- id: test_missing_input
input: {}
output:
failed: true
msg: "missing required arguments: name"
- id: test_present_minimal_input_stonith_not_exists
input:
state: present
name: virtual-stonith
stonith_type: fence_virt
stonith_options:
- "pcmk_host_list=f1"
stonith_operations:
- operation_action: monitor
operation_options:
- "interval=30s"
output:
changed: true
previous_value: null
value: " * virtual-stonith\t(stonith:fence_virt):\t Started"
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: ""
- command: ["/testbin/pcs", stonith, create, virtual-stonith, fence_virt, "pcmk_host_list=f1", "op", "monitor", "interval=30s", "--wait=300"]
environ: *env-def
rc: 0
out: ""
err: ""
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Started"
err: ""
- id: test_present_minimal_input_stonith_exists
input:
state: present
name: virtual-stonith
stonith_type: fence_virt
stonith_options:
- "pcmk_host_list=f1"
stonith_operations:
- operation_action: monitor
operation_options:
- "interval=30s"
output:
changed: false
previous_value: " * virtual-stonith\t(stonith:fence_virt):\t Started"
value: " * virtual-stonith\t(stonith:fence_virt):\t Started"
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Started"
err: ""
- command: ["/testbin/pcs", stonith, create, virtual-stonith, fence_virt, "pcmk_host_list=f1", "op", "monitor", "interval=30s", "--wait=300"]
environ: *env-def
rc: 0
out: ""
err: "Error: 'virtual-stonith' already exists.\n"
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Started"
err: ""
- id: test_absent_minimal_input_stonith_not_exists
input:
state: absent
name: virtual-stonith
output:
changed: false
previous_value: null
value: null
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: ""
- command: ["/testbin/pcs", stonith, remove, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: "Error: Resource 'virtual-stonith' does not exist.\n"
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: ""
- id: test_absent_minimal_input_stonith_exists
input:
state: absent
name: virtual-stonith
output:
changed: true
previous_value: " * virtual-stonith\t(stonith:fence_virt):\t Started"
value: null
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Started"
err: ""
- command: ["/testbin/pcs", stonith, remove, virtual-stonith]
environ: *env-def
rc: 0
out: ""
err: "Attempting to stop: virtual-ip... Stopped\n"
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: ""
- id: test_enabled_minimal_input_stonith_not_exists
input:
state: enabled
name: virtual-stonith
output:
failed: true
msg: "pcs failed with error (rc=1): Error: Resource 'virtual-stonith' does not exist."
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: ""
- command: ["/testbin/pcs", stonith, enable, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: "Error: Resource 'virtual-stonith' does not exist."
- id: test_enabled_minimal_input_stonith_exists
input:
state: enabled
name: virtual-stonith
output:
changed: true
previous_value: " * virtual-stonith\t(stonith:fence_virt):\t Stopped (disabled)"
value: " * virtual-stonith\t(stonith:fence_virt):\t Starting"
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Stopped (disabled)"
err: ""
- command: ["/testbin/pcs", stonith, enable, virtual-stonith]
environ: *env-def
rc: 0
out: ""
err: ""
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Starting"
err: ""
- id: test_disable_minimal_input_stonith_not_exists
input:
state: disabled
name: virtual-stonith
output:
failed: true
msg: "pcs failed with error (rc=1): Error: Resource 'virtual-stonith' does not exist."
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: ""
- command: ["/testbin/pcs", stonith, disable, virtual-stonith]
environ: *env-def
rc: 1
out: ""
err: "Error: Resource 'virtual-stonith' does not exist."
- id: test_disable_minimal_input_stonith_exists
input:
state: disabled
name: virtual-stonith
output:
changed: true
previous_value: " * virtual-stonith\t(stonith:fence_virt):\t Started"
value: " * virtual-stonith\t(stonith:fence_virt):\t Stopped (disabled)"
mocks:
run_command:
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Started"
err: ""
- command: ["/testbin/pcs", stonith, disable, virtual-stonith]
environ: *env-def
rc: 0
out: ""
err: ""
- command: ["/testbin/pcs", stonith, status, virtual-stonith]
environ: *env-def
rc: 0
out: " * virtual-stonith\t(stonith:fence_virt):\t Stopped (disabled)"
err: ""