Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPDEV-103824] - caught sftp eof error during reboot #681

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kubemarine/core/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -132,6 +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) -> None:
try:
super().close()
except EOFError as 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):
Expand All @@ -149,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:
Expand Down
Loading