summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvamahaja <vamahaja@redhat.com>2019-07-16 12:04:19 +0530
committervamahaja <vamahaja@redhat.com>2019-08-07 12:34:13 +0530
commitaed2e7e9543969c604a61af020c8a5fbaf38cd04 (patch)
tree0c4de45068e49869b5d0c0cc56ac804dd35bcdc5
parent9443109a6fd20e8124b37099e620e6551b25dc8a (diff)
Workaround BZ-1727360 in the "get_gluster_pod_names_by_pvc_name" func
"get_gluster_pod_names_by_pvc_name" function depends on the ocp3.11 specific shell command, which fails on old OCP versions. So, fix it by getting info in compatible way. Also, update usages of this function with new return data structure. Change-Id: Ibb8559590a1288c032630b3292f631d28bc87263 Signed-off-by: vamahaja <vamahaja@redhat.com>
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/openshift_ops.py129
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/podcmd.py5
-rw-r--r--tests/functional/provisioning/test_dynamic_provisioning_block.py2
-rw-r--r--tests/functional/provisioning/test_dynamic_provisioning_file.py2
-rw-r--r--tests/functional/test_node_restart.py6
5 files changed, 77 insertions, 67 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
index 24dcbfd..8069fd8 100644
--- a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
+++ b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
@@ -98,22 +98,42 @@ def oc_get_pods_full(ocp_node):
return yaml.load(out)
-def get_ocp_gluster_pod_names(ocp_node):
+def get_ocp_gluster_pod_details(ocp_node):
"""Gets the gluster pod names in the current project.
Args:
ocp_node (str): Node in which ocp command will be executed.
Returns:
- list : list of gluster pod names in the current project.
- Empty list, if there are no gluster pods.
-
- Example:
- get_ocp_gluster_pod_names(ocp_node)
+ list: List of dicts, which consist of following key-value pairs:
+ pod_name=<pod_name_value>,
+ pod_host_ip=<host_ip_value>
+ pod_ip=<pod_ip_vlaue>
+ pod_hostname=<host_name_value>
+ pod_status=<pod_status_value>
+ pod_restarts=<pod_restart_value>
"""
- pod_names = list(oc_get_pods(ocp_node).keys())
- return [pod for pod in pod_names if pod.startswith('glusterfs-')]
+ pod_columns = [
+ ".:metadata.name", ".:status.hostIP", ".:status.podIP",
+ ".:spec.nodeName", ".:status.phase",
+ ".:status.containerStatuses[0].restartCount"]
+ pod_selector = "glusterfs-node=pod"
+
+ gluster_pods = oc_get_custom_resource(
+ ocp_node, "pod", pod_columns, selector=pod_selector)
+
+ gluster_pod_details = map(
+ lambda pod: {
+ "pod_name": pod[0],
+ "pod_host_ip": pod[1],
+ "pod_ip": pod[2],
+ "pod_hostname": pod[3],
+ "pod_status": pod[4],
+ "pod_restarts": pod[5]},
+ gluster_pods)
+
+ return gluster_pod_details
def get_amount_of_gluster_nodes(ocp_node):
@@ -125,7 +145,7 @@ def get_amount_of_gluster_nodes(ocp_node):
Integer value as amount of either GLuster PODs or Gluster nodes.
"""
# Containerized Gluster
- gluster_pods = get_ocp_gluster_pod_names(ocp_node)
+ gluster_pods = get_ocp_gluster_pod_details(ocp_node)
if gluster_pods:
return len(gluster_pods)
@@ -611,30 +631,25 @@ def scale_dc_pod_amount_and_wait(hostname, dc_name,
return pod_names
-def get_gluster_pod_names_by_pvc_name(ocp_node, pvc_name):
- """Get Gluster POD names, whose nodes store bricks for specified PVC.
+def get_gluster_host_ips_by_pvc_name(ocp_node, pvc_name):
+ """Get Gluster Host IPs, whose nodes store bricks for specified PVC.
Args:
ocp_node (str): Node to execute OCP commands on.
- pvc_name (str): Name of a PVC to get related Gluster PODs.
+ pvc_name (str): Name of a PVC to get related Gluster Hosts.
Returns:
- list: List of dicts, which consist of following 3 key-value pairs:
- pod_name=<pod_name_value>,
- host_name=<host_name_value>,
- host_ip=<host_ip_value>
+ list: List of gluster host IPs.
"""
# Check storage provisioner
- sp_cmd = (
- r'oc get pvc %s --no-headers -o=custom-columns='
- r':.metadata.annotations."volume\.beta\.kubernetes\.io\/'
- r'storage\-provisioner"' % pvc_name)
- sp_raw = command.cmd_run(sp_cmd, hostname=ocp_node)
- sp = sp_raw.strip()
+ column = (
+ r':.metadata.annotations.'
+ r'"volume\.beta\.kubernetes\.io\/storage-provisioner"')
+ sp = oc_get_custom_resource(ocp_node, "pvc", column, name=pvc_name)[0]
# Get node IPs
if sp == "kubernetes.io/glusterfs":
pv_info = get_gluster_vol_info_by_pvc_name(ocp_node, pvc_name)
- gluster_pod_nodes_ips = [
+ gluster_host_ips = [
brick["name"].split(":")[0]
for brick in pv_info["bricks"]["brick"]
]
@@ -649,51 +664,43 @@ def get_gluster_pod_names_by_pvc_name(ocp_node, pvc_name):
get_gluster_pod_node_ip_cmd, hostname=ocp_node)
node_ips_raw = node_ips_raw.replace(
"[", " ").replace("]", " ").replace(",", " ")
- gluster_pod_nodes_ips = [
+ gluster_host_ips = [
s.strip() for s in node_ips_raw.split(" ") if s.strip()
]
else:
assert False, "Unexpected storage provisioner: %s" % sp
- # Get node names
- get_node_names_cmd = (
- "oc get node -o wide | grep -e '%s ' | awk '{print $1}'" % (
- " ' -e '".join(gluster_pod_nodes_ips)))
- gluster_pod_node_names = command.cmd_run(
- get_node_names_cmd, hostname=ocp_node)
- gluster_pod_node_names = [
- node_name.strip()
- for node_name in gluster_pod_node_names.split("\n")
- if node_name.strip()
- ]
- node_count = len(gluster_pod_node_names)
- err_msg = "Expected more than one node hosting Gluster PODs. Got '%s'." % (
- node_count)
- assert (node_count > 1), err_msg
+ return gluster_host_ips
+
+
+def get_gluster_pod_names_by_pvc_name(
+ ocp_node, pvc_name, raise_on_error=True):
+ """Get Gluster POD names, whose nodes store bricks for specified PVC.
+
+ Args:
+ ocp_node (str): Node to execute OCP commands on.
+ pvc_name (str): Name of a PVC to get related Gluster PODs.
+ Returns:
+ list: List of dicts of gluster pods details.
+ """
+ gluster_host_ips = get_gluster_host_ips_by_pvc_name(ocp_node, pvc_name)
# Get Gluster POD names which are located on the filtered nodes
- get_pod_name_cmd = (
- "oc get pods --all-namespaces "
- "-o=custom-columns=:.metadata.name,:.spec.nodeName,:.status.hostIP | "
- "grep 'glusterfs-' | grep -e '%s '" % "' -e '".join(
- gluster_pod_node_names)
- )
- out = command.cmd_run(
- get_pod_name_cmd, hostname=ocp_node)
- data = []
- for line in out.split("\n"):
- pod_name, host_name, host_ip = [
- el.strip() for el in line.split(" ") if el.strip()]
- data.append({
- "pod_name": pod_name,
- "host_name": host_name,
- "host_ip": host_ip,
- })
- pod_count = len(data)
- err_msg = "Expected 3 or more Gluster PODs to be found. Actual is '%s'" % (
- pod_count)
- assert (pod_count > 2), err_msg
- return data
+ gluster_pods = get_ocp_gluster_pod_details(ocp_node)
+ if gluster_pods:
+ matched_gluster_pods = filter(
+ lambda pod: (pod["pod_host_ip"] in gluster_host_ips), gluster_pods)
+ pod_count = len(matched_gluster_pods)
+ err_msg = (
+ "Expected 3 or more Gluster PODs to be found. "
+ "Actual is '%s'" % (pod_count))
+ assert (pod_count > 2), err_msg
+ return matched_gluster_pods
+ elif raise_on_error:
+ raise exceptions.ExecutionError(
+ "Haven't found Gluster PODs on the cluster.")
+ else:
+ return None
def cmd_run_on_gluster_pod_or_node(
diff --git a/openshift-storage-libs/openshiftstoragelibs/podcmd.py b/openshift-storage-libs/openshiftstoragelibs/podcmd.py
index 83f49ca..62fff01 100644
--- a/openshift-storage-libs/openshiftstoragelibs/podcmd.py
+++ b/openshift-storage-libs/openshiftstoragelibs/podcmd.py
@@ -87,9 +87,10 @@ def run(target, command, user=None, log_level=None, orig_run=g.run):
if target == 'auto_get_gluster_endpoint':
ocp_client_node = list(g.config['ocp_servers']['client'].keys())[0]
- gluster_pods = openshift_ops.get_ocp_gluster_pod_names(ocp_client_node)
+ gluster_pods = openshift_ops.get_ocp_gluster_pod_details(
+ ocp_client_node)
if gluster_pods:
- target = Pod(ocp_client_node, gluster_pods[0])
+ target = Pod(ocp_client_node, gluster_pods[0]["pod_name"])
else:
target = list(g.config.get("gluster_servers", {}).keys())[0]
diff --git a/tests/functional/provisioning/test_dynamic_provisioning_block.py b/tests/functional/provisioning/test_dynamic_provisioning_block.py
index ae7198d..0a58797 100644
--- a/tests/functional/provisioning/test_dynamic_provisioning_block.py
+++ b/tests/functional/provisioning/test_dynamic_provisioning_block.py
@@ -176,7 +176,7 @@ class TestDynamicProvisioningBlockP0(GlusterBlockBaseClass):
oc_delete(self.node, 'pod', gluster_pod_data["pod_name"])
cmd = ("oc get pods -o wide | grep glusterfs | grep %s | "
"grep -v Terminating | awk '{print $1}'") % (
- gluster_pod_data["host_name"])
+ gluster_pod_data["pod_hostname"])
for w in Waiter(600, 15):
out = self.cmd_run(cmd)
new_gluster_pod_name = out.strip().split("\n")[0].strip()
diff --git a/tests/functional/provisioning/test_dynamic_provisioning_file.py b/tests/functional/provisioning/test_dynamic_provisioning_file.py
index 64e94ab..4b53d3c 100644
--- a/tests/functional/provisioning/test_dynamic_provisioning_file.py
+++ b/tests/functional/provisioning/test_dynamic_provisioning_file.py
@@ -242,7 +242,7 @@ class TestDynamicProvisioningP0(BaseClass):
oc_delete(self.node, 'pod', gluster_pod_data["pod_name"])
cmd = ("oc get pods -o wide | grep glusterfs | grep %s | "
"grep -v Terminating | awk '{print $1}'") % (
- gluster_pod_data["host_name"])
+ gluster_pod_data["pod_hostname"])
for w in Waiter(600, 15):
out = self.cmd_run(cmd)
new_gluster_pod_name = out.strip().split("\n")[0].strip()
diff --git a/tests/functional/test_node_restart.py b/tests/functional/test_node_restart.py
index 745ea2d..2452c61 100644
--- a/tests/functional/test_node_restart.py
+++ b/tests/functional/test_node_restart.py
@@ -7,7 +7,7 @@ from openshiftstoragelibs.baseclass import BaseClass
from openshiftstoragelibs.exceptions import ExecutionError
from openshiftstoragelibs.openshift_ops import (
check_service_status_on_pod,
- get_ocp_gluster_pod_names,
+ get_ocp_gluster_pod_details,
oc_rsh,
wait_for_pod_be_ready,
)
@@ -20,7 +20,9 @@ class TestNodeRestart(BaseClass):
super(TestNodeRestart, self).setUp()
self.oc_node = self.ocp_master_node[0]
- self.gluster_pod_list = get_ocp_gluster_pod_names(self.oc_node)
+ self.gluster_pod_list = [
+ pod["pod_name"]
+ for pod in get_ocp_gluster_pod_details(self.oc_node)]
if not self.gluster_pod_list:
self.skipTest("Standalone Gluster is not supported by this test.")
self.gluster_pod_name = self.gluster_pod_list[0]