-
Notifications
You must be signed in to change notification settings - Fork 50
WIP: Fix Version compatible and refactor check_cluster_conf_ssh #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
|
@@ -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 == '': | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the logic is different with the lines in the original function: 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 | ||
|
|
||
There was a problem hiding this comment.
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