From 7cbc41ba32fd3e1eb7bfbf43707ad95b6fe73c9a Mon Sep 17 00:00:00 2001 From: Imadzuma Date: Wed, 21 Aug 2024 09:05:41 +0300 Subject: [PATCH 1/3] caught sftp eof error during reboot --- kubemarine/core/connections.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kubemarine/core/connections.py b/kubemarine/core/connections.py index 76b43478f..c2ff475c9 100644 --- a/kubemarine/core/connections.py +++ b/kubemarine/core/connections.py @@ -132,6 +132,11 @@ def _prefetch_thread(file: paramiko.SFTPFile, chunks: List[Tuple[int, int]], sftp_file._prefetch_thread = _prefetch_thread.__get__(sftp_file, paramiko.SFTPFile) # type: ignore[attr-defined] return sftp_file + def close(self): + try: + super().close() + except EOFError as e: + self.logger.warning(f"Caught EOFError during closing sftp connection {e}") class Connection(fabric.Connection): # type: ignore[misc] def __init__(self, host: str, **kwargs: Any): From 96df992ac7c39f1010cf7f6e2908fc09e07db06b Mon Sep 17 00:00:00 2001 From: Imadzuma Date: Wed, 21 Aug 2024 10:06:19 +0300 Subject: [PATCH 2/3] add host information for sftp eof error --- kubemarine/core/connections.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kubemarine/core/connections.py b/kubemarine/core/connections.py index c2ff475c9..de8712022 100644 --- a/kubemarine/core/connections.py +++ b/kubemarine/core/connections.py @@ -95,6 +95,7 @@ class SFTPClient(paramiko.SFTPClient): def __init__(self, sock: paramiko.Channel): super().__init__(sock) self.KM_callback: Optional[TransferCallback] = None + self.host = "" def getfo(self, remotepath: Union[bytes, str], fl: IO[bytes], callback: Callable[[int, int], object] = None, prefetch: bool = True, @@ -136,7 +137,7 @@ def close(self): try: super().close() except EOFError as e: - self.logger.warning(f"Caught EOFError during closing sftp connection {e}") + self.logger.warning("Caught EOFError during closing sftp connection on host %s %s" % (self.host, e)) class Connection(fabric.Connection): # type: ignore[misc] def __init__(self, host: str, **kwargs: Any): @@ -154,6 +155,7 @@ def __setattr__(self, key: str, value: Any) -> None: def sftp(self) -> SFTPClient: if self._sftp is None: self._sftp = cast(SFTPClient, SFTPClient.from_transport(self.client.get_transport())) + self._sftp.host = self.host return self._sftp def get(self, *args: Any, **kwargs: Any) -> fabric.transfer.Result: From cb0ed28188dec995ad7251c2e7fde8d91bed387e Mon Sep 17 00:00:00 2001 From: Imadzuma Date: Wed, 21 Aug 2024 10:18:12 +0300 Subject: [PATCH 3/3] fix mypy and linter issues --- kubemarine/core/connections.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kubemarine/core/connections.py b/kubemarine/core/connections.py index de8712022..006379680 100644 --- a/kubemarine/core/connections.py +++ b/kubemarine/core/connections.py @@ -133,11 +133,11 @@ def _prefetch_thread(file: paramiko.SFTPFile, chunks: List[Tuple[int, int]], sftp_file._prefetch_thread = _prefetch_thread.__get__(sftp_file, paramiko.SFTPFile) # type: ignore[attr-defined] return sftp_file - def close(self): + def close(self) -> None: try: super().close() except EOFError as e: - self.logger.warning("Caught EOFError during closing sftp connection on host %s %s" % (self.host, e)) + self.logger.warning("Caught EOFError during closing sftp connection on host %s %s", self.host, e) class Connection(fabric.Connection): # type: ignore[misc] def __init__(self, host: str, **kwargs: Any):