carletes / mock-ssh-server

Python mock SSH server for testing purposes
MIT License
56 stars 32 forks source link

`stat` on SFTPHandle causes paramiko prefetch mechanism to fail #12

Closed swiatek25 closed 4 years ago

swiatek25 commented 4 years ago

I have a client use case where I do:

with self._client.open(file_name, mode) as file:
    file.prefetch()
    # rest of file processing here

Unfortunately paramiko internally calls: resp = self.file_table[handle].stat() where self.file_table[handle] return instance of mockssh.sftp.SFTPHandle that lacks this method.

I now patch my tests with following stat() method implementation:

def stat(self):
    st = os.fstat(self.file_obj.name)
    return paramiko.SFTPAttributes.from_stat(st)

Maybe we could make it the default or support it in any other way?

carletes commented 4 years ago

Thanks, @swiatek25! Your implementation of the stat() method for SFTPHandle looks OK.

Could you perhaps open a pull request? (with a couple of tests, ideally!) I'm quite busy nowadays, and won't be able to do it myself in a reasonable time frame.

swiatek25 commented 4 years ago

Closing in favor of https://github.com/carletes/mock-ssh-server/pull/13