diff options
| author | Valerii Ponomarov <vponomar@redhat.com> | 2018-12-05 20:22:38 +0530 |
|---|---|---|
| committer | Valerii Ponomarov <vponomar@redhat.com> | 2018-12-07 10:26:04 +0000 |
| commit | 65487518fd4fc78da9e0061ec0a8b9b9d6bfa071 (patch) | |
| tree | a8d68942193409a496adc37c4ef9446c84773389 | |
| parent | 812e853791f3704a1136511227af80e767e80c89 (diff) | |
Add cmd-runner function which is gluster deployment type agnostic
For the moment, most of the test cases and lib functions in
'openshift_ops' python module support only containerized
Gluster clusters. So, to be able to support standalone Gluster clusters
in addition to the containerized ones, add special function
which allows us to run shell commands on both types of Gluster clusters
autodetecting the type.
As an example, update one of the existing lib functions making
all the existing 'arbiter' test cases work in both cases.
Change-Id: Iad69d7dc692c87eb70ed5caf780cb688f274bf02
| -rw-r--r-- | cns-libs/cnslibs/common/openshift_ops.py | 37 | ||||
| -rw-r--r-- | tests/functional/common/arbiter/test_arbiter.py | 3 |
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')) |
