summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerii Ponomarov <vponomar@redhat.com>2018-12-07 12:42:46 +0000
committerGerrit Code Review <gerrit2@gerrit.host.prod.eng.bos.redhat.com>2018-12-07 12:42:46 +0000
commit31492fa754bd77e583564d8356822500078d1e2c (patch)
tree126202ae2a9c647c5c6ffcf432f86053dd9b7331
parent8a435684c2d8e3e8743adb2e2b2e694fd4536a55 (diff)
parent65487518fd4fc78da9e0061ec0a8b9b9d6bfa071 (diff)
Merge "Add cmd-runner function which is gluster deployment type agnostic"
-rw-r--r--cns-libs/cnslibs/common/openshift_ops.py37
-rw-r--r--tests/functional/common/arbiter/test_arbiter.py3
2 files changed, 30 insertions, 10 deletions
diff --git a/cns-libs/cnslibs/common/openshift_ops.py b/cns-libs/cnslibs/common/openshift_ops.py
index dae8cb27..7e000bc7 100644
--- a/cns-libs/cnslibs/common/openshift_ops.py
+++ b/cns-libs/cnslibs/common/openshift_ops.py
@@ -785,6 +785,34 @@ def get_gluster_pod_names_by_pvc_name(ocp_node, pvc_name):
return data
+def cmd_run_on_gluster_pod_or_node(ocp_client_node, cmd):
+ """Run shell command on either Gluster POD or Gluster node.
+
+ Args:
+ ocp_client_node (str): Node to execute OCP commands on.
+ cmd (str): shell command to run.
+ Returns:
+ Output of a shell command as string object.
+ """
+ # Containerized Glusterfs
+ gluster_pods = get_ocp_gluster_pod_names(ocp_client_node)
+ if gluster_pods:
+ pod_cmd = "oc exec %s -- %s" % (gluster_pods[0], cmd)
+ return command.cmd_run(pod_cmd, hostname=ocp_client_node)
+
+ # Standalone Glusterfs
+ for g_host in g.config.get("gluster_servers", {}).keys():
+ try:
+ return command.cmd_run(cmd, hostname=g_host)
+ except Exception as e:
+ g.log.error(
+ "Failed to run '%s' command on '%s' Gluster node. "
+ "Error: %s" % (cmd, g_host, e))
+
+ raise exceptions.ConfigError(
+ "Haven't found neither Gluster PODs nor Gluster nodes.")
+
+
def get_gluster_vol_info_by_pvc_name(ocp_node, pvc_name):
"""Get Gluster volume info based on the PVC name.
@@ -807,13 +835,8 @@ def get_gluster_vol_info_by_pvc_name(ocp_node, pvc_name):
vol_id = command.cmd_run(get_pv_cmd, hostname=ocp_node)
assert vol_id, "Gluster volume ID should not be empty: '%s'" % vol_id
- # Get name of one the Gluster PODs
- gluster_pod = get_ocp_gluster_pod_names(ocp_node)[1]
-
- # Get Gluster volume info
- vol_info_cmd = "oc exec %s -- gluster v info %s --xml" % (
- gluster_pod, vol_id)
- vol_info = command.cmd_run(vol_info_cmd, hostname=ocp_node)
+ vol_info_cmd = "gluster v info %s --xml" % vol_id
+ vol_info = cmd_run_on_gluster_pod_or_node(ocp_node, vol_info_cmd)
# Parse XML output to python dict
with mock.patch('glusto.core.Glusto.run', return_value=(0, vol_info, '')):
diff --git a/tests/functional/common/arbiter/test_arbiter.py b/tests/functional/common/arbiter/test_arbiter.py
index 2d67db16..2aab199b 100644
--- a/tests/functional/common/arbiter/test_arbiter.py
+++ b/tests/functional/common/arbiter/test_arbiter.py
@@ -20,9 +20,6 @@ class TestArbiterVolumeCreateExpandDelete(cns_baseclass.CnsBaseClass):
def setUp(self):
super(TestArbiterVolumeCreateExpandDelete, self).setUp()
- # Skip test if it is not CNS deployment
- if self.deployment_type != "cns":
- raise self.skipTest("This test can run only on CNS deployment.")
self.node = self.ocp_master_node[0]
self.sc = self.cns_storage_class.get(
'storage_class1', self.cns_storage_class.get('file_storage_class'))