diff --git a/e2e_test/hawk_test.py b/e2e_test/hawk_test.py index 63762aad1..3cce093b2 100755 --- a/e2e_test/hawk_test.py +++ b/e2e_test/hawk_test.py @@ -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, diff --git a/e2e_test/hawk_test_driver.py b/e2e_test/hawk_test_driver.py index fff91bed1..3b5025bd7 100644 --- a/e2e_test/hawk_test_driver.py +++ b/e2e_test/hawk_test_driver.py @@ -102,7 +102,7 @@ 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: @@ -110,7 +110,7 @@ def __init__(self, addr='localhost', port='7630', browser='firefox', headless=Fa 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 @@ -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: + 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): @@ -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): print(f'ERROR: {Error.CRM_CONFIG_ADVANCED_ATTRIBUTES}') return False # If the crm_attribute too old for this diff --git a/e2e_test/hawk_test_ssh.py b/e2e_test/hawk_test_ssh.py index d0d76529b..8f201d585 100644 --- a/e2e_test/hawk_test_ssh.py +++ b/e2e_test/hawk_test_ssh.py @@ -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): ''' 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 - 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): @@ -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 @@ -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 @@ -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 @@ -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 == '': print("INFO: primitive successfully removed") self.set_test_status(results, 'verify_primitive_removed', 'passed') return True