Skip to content

Commit

Permalink
Merge pull request #275 from alvarocarvajald/unmanage_maintenance
Browse files Browse the repository at this point in the history
Check rsc stonith is in maintenance by either of 2 keywords
  • Loading branch information
aleksei-burlakov authored Mar 8, 2024
2 parents 3388d24 + 55e2260 commit 1219b4b
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions e2e_test/hawk_test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ def __init__(self, hostname, secret=None):
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
self.ssh.connect(hostname=hostname.lower(), username="root", password=secret)

def check_cluster_conf_ssh(self, command, mustmatch):
def check_cluster_conf_ssh(self, command, mustmatch, anycheck=False):
_, out, err = self.ssh.exec_command(command)
out, err = map(lambda f: f.read().decode().rstrip('\n'), (out, err))
print(f"INFO: ssh command [{command}] got output [{out}] and error [{err}]")
if err:
print(f"ERROR: got an error over SSH: [{err}]")
return False
if isinstance(mustmatch, str):
if mustmatch:
if mustmatch in out:
return True
return False
return out == mustmatch
if isinstance(mustmatch, list):
for exp in mustmatch:
if exp not in out:
return False
return True
return mustmatch in out
if isinstance(mustmatch, list) and anycheck:
# Output has to match at least one element in the list
return any(_ in out for _ in mustmatch)
if isinstance(mustmatch, list) and not anycheck:
# Output has to match all elements in list
return all(_ in out for _ in mustmatch)
raise ValueError("check_cluster_conf_ssh: mustmatch must be str or list")

@staticmethod
Expand All @@ -39,12 +36,11 @@ def set_test_status(results, test, status):

def verify_stonith_in_maintenance(self, results):
print("TEST: verify_stonith_in_maintenance")
if self.check_cluster_conf_ssh("crm status | grep stonith-sbd", "unmanaged") or \
self.check_cluster_conf_ssh("crm status | grep stonith-sbd", "maintenance"):
if self.check_cluster_conf_ssh("crm status | grep stonith-sbd", ["unmanaged", "maintenance"], True):
print("INFO: stonith-sbd is unmanaged/maintenance")
self.set_test_status(results, 'verify_stonith_in_maintenance', 'passed')
return True
print("ERROR: stonith-sbd is not unmanaged but should be")
print("ERROR: stonith-sbd is not unmanaged nor in maintenance but should be")
self.set_test_status(results, 'verify_stonith_in_maintenance', 'failed')
return False

Expand Down

0 comments on commit 1219b4b

Please sign in to comment.