summaryrefslogtreecommitdiffstats
path: root/cns-libs/cnslibs/common/openshift_ops.py
diff options
context:
space:
mode:
authorApeksha D Khakharia <akhakhar@redhat.com>2018-07-27 21:05:39 +0530
committerApeksha D Khakharia <akhakhar@redhat.com>2018-08-06 18:55:30 +0530
commit3f2f40ec0e4c2d2ff548fcc3b2db5dc9b700007d (patch)
tree937bb3be98aaa355ce3f2879379f2d1492fc7de5 /cns-libs/cnslibs/common/openshift_ops.py
parentce5bb6aaab0051d32cbc2b697a288824d0ebde52 (diff)
CNS: new library - heketi-scale-pod, pod-state-ready
Change-Id: I97eb3ae1d0af48d405a0187fe585e2732658f809 Signed-off-by: Apeksha D Khakharia <akhakhar@redhat.com>
Diffstat (limited to 'cns-libs/cnslibs/common/openshift_ops.py')
-rw-r--r--cns-libs/cnslibs/common/openshift_ops.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/cns-libs/cnslibs/common/openshift_ops.py b/cns-libs/cnslibs/common/openshift_ops.py
index 2a61f6ac..7f2d2de0 100644
--- a/cns-libs/cnslibs/common/openshift_ops.py
+++ b/cns-libs/cnslibs/common/openshift_ops.py
@@ -14,6 +14,8 @@ import yaml
from cnslibs.common import exceptions
from cnslibs.common import utils
from cnslibs.common import waiter
+from cnslibs.common.dynamic_provisioning import (
+ wait_for_pod_be_ready)
PODS_WIDE_RE = re.compile(
@@ -414,3 +416,42 @@ def wait_for_resource_absence(ocp_node, rtype, name,
rtype, name, timeout)
g.log.error(error_msg)
raise exceptions.ExecutionError(error_msg)
+
+
+def scale_heketi_pod_amount_and_wait(hostname, dc_name,
+ namespace, pod_amount=1):
+ '''
+ This function scales heketi_pod and waits
+ If pod_amount 0 waits for its absence
+ If pod_amount =>1 waits for all pods to be ready
+ Args:
+ hostname (str): Node on which the ocp command will run
+ dc_name (str): Name of heketi dc
+ namespace (str): Namespace
+ pod_amount (int): Number of heketi pods to scale
+ ex: 0, 1 or 2
+ '''
+ heketi_scale_cmd = "oc scale --replicas=%d dc/%s --namespace %s" % (
+ dc_name, pod_amount, namespace)
+ ret, out, err = g.run(hostname, heketi_scale_cmd, "root")
+ if ret != 0:
+ error_msg = ("failed to execute cmd %s "
+ "out- %s err %s" % (heketi_scale_cmd, out, err))
+ g.log.error(error_msg)
+ raise exceptions.ExecutionError(error_msg)
+ get_heketi_podname_cmd = (
+ "oc get pods --all-namespaces -o=custom-columns=:.metadata.name "
+ "--no-headers=true "
+ "--selector deploymentconfig=%s" % dc_name)
+ ret, out, err = g.run(hostname, get_heketi_podname_cmd)
+ if ret != 0:
+ error_msg = ("failed to execute cmd %s "
+ "out- %s err %s" % (get_heketi_podname_cmd, out, err))
+ g.log.error(error_msg)
+ raise exceptions.ExecutionError(error_msg)
+ pod_list = out.strip().split("\n")
+ for pod in pod_list:
+ if pod_amount == 0:
+ wait_for_resource_absence(hostname, 'pod', pod)
+ else:
+ wait_for_pod_be_ready(hostname, pod)