From 0e5dc8cd5053fd9fd3582221b1bd6c211a643778 Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Fri, 24 May 2019 21:03:55 +0530 Subject: 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 --- .../openshiftstoragelibs/__init__.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'openshift-storage-libs') 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 -- cgit