yanne / api-test

0 stars 0 forks source link

Path separator of the target machine should be configurable #33

Closed yanne closed 10 years ago

yanne commented 10 years ago

Let's say you have this test:

* Settings * Library SSHLibrary

* Variables * ${HOST} ${USERNAME} ${PWD}

* Test Cases * Failing to copy a file on a Windows machine Open Connection ${HOST} Login ${USERNAME} ${PWD} Put File test.txt c:\windows\temp\test.txt Close Connection

When you run this with Robot Framework you get something alone:

KEYWORD: SSHLibrary.Put File test.txt, c:\windows\temp\test.txt Documentation: Copies file(s) from local host to remote host using existing SSH connection. Start / End / Elapsed: 20110727 16:01:42.091 / 20110727 16:01:42.183 / 00:00:00.092 16:01:42.164 INFO Creating missing remote directory 'windows' 16:01:42.183 FAIL IOError: [Errno 2] The file path does not exist or is invalid.

Now if you take this:

from SSHLibrary import SSHLibrary

all = ['SSHLib']

class SSHLib(SSHLibrary): ROBOT_LIBRARY_SCOPE = 'GLOBAL'

def put_one_file(self, source, destination='.', mode='0744', newlines='default'):
    self._client.create_sftp_client()
    try:
        self._info("Putting '%s' to '%s'" % (source, destination))
        self._client.put_file(source, destination, int(mode, 8),
                              {'CRLF': '\r\n', 'LF': '\n'}.get(newlines, None))
    finally:
        self._client.close_sftp_client()

if name == 'main': ssh = SSHLib() ssh.open_connection("192.168.0.66") ssh.login("test", "test") ssh.put_one_file("test.txt", "c:\windows\temp\test.txt") ssh.close_connection()

It will succeed copying the file.

It appears that the top-level Put File keyword performs some operations on the path that aren't handled well with Windows.

Python 2.7 Robot Framework 2.5.7 SSH Library 1.0 Paramiko 1.7.7.1 PyCrypto 2.3 Windows 2008

This issue was originally opened at Google Code on Jul 27, 2011.

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Sep 25, 2011.

We've had some problems with Put File and Windows servers before. The problem is that we have no Windows servers against which we can test this.

Which SSH server is running in your Windows server?

I'll try to figure out if I can reproduce (and fix) this somehow.

yanne commented 10 years ago

Original comment by helioxen...@gmail.com on Aug 23, 2012.

I was having similar problems, but they were fixed (so many tries that I am not sure what worked). I am running RIDE from a Windows 7 x64 machine, connecting to other Windows XP 32bit, having OpenSSH.

Most probable fix is using '/' for path separator, so c:\windows\temp\test.txt should be /windows/temp/test.txt.

OpenSSH uses a mapping for the C:\ like /cygdrive/c/.

On the target Windows machine, I added the user to Administrators group, with a password and set a Local path for its Home. That Home path must translated and set in the /etc/passwd file in OpenSSH.

Good luck, Helio

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Aug 30, 2012.

I took a look at the code that we have and Windows remote paths are handled indeed quite incorrectly.

I'll try to fix this by introducing a configuration option to get/put file, where the separator character may be defined, to enable correct resolution of remote paths.

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Aug 30, 2012.

Pushed the change in r183 . Since I do not have a Windows server, the fix is based on wishful thinking. Would be really cool if someone could try this version and give feedback.

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Aug 31, 2012.

This will be released as is, if bugs are found 1.1.1 can be made with short notice.