diff options
author | Valerii Ponomarov <vponomar@redhat.com> | 2018-11-24 04:47:58 +0530 |
---|---|---|
committer | Valerii Ponomarov <vponomar@redhat.com> | 2018-12-17 14:43:14 +0000 |
commit | e012567e38d8f5957aa7bc27b4a35e67ba665498 (patch) | |
tree | 462808eac58497fee46322e68e78c42d1a963503 /cns-libs/cnslibs/common/openshift_ops.py | |
parent | 78d7a913a49d388d80f42e367f2cb9ff6dc5ca20 (diff) |
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
Diffstat (limited to 'cns-libs/cnslibs/common/openshift_ops.py')
-rw-r--r-- | cns-libs/cnslibs/common/openshift_ops.py | 33 |
1 files changed, 2 insertions, 31 deletions
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 |