summaryrefslogtreecommitdiffstats
path: root/cns-libs/cnslibs/common/openshift_ops.py
diff options
context:
space:
mode:
authornigoyal <nigoyal@redhat.com>2019-02-14 19:29:53 +0530
committerApeksha D khakharia <akhakhar@redhat.com>2019-03-06 10:16:04 +0000
commit3d4ab96edfa54ec7f2dd9682d1ee3e3077dfa79c (patch)
tree69a2667308647532a141d6615c4bb1a3b5fb4518 /cns-libs/cnslibs/common/openshift_ops.py
parente8bd46079bda96c7b89094644ccfdb689f1800b1 (diff)
Add TCs creating block-PVCs and app pods changing node scheduling policy
Add 2 test cases, where one verifies creation of an app pod on the Gluster node and another on the separate node Change-Id: I99dfc5db7fa74d0f69115cfed470f72e66b1a256
Diffstat (limited to 'cns-libs/cnslibs/common/openshift_ops.py')
-rw-r--r--cns-libs/cnslibs/common/openshift_ops.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/cns-libs/cnslibs/common/openshift_ops.py b/cns-libs/cnslibs/common/openshift_ops.py
index 2899d531..b7390152 100644
--- a/cns-libs/cnslibs/common/openshift_ops.py
+++ b/cns-libs/cnslibs/common/openshift_ops.py
@@ -1451,3 +1451,56 @@ def restart_service_on_gluster_pod_or_node(ocp_client, service, gluster_node):
"""
cmd_run_on_gluster_pod_or_node(
ocp_client, SERVICE_RESTART % service, gluster_node)
+
+
+def oc_adm_manage_node(
+ ocp_client, operation, nodes=None, node_selector=None):
+ """Manage common operations on nodes for administrators.
+
+ Args:
+ ocp_client (str): host on which we want to run 'oc' commands.
+ operations (str):
+ eg. --schedulable=true.
+ nodes (list): list of nodes to manage.
+ node_selector (str): selector to select the nodes.
+ Note: 'nodes' and 'node_selector' are are mutually exclusive.
+ Only either of them should be passed as parameter not both.
+ Returns:
+ str: In case of success.
+ Raises:
+ AssertionError: In case of any failures.
+ """
+
+ if (not nodes) == (not node_selector):
+ raise AssertionError(
+ "'nodes' and 'node_selector' are mutually exclusive. "
+ "Only either of them should be passed as parameter not both.")
+
+ cmd = "oc adm manage-node %s" % operation
+ if node_selector:
+ cmd += " --selector %s" % node_selector
+ else:
+ node = ' '.join(nodes)
+ cmd += " " + node
+
+ return command.cmd_run(cmd, ocp_client)
+
+
+def oc_get_schedulable_nodes(ocp_client):
+ """Get the list of schedulable nodes.
+
+ Args:
+ ocp_client (str): host on which we want to run 'oc' commands.
+
+ Returns:
+ list: list of nodes if present.
+ Raises:
+ AssertionError: In case of any failures.
+ """
+ cmd = ("oc get nodes --field-selector=spec.unschedulable!=true "
+ "-o=custom-columns=:.metadata.name,:.spec.taints[*].effect "
+ "--no-headers | awk '!/NoSchedule/{print $1}'")
+
+ out = command.cmd_run(cmd, ocp_client)
+
+ return out.split('\n') if out else out