Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions e2e_test/hawk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def main():
# Establish SSH connection to verify status
ssh = HawkTestSSH(args.host, args.secret)

# Get version from /etc/os-release
test_version = ssh.ssh.exec_command("grep VERSION= /etc/os-release")[1].read().decode().strip().split("=")[1].strip('"')
# Get VERSION_ID from /etc/os-release
output = ssh.ssh.exec_command("grep VERSION_ID= /etc/os-release")[1].read().decode()
test_version = output.strip().split("=")[1].strip('"')

# Create driver instance
browser = HawkTestDriver(addr=args.host, port=args.port,
Expand Down
15 changes: 12 additions & 3 deletions e2e_test/hawk_test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class HawkTestDriver:
'''
Hawk Test driver main class
'''
def __init__(self, addr='localhost', port='7630', browser='firefox', headless=False, version='15-SP5'):
def __init__(self, addr='localhost', port='7630', browser='firefox', headless=False, version='15.5'):
'''
Constructor function to initialize parameters
Args:
addr (str): target hostname, default is localhost
port (str): port number, default is 7630
browser (str): browser for testing, default is firefox
headless (boolean): headless mode, default is False
version (str): OS version, default is 15-SP5
version (str): OS version, default is 15.5
'''
self.addr = addr
self.port = port
Expand Down Expand Up @@ -315,6 +315,14 @@ def check_and_click_by_xpath(self, errmsg, xpath_exps):
# Element is obscured. Wait and click again
time.sleep(10 * self.timeout_scale)
elem.click()
except StaleElementReferenceException:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is missing from selenium.common.exceptions import StaleElementReferenceException

is_active = self.find_element(By.XPATH, xpath).get_attribute("class")
print("DEBUG: Is active ? " + is_active)
# Element is obscured. Wait and click again
time.sleep(10 * self.timeout_scale)
is_active = self.find_element(By.XPATH, xpath).get_attribute("class")
print("DEBUG: Is active ? " + is_active)
elem.click()

# Generic function to perform the tests
def test(self, testname, results, *extra):
Expand Down Expand Up @@ -954,7 +962,8 @@ def test_check_cluster_configuration(self, ssh):

# First try to get the values from the crm_attribute
if ssh.is_valid_command("crm_attribute --list-options=cluster --all --output-as=xml"):
if not ssh.check_cluster_conf_ssh("crm_attribute --list-options=cluster --all --output-as=xml | grep 'advanced=\"0\"' | sed 's/.*name=\"*\\([^\\\"]*\\)\".*/\\1/'", lst, silent=True, anycheck=False):
out = ssh.get_cluster_conf_ssh_output("crm_attribute --list-options=cluster --all --output-as=xml | grep 'advanced=\"0\"' | sed 's/.*name=\"*\\([^\\\"]*\\)\".*/\\1/'")
if not all(_ in out for _ in lst):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means that out must be iterable (like list/dict), we also need to consider out is possibly string type.

print(f'ERROR: {Error.CRM_CONFIG_ADVANCED_ATTRIBUTES}')
return False
# If the crm_attribute too old for this
Expand Down
34 changes: 13 additions & 21 deletions e2e_test/hawk_test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,23 @@ def is_valid_command(self, command):
return False
return True

def check_cluster_conf_ssh(self, command, mustmatch, silent=False, anycheck=False):
def get_cluster_conf_ssh_output(self, command):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a reminder: please make sure update all of check_cluster_conf_ssh to get_cluster_conf_ssh_output in this project

'''
Execute command via SSH connection and compare if its output matches expectation
Args:
command (str): input command
mustmatch (object): expected string or list
silent (boolean): print info or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a leftover

anycheck (boolean): if match at least one element in the list
Raises:
ValueError: No value matches expected string or list
Return:
boolean or matched value
The stdout of SSH command when no error detected
Else False (0)
'''
_, out, err = self.ssh.exec_command(command)
out, err = map(lambda f: f.read().decode().rstrip('\n'), (out, err))
if not silent:
print(f"INFO: ssh command [{command}] got output [{out}] and error [{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):
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")
return out

@staticmethod
def set_test_status(results, test, status):
Expand All @@ -88,7 +76,8 @@ def verify_stonith_in_maintenance(self, results):
False when stonith-sbd is not unmanaged nor in maintenance
'''
print("TEST: verify_stonith_in_maintenance")
if self.check_cluster_conf_ssh("crm status | grep stonith-sbd", ["unmanaged", "maintenance"], anycheck=True):
out = self.get_cluster_conf_ssh_output("crm status | grep stonith-sbd")
if any(_ in out for _ in ('unmanaged', 'maintenance')):
print("INFO: stonith-sbd is unmanaged/maintenance")
self.set_test_status(results, 'verify_stonith_in_maintenance', 'passed')
return True
Expand All @@ -107,7 +96,8 @@ def verify_node_maintenance(self, results):
False when node is in maintenance mode
'''
print("TEST: verify_node_maintenance: check cluster node is in maintenance mode")
if self.check_cluster_conf_ssh("crm status | grep -i node", "maintenance"):
out = self.get_cluster_conf_ssh_output("crm status | grep -i node")
if "maintenance" in out:
print("INFO: cluster node set successfully in maintenance mode")
self.set_test_status(results, 'verify_node_maintenance', 'passed')
return True
Expand All @@ -134,7 +124,8 @@ def verify_primitive(self, primitive, version, results):
matches.append("op stop timeout=15s")
else:
matches.append("op stop timeout=15s on-fail=stop")
if self.check_cluster_conf_ssh("crm configure show", matches):
out = self.get_cluster_conf_ssh_output("crm configure show")
if all(_ in out for _ in matches):
print(f"INFO: primitive [{primitive}] correctly defined in the cluster configuration")
self.set_test_status(results, 'verify_primitive', 'passed')
return True
Expand All @@ -154,7 +145,8 @@ def verify_primitive_removed(self, primitive, results):
False when configuration is not removed
'''
print(f"TEST: verify_primitive_removed: check primitive [{primitive}] is removed")
if self.check_cluster_conf_ssh("crm resource status | grep ocf::heartbeat:Dummy", ''):
out = self.get_cluster_conf_ssh_output("crm resource status | grep ocf::heartbeat:Dummy")
if out == '':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic is different with the lines in the original function:

        if isinstance(mustmatch, str):
            return mustmatch in out

please make sure out must be '' rather than ['a', 'b', ''], {'apple', ''}, {'': 'empty key value', 'id': 123} or any string.

print("INFO: primitive successfully removed")
self.set_test_status(results, 'verify_primitive_removed', 'passed')
return True
Expand Down
Loading