summaryrefslogtreecommitdiffstats
path: root/openshift-storage-libs
diff options
context:
space:
mode:
authorvamahaja <vamahaja@redhat.com>2019-09-11 14:46:59 +0530
committervponomar <vponomar@redhat.com>2019-09-19 11:45:44 +0000
commita214cf6781d48594afc84d08e865d59bdcbe8fe1 (patch)
tree484092c4cc0f318871ed4c4299e663edf0b0489e /openshift-storage-libs
parent764d7bd68ec0b4ea9229c381b3b4195367b44b83 (diff)
Merge heketi node operation tests in one class and fix library
Fix consists of - - Use "**kwargs" approach in the "heketi_node_list" function as it is done in lots of other functions. - Parse the CLI output in the "heketi_node_list" function using regex instead of the splitting and stripping strings. - Combine test cases related to the same feature into one module - test_heketi_node_operations.py - Remove redundant checks which already exist in common libraries. - Remove unnecessary logging. Change-Id: I815ddfbbacb765140229e7630ec87a6bbaa6255b Signed-off-by: vamahaja <vamahaja@redhat.com>
Diffstat (limited to 'openshift-storage-libs')
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/heketi_ops.py37
1 files changed, 20 insertions, 17 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
index 38e09cd..7c7d98e 100644
--- a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
+++ b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
@@ -18,19 +18,20 @@ from openshiftstoragelibs.utils import parse_prometheus_data
from openshiftstoragelibs import waiter
-HEKETI_BHV = re.compile(r"Id:(\S+)\s+Cluster:(\S+)\s+Name:(\S+)\s\[block\]")
-HEKETI_OPERATIONS = re.compile(r"Id:(\S+)\s+Type:(\S+)\s+Status:(\S+)")
+HEKETI_DC = g.config.get("cns", g.config.get("openshift"))[
+ "heketi_config"]["heketi_dc_name"]
HEKETI_COMMAND_TIMEOUT = g.config.get("common", {}).get(
"heketi_command_timeout", 120)
-TIMEOUT_PREFIX = "timeout %s " % HEKETI_COMMAND_TIMEOUT
-
MASTER_NODE = list(g.config["ocp_servers"]["master"].keys())[0]
-HEKETI_DC = g.config.get("cns", g.config.get("openshift"))[
- "heketi_config"]["heketi_dc_name"]
+
+HEKETI_BHV = re.compile(r"Id:(\S+)\s+Cluster:(\S+)\s+Name:(\S+)\s\[block\]")
+HEKETI_OPERATIONS = re.compile(r"Id:(\S+)\s+Type:(\S+)\s+Status:(\S+)")
+HEKETI_NODES = re.compile(r"Id:(\S+)\s+Cluster:(\S+)")
+
GET_HEKETI_PODNAME_CMD = (
"oc get pods -l deploymentconfig=%s -o=custom-columns=:.metadata.name "
- "--no-headers" % HEKETI_DC
-)
+ "--no-headers" % HEKETI_DC)
+TIMEOUT_PREFIX = "timeout %s " % HEKETI_COMMAND_TIMEOUT
def cmd_run_on_heketi_pod(cmd, raise_on_error=True):
@@ -948,22 +949,26 @@ def heketi_node_info(heketi_client_node, heketi_server_url, node_id, **kwargs):
return out
-def heketi_node_list(heketi_client_node, heketi_server_url,
- heketi_user=None, heketi_secret=None):
+def heketi_node_list(heketi_client_node, heketi_server_url, **kwargs):
"""Execute CLI 'heketi node list' command and parse its output.
Args:
heketi_client_node (str): Node on which cmd has to be executed
heketi_server_url (str): Heketi server url to perform request to
- heketi_user (str): Name of the user to perform request with
- heketi_secret (str): Secret for 'heketi_user'
+
+ Kwargs:
+ The keys, values in kwargs are:
+ - json : (bool)
+ - secret : (str)|None
+ - user : (str)|None
Returns:
list of strings which are node IDs
+
Raises: openshiftstoragelibs.exceptions.ExecutionError when command fails.
"""
heketi_server_url, json_arg, admin_key, user = _set_heketi_global_flags(
- heketi_server_url, user=heketi_user, secret=heketi_secret)
+ heketi_server_url, **kwargs)
cmd = "heketi-cli -s %s node list %s %s %s" % (
heketi_server_url, json_arg, admin_key, user)
@@ -971,10 +976,8 @@ def heketi_node_list(heketi_client_node, heketi_server_url,
out = heketi_cmd_run(heketi_client_node, cmd)
heketi_node_id_list = []
- for line in out.strip().split("\n"):
- # Line looks like this: 'Id:nodeIdString\tCluster:clusterIdString'
- heketi_node_id_list.append(
- line.strip().split("Cluster")[0].strip().split(":")[1])
+ for node in HEKETI_NODES.findall(out.strip()):
+ heketi_node_id_list.append(node[0])
return heketi_node_id_list