summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerii Ponomarov <vponomar@redhat.com>2019-05-24 21:03:55 +0530
committervponomar <vponomar@redhat.com>2019-05-29 09:43:58 +0000
commit0e5dc8cd5053fd9fd3582221b1bd6c211a643778 (patch)
tree3b20a110776ba835f247a5a120af2e9e194287f2
parentfcbd09ed00839d262598628695437260fcf42971 (diff)
Make g.run recreate SSH connection in case of it's breakage
It happens, that saved SSH connection gets corrupted and we get errors trying to run commands on remote machines. So, to avoid such problem, monkey-patch Glusto's special method for getting SSH connections with ourselves-crafted method which recreates SSH connection in case it is broken. Change-Id: Iee69d21f3e23541480653205d86fefef2d842d34
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/__init__.py b/openshift-storage-libs/openshiftstoragelibs/__init__.py
index e69de29b..8d4d25c6 100644
--- a/openshift-storage-libs/openshiftstoragelibs/__init__.py
+++ b/openshift-storage-libs/openshiftstoragelibs/__init__.py
@@ -0,0 +1,25 @@
+from glusto.core import Glusto
+from six import add_metaclass
+
+
+def monkeypatch_class(name, bases, namespace):
+ assert len(bases) == 1, "Only 1 parent class is supported."
+ base = bases[0]
+ for name, value in namespace.items():
+ if not name.startswith("__"):
+ setattr(base, name, value)
+ return base
+
+
+@add_metaclass(monkeypatch_class)
+class MonkeyPatchedGlusto(Glusto):
+ @classmethod
+ def _get_ssh_connection(cls, host, user=None):
+ ssh = super(MonkeyPatchedGlusto, cls)._get_ssh_connection(
+ host=host, user=user)
+ if not ssh:
+ super(MonkeyPatchedGlusto, cls).ssh_close_connection(
+ host=host, user=user)
+ ssh = super(MonkeyPatchedGlusto, cls)._get_ssh_connection(
+ host=host, user=user)
+ return ssh