From e012567e38d8f5957aa7bc27b4a35e67ba665498 Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Sat, 24 Nov 2018 04:47:58 +0530 Subject: Add 'openshift_version.py' module With growth of amount of test cases and supported OpenShift versions we need to perform more and more version comparisons. So, this module is designed to ease such operations. Usage example: from cnslibs.common import openshift_version version = openshift_version.get_openshift_version() if '3.9' < version <= '3.11': # Do stuff for OpenShift 3.11 or 3.10 elif version <= '3.9': # Do stuff for OpenShift 3.9 or lower else: # Do stuff for higher versions than 3.11 Also, reuse it in all the existing places with version comparisons. Change-Id: Ibc27eff20ed0dff80deca73d5d156e23bda57439 --- cns-libs/cnslibs/common/openshift_ops.py | 33 ++------------------------------ 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'cns-libs/cnslibs/common/openshift_ops.py') diff --git a/cns-libs/cnslibs/common/openshift_ops.py b/cns-libs/cnslibs/common/openshift_ops.py index eac0f994..cc84098e 100644 --- a/cns-libs/cnslibs/common/openshift_ops.py +++ b/cns-libs/cnslibs/common/openshift_ops.py @@ -19,6 +19,7 @@ import yaml from cnslibs.common import command from cnslibs.common import exceptions +from cnslibs.common import openshift_version from cnslibs.common import podcmd from cnslibs.common import utils from cnslibs.common import waiter @@ -32,7 +33,6 @@ PODS_WIDE_RE = re.compile( SERVICE_STATUS = "systemctl status %s" SERVICE_RESTART = "systemctl restart %s" SERVICE_STATUS_REGEX = r"Active: active \((.*)\) since .*;.*" -OC_VERSION = None def oc_get_pods(ocp_node): @@ -495,13 +495,7 @@ def oc_delete(ocp_node, rtype, name, raise_on_absence=True): raise_on_error=raise_on_absence): return cmd = ['oc', 'delete', rtype, name] - - global OC_VERSION - if not OC_VERSION: - OC_VERSION = oc_version(ocp_node) - - versions = ['v3.6', 'v3.7', 'v3.9', 'v3.10'] - if not OC_VERSION.rsplit('.', 1)[0] in versions: + if openshift_version.get_openshift_version() >= '3.11': cmd.append('--wait=false') ret, out, err = g.run(ocp_node, cmd) @@ -1078,29 +1072,6 @@ def verify_pvc_status_is_bound(hostname, pvc_name, timeout=120, wait_step=3): raise AssertionError(msg) -def oc_version(hostname): - ''' - Get Openshift version from oc version command - Args: - hostname (str): Node on which the ocp command will run. - Returns: - str : oc version if successful, - otherwise raise Exception - ''' - cmd = "oc version | grep openshift | cut -d ' ' -f 2" - ret, out, err = g.run(hostname, cmd, "root") - if ret != 0: - msg = ("failed to get oc version err %s; out %s" % (err, out)) - g.log.error(msg) - raise AssertionError(msg) - if not out: - error_msg = "Empty string found for oc version" - g.log.error(error_msg) - raise exceptions.ExecutionError(error_msg) - - return out.strip() - - def resize_pvc(hostname, pvc_name, size): ''' Resize PVC -- cgit