summaryrefslogtreecommitdiffstats
path: root/cns-libs/cnslibs/common/podcmd.py
diff options
context:
space:
mode:
authorValerii Ponomarov <vponomar@redhat.com>2018-12-20 23:04:22 +0530
committerValerii Ponomarov <vponomar@redhat.com>2018-12-25 20:54:32 +0530
commit8b6107b62dacf5edc264f4f0206771d8fa07f7bf (patch)
tree775a3755324ea3a272a65ba9eddf100a605208d1 /cns-libs/cnslibs/common/podcmd.py
parent418b6a6dd31e70888cfcc343922d43e4646f7184 (diff)
Add abstraction between deployment types and gluster commands
Now, it is possible to run glustolibs commands on both deployment types: containerized and standalone. It is possible using 'auto_get_gluster_endpoint' as target for lib function in addition to the '@podcmd.GlustoPod()' decorator. Example: """ from glustolibs.gluster.volume_ops import get_volume_list from cnslibs.common import heketi_libs from cnslibs.common import podcmd class TestExample(heketi_libs.HeketiBaseClass): @podcmd.GlustoPod() def test_get_vol_list_either_on_node_or_on_pod(self): volumes = get_volume_list('auto_get_gluster_endpoint') """ Also, delete all the current usages of 'deployment_type' config option, and delete the option as unneeded anymore. Change-Id: I281f287c432a5a9efefda588be436ee285188697
Diffstat (limited to 'cns-libs/cnslibs/common/podcmd.py')
-rw-r--r--cns-libs/cnslibs/common/podcmd.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/cns-libs/cnslibs/common/podcmd.py b/cns-libs/cnslibs/common/podcmd.py
index 0613c206..2673461b 100644
--- a/cns-libs/cnslibs/common/podcmd.py
+++ b/cns-libs/cnslibs/common/podcmd.py
@@ -51,6 +51,8 @@ import types
from glusto.core import Glusto as g
+from cnslibs.common import openshift_ops
+
# Define a namedtuple that allows us to address pods instead of just
# hosts,
Pod = namedtuple('Pod', 'node podname')
@@ -61,11 +63,15 @@ def run(target, command, log_level=None, orig_run=g.run):
Wraps glusto's run function.
Args:
- target (str|Pod): If target is a anything other than a Pod
- object the command will be run directly on the target
- (hostname or IP). If target is a Pod object it will run
- on the named pod, going through the node named in the
- Pod object.
+ target (str|Pod): If target is str object and
+ it equals to 'auto_get_gluster_endpoint', then
+ Gluster endpoint gets autocalculated to be any of
+ Gluster PODs or nodes depending on the deployment type of
+ a Gluster cluster.
+ If it is str object with other value, then it is considered to be
+ an endpoint for command.
+ If 'target' is of the 'Pod' type,
+ then command will run on the specified POD.
command (str|list): Command to run.
log_level (str|None): log level to be passed on to glusto's
run method
@@ -78,6 +84,15 @@ def run(target, command, log_level=None, orig_run=g.run):
# NOTE: orig_run captures the glusto run method at function
# definition time in order to capture the method before
# any additional monkeypatching by other code
+
+ 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)
+ if gluster_pods:
+ target = Pod(ocp_client_node, gluster_pods[0])
+ else:
+ target = list(g.config.get("gluster_servers", {}).keys())[0]
+
if isinstance(target, Pod):
prefix = ['oc', 'rsh', target.podname]
if isinstance(command, types.StringTypes):