summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvamahaja <vamahaja@redhat.com>2020-03-24 17:04:42 +0530
committerVaibhav Mahajan <vamahaja@redhat.com>2020-03-26 06:17:08 +0000
commit1b93f719566bdaad263d4e6e5ed107c7311541c9 (patch)
tree20cf750622574b3ff9b24d5c4ec592b788be3c71
parentc697befe2b21543186b24b1092b79ddcd6a60273 (diff)
[LibFix] Fix 'g.rpyc_get_connection' library issueHEADmaster
'g.rpyc_get_connection' library fails to set connection. Instead of using 'g.rpyc_get_connection' libray for modifying file remotely, create file locally and upload to remote location using 'g.upload' library. Change-Id: I85564ee5b7c28a9d866be033d18bd018f648cd5b Signed-off-by: vamahaja <vamahaja@redhat.com>
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py84
-rw-r--r--tests/functional/heketi/test_volume_multi_req.py10
2 files changed, 52 insertions, 42 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py b/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py
index 5005a91..c8f2372 100644
--- a/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py
+++ b/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py
@@ -1,4 +1,8 @@
+import os
+import tempfile
+
from glusto.core import Glusto as g
+import six
import yaml
from openshiftstoragelibs.command import cmd_run
@@ -66,43 +70,51 @@ def enable_pvc_resize(master_node):
g.log.error(msg)
raise NotSupportedException(msg)
+ with tempfile.NamedTemporaryFile(delete=False) as temp:
+ temp_filename = temp.name
+
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, Loader=yaml.FullLoader)
- 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)
+ g.download(master_node, MASTER_CONFIG_FILEPATH, temp_filename)
+ except Exception as e:
+ err_msg = (
+ "Failed to download '{}' from master node '{}' due to"
+ "exception\n{}".format(
+ MASTER_CONFIG_FILEPATH, master_node, six.text_type(e)))
+ raise ExecutionError(err_msg)
+
+ with open(temp_filename, 'r') as f:
+ data = yaml.load(f, Loader=yaml.FullLoader)
+ 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 open(temp_filename, 'w+') as f:
+ yaml.dump(data, f, default_flow_style=False)
+
+ try:
+ g.upload(master_node, temp_filename, MASTER_CONFIG_FILEPATH)
+ except Exception as e:
+ err_msg = (
+ "Failed to upload '{}' to master node '{}' due to"
+ "exception\n{}".format(
+ master_node, MASTER_CONFIG_FILEPATH, six.text_type(e)))
+ raise ExecutionError(err_msg)
+ os.unlink(temp_filename)
+
if version == "3.9":
cmd = ("systemctl restart atomic-openshift-master-api "
"atomic-openshift-master-controllers")
diff --git a/tests/functional/heketi/test_volume_multi_req.py b/tests/functional/heketi/test_volume_multi_req.py
index 0c1b42a..3fdc438 100644
--- a/tests/functional/heketi/test_volume_multi_req.py
+++ b/tests/functional/heketi/test_volume_multi_req.py
@@ -3,6 +3,7 @@
import contextlib
import random
+import tempfile
import threading
import time
@@ -94,15 +95,12 @@ def temp_config(ocp_node, cfg):
Returns:
str: A path to a temporary file.
"""
- conn = g.rpyc_get_connection(ocp_node, user="root")
- tmp = conn.modules.tempfile.NamedTemporaryFile()
- try:
- tmp.write(yaml.safe_dump(cfg))
+ with tempfile.NamedTemporaryFile() as tmp:
+ tmp.write(yaml.safe_dump(cfg).encode())
tmp.flush()
filename = tmp.name
+ g.upload(ocp_node, filename, filename)
yield filename
- finally:
- tmp.close()
def wait_for_claim(ocp_node, pvc_name, timeout=60, interval=2):