diff options
author | Apeksha D Khakharia <akhakhar@redhat.com> | 2018-05-18 18:21:08 +0530 |
---|---|---|
committer | Apeksha D Khakharia <akhakhar@redhat.com> | 2018-10-18 13:05:39 +0530 |
commit | f3bf3c89c5c2ab0117ac5723c60ec4692ab5e334 (patch) | |
tree | fa90b54aa9d25712eb58d770127d0a7fdecf9f7b /cns-libs/cnslibs/common/cns_libs.py | |
parent | 8c53dc0b520d88513598c3e8e06a40e1e3a64f7c (diff) |
CNS: adding libraries and 2 testcases for pv resize
Change-Id: Idae22a28e4da867fd0567cbec49760d6f3a374f6
Signed-off-by: Apeksha D Khakharia <akhakhar@redhat.com>
Diffstat (limited to 'cns-libs/cnslibs/common/cns_libs.py')
-rw-r--r-- | cns-libs/cnslibs/common/cns_libs.py | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/cns-libs/cnslibs/common/cns_libs.py b/cns-libs/cnslibs/common/cns_libs.py index dbb78dcf..5b9a3027 100644 --- a/cns-libs/cnslibs/common/cns_libs.py +++ b/cns-libs/cnslibs/common/cns_libs.py @@ -1,8 +1,10 @@ from cnslibs.common.exceptions import ( - ExecutionError) + ExecutionError, + NotSupportedException) from cnslibs.common.openshift_ops import ( get_ocp_gluster_pod_names, - oc_rsh) + oc_rsh, + oc_version) from cnslibs.common.waiter import Waiter from glusto.core import Glusto as g import yaml @@ -464,3 +466,76 @@ def validate_gluster_blockd_service_gluster_pod(hostname): g.log.info("gluster-blockd service is running on all " "gluster-pods %s" % gluster_pod_list) return True + + +def enable_pvc_resize(master_node): + ''' + This function edits the /etc/origin/master/master-config.yaml + file - to enable pv_resize feature + and restarts atomic-openshift service on master node + Args: + master_node (str): hostname of masternode on which + want to edit the + master-config.yaml file + Returns: + bool: True if successful, + otherwise raise Exception + ''' + version = oc_version(master_node) + if any(v in version for v in ("3.6", "3.7", "3.8")): + msg = ("pv resize is not available in openshift " + "version %s " % version) + g.log.error(msg) + raise NotSupportedException(msg) + + try: + conn = g.rpyc_get_connection(master_node, user="root") + if conn is None: + err_msg = ("Failed to get rpyc connection of node %s" + % master_node) + g.log.error(err_msg) + raise ExecutionError(err_msg) + + with conn.builtin.open(MASTER_CONFIG_FILEPATH, 'r') as f: + data = yaml.load(f) + dict_add = data['admissionConfig']['pluginConfig'] + if "PersistentVolumeClaimResize" in dict_add: + g.log.info("master-config.yaml file is already edited") + return True + dict_add['PersistentVolumeClaimResize'] = { + 'configuration': { + 'apiVersion': 'v1', + 'disable': 'false', + 'kind': 'DefaultAdmissionConfig'}} + data['admissionConfig']['pluginConfig'] = dict_add + kube_config = data['kubernetesMasterConfig'] + for key in ('apiServerArguments', 'controllerArguments'): + kube_config[key] = ( + kube_config.get(key) + if isinstance(kube_config.get(key), dict) else {}) + value = ['ExpandPersistentVolumes=true'] + kube_config[key]['feature-gates'] = value + with conn.builtin.open(MASTER_CONFIG_FILEPATH, 'w+') as f: + yaml.dump(data, f, default_flow_style=False) + except Exception as err: + raise ExecutionError("failed to edit master-config.yaml file " + "%s on %s" % (err, master_node)) + finally: + g.rpyc_close_connection(master_node, user="root") + + g.log.info("successfully edited master-config.yaml file " + "%s" % master_node) + if "3.9" in version: + cmd = ("systemctl restart atomic-openshift-master-api " + "atomic-openshift-master-controllers") + else: + cmd = ("/usr/local/bin/master-restart api && " + "/usr/local/bin/master-restart controllers") + ret, out, err = g.run(master_node, cmd, "root") + if ret != 0 or out == "": + err_msg = ("failed to execute cmd %s on %s, err %s" + % (cmd, master_node, out)) + g.log.error(err_msg) + raise ExecutionError(err_msg) + + return True |