mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-22 15:04:33 -07:00
[PR #10707/63321754 backport][stable-11] pacemaker: Add regex checking for maintenance-mode (#10749)
pacemaker: Add regex checking for maintenance-mode (#10707)
* Add regex checking for maintenance-mode
* Add changelog fragment
* Apply suggestions from code review
---------
(cherry picked from commit 6332175493
)
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:
parent
a618aa6b0a
commit
ddc546596e
4 changed files with 70 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "pacemaker - use regex for matching ``maintenance-mode`` output to determine cluster maintenance status (https://github.com/ansible-collections/community.general/issues/10426, https://github.com/ansible-collections/community.general/pull/10707)."
|
|
@ -6,8 +6,9 @@
|
|||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
|
||||
import re
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
|
||||
|
||||
_state_map = {
|
||||
"present": "create",
|
||||
|
@ -45,7 +46,8 @@ def fmt_resource_argument(value):
|
|||
def get_pacemaker_maintenance_mode(runner):
|
||||
with runner("cli_action config") as ctx:
|
||||
rc, out, err = ctx.run(cli_action="property")
|
||||
maintenance_mode_output = list(filter(lambda string: "maintenance-mode=true" in string.lower(), out.splitlines()))
|
||||
maint_mode_re = re.compile(r"maintenance-mode.*true", re.IGNORECASE)
|
||||
maintenance_mode_output = [line for line in out.splitlines() if maint_mode_re.search(line)]
|
||||
return bool(maintenance_mode_output)
|
||||
|
||||
|
||||
|
|
|
@ -371,6 +371,30 @@ test_cases:
|
|||
rc: 0
|
||||
out: 'maintenance-mode=true'
|
||||
err: ""
|
||||
- id: test_maintenance_minimal_input_initial_online_version_change
|
||||
input:
|
||||
state: maintenance
|
||||
output:
|
||||
changed: true
|
||||
previous_value: 'maintenance-mode: false'
|
||||
value: 'maintenance-mode: true'
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/pcs, property, config, maintenance-mode]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: 'maintenance-mode: false'
|
||||
err: ""
|
||||
- command: [/testbin/pcs, property, set, maintenance-mode=true]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ""
|
||||
err: ""
|
||||
- command: [/testbin/pcs, property, config, maintenance-mode]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: 'maintenance-mode: true'
|
||||
err: ""
|
||||
- id: test_maintenance_minimal_input_initial_offline
|
||||
input:
|
||||
state: maintenance
|
||||
|
|
|
@ -189,6 +189,46 @@ test_cases:
|
|||
rc: 0
|
||||
out: " * virtual-ip\t(ocf:heartbeat:IPAddr2):\t Stopped"
|
||||
err: ""
|
||||
- id: test_present_minimal_input_resource_maintenance_mode_version_change
|
||||
input:
|
||||
state: present
|
||||
name: virtual-ip
|
||||
resource_type:
|
||||
resource_name: IPaddr2
|
||||
resource_option:
|
||||
- "ip=[192.168.2.1]"
|
||||
output:
|
||||
changed: true
|
||||
previous_value: null
|
||||
value: " * virtual-ip\t(ocf:heartbeat:IPAddr2):\t Stopped"
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/pcs, resource, status, virtual-ip]
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
out: ""
|
||||
err: ""
|
||||
- command: [/testbin/pcs, property, config]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: |
|
||||
Cluster Properties: cib-bootstrap-options
|
||||
cluster-infrastructure: corosync
|
||||
cluster-name: hacluster
|
||||
dc-version: 2.1.9-1.fc41-7188dbf
|
||||
have-watchdog: false
|
||||
maintenance-mode: true
|
||||
err: ""
|
||||
- command: [/testbin/pcs, resource, create, virtual-ip, IPaddr2, "ip=[192.168.2.1]", --wait=300]
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
out: ""
|
||||
err: "Error: resource 'virtual-ip' is not running on any node"
|
||||
- command: [/testbin/pcs, resource, status, virtual-ip]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: " * virtual-ip\t(ocf:heartbeat:IPAddr2):\t Stopped"
|
||||
err: ""
|
||||
- id: test_absent_minimal_input_resource_not_exist
|
||||
input:
|
||||
state: absent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue