예제 #1
0
파일: ssh.py 프로젝트: sandeep937/dvc
    def test_url(self):
        user = '******'
        host = '123.45.67.89'
        port = 1234
        path = '/path/to/dir'

        # URL ssh://[user@]host.xz[:port]/path
        url = 'ssh://{}@{}:{}{}'.format(user, host, port, path)
        config = {'url': url}

        remote = RemoteSSH(None, config)

        self.assertEqual(remote.user, user)
        self.assertEqual(remote.host, host)
        self.assertEqual(remote.port, port)
        self.assertEqual(remote.prefix, path)

        # SCP-like URL ssh://[user@]host.xz:path
        url = 'ssh://{}@{}:{}'.format(user, host, path)
        config = {'url': url}

        remote = RemoteSSH(None, config)

        self.assertEqual(remote.user, user)
        self.assertEqual(remote.host, host)
        self.assertEqual(remote.port, remote.DEFAULT_PORT)
        self.assertEqual(remote.prefix, path)
예제 #2
0
    def test_url(self):
        user = "******"
        host = "123.45.67.89"
        port = 1234
        path = "/path/to/dir"

        # URL ssh://[user@]host.xz[:port]/path
        url = "ssh://{}@{}:{}{}".format(user, host, port, path)
        config = {"url": url}

        remote = RemoteSSH(None, config)

        self.assertEqual(remote.user, user)
        self.assertEqual(remote.host, host)
        self.assertEqual(remote.port, port)
        self.assertEqual(remote.prefix, path)

        # SCP-like URL ssh://[user@]host.xz:/absolute/path
        url = "ssh://{}@{}:{}".format(user, host, path)
        config = {"url": url}

        remote = RemoteSSH(None, config)

        self.assertEqual(remote.user, user)
        self.assertEqual(remote.host, host)
        self.assertEqual(remote.port, remote.DEFAULT_PORT)
        self.assertEqual(remote.prefix, path)
예제 #3
0
def test_ssh_host_override_from_config(mock_file, mock_exists, config,
                                       expected_host):
    remote = RemoteSSH(None, config)

    mock_exists.assert_called_with(RemoteSSH.ssh_config_filename())
    mock_file.assert_called_with(RemoteSSH.ssh_config_filename())
    assert remote.host == expected_host
예제 #4
0
파일: ssh.py 프로젝트: siddygups/dvc
    def test_user(self):
        url = "ssh://127.0.0.1:/path/to/dir"
        config = {"url": url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.user, getpass.getuser())

        user = "******"
        url = "ssh://{}@127.0.0.1:/path/to/dir".format(user)
        config = {"url": url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.user, user)

        user = "******"
        config["user"] = user
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.user, user)
예제 #5
0
파일: ssh.py 프로젝트: siddygups/dvc
    def test_port(self):
        url = "ssh://127.0.0.1/path/to/dir"
        config = {"url": url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.port, remote.DEFAULT_PORT)

        port = 1234
        url = "ssh://127.0.0.1:{}/path/to/dir".format(port)
        config = {"url": url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.port, port)

        port = 4321
        config["port"] = port
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.port, port)
예제 #6
0
def test_hardlink_optimization(repo_dir, ssh_server):
    port = ssh_server.test_creds["port"]
    user = ssh_server.test_creds["username"]

    config = {
        "url": get_ssh_url_mocked(user, port),
        "port": port,
        "user": user,
        "keyfile": ssh_server.test_creds["key_filename"],
    }
    remote = RemoteSSH(None, config)

    from_info = remote.path_info / "empty"
    to_info = remote.path_info / "link"

    with remote.open(from_info, "wb"):
        pass

    if os.name == "nt":
        link_path = "c:" + to_info.path.replace("/", "\\")
    else:
        link_path = to_info.path

    remote.hardlink(from_info, to_info)
    assert not System.is_hardlink(link_path)
예제 #7
0
파일: ssh.py 프로젝트: sandeep937/dvc
    def test_user(self):
        url = 'ssh://127.0.0.1:/path/to/dir'
        config = {'url': url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.user, getpass.getuser())

        user = '******'
        url = 'ssh://{}@127.0.0.1:/path/to/dir'.format(user)
        config = {'url': url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.user, user)

        user = '******'
        config['user'] = user
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.user, user)
예제 #8
0
파일: ssh.py 프로젝트: sandeep937/dvc
    def test_port(self):
        url = 'ssh://127.0.0.1/path/to/dir'
        config = {'url': url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.port, remote.DEFAULT_PORT)

        port = 1234
        url = 'ssh://127.0.0.1:{}/path/to/dir'.format(port)
        config = {'url': url}
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.port, port)

        port = 4321
        config['port'] = port
        remote = RemoteSSH(None, config)
        self.assertEqual(remote.port, port)
예제 #9
0
파일: test_ssh.py 프로젝트: shizacat/dvc
def test_url(dvc):
    user = "******"
    host = "123.45.67.89"
    port = 1234
    path = "/path/to/dir"

    # URL ssh://[user@]host.xz[:port]/path
    url = "ssh://{}@{}:{}{}".format(user, host, port, path)
    config = {"url": url}

    remote = RemoteSSH(dvc, config)
    assert remote.path_info == url

    # SCP-like URL ssh://[user@]host.xz:/absolute/path
    url = "ssh://{}@{}:{}".format(user, host, path)
    config = {"url": url}

    remote = RemoteSSH(dvc, config)
    assert remote.path_info == url
예제 #10
0
파일: ssh.py 프로젝트: ml-lab/dvc
    def __init__(self, stage, path, info=None, remote=None):
        super(DependencySSH, self).__init__(stage, path, info=info)
        self.remote = remote if remote else RemoteSSH(stage.project, {})

        host = remote.host if remote else self.group('host')
        port = remote.port if remote else RemoteSSH.DEFAULT_PORT
        user = remote.user if remote else self.group('user')
        if remote:
            path = posixpath.join(remote.prefix,
                                  urlparse(path).path.lstrip('/'))
        else:
            path = self.match(self.url).group('path')

        self.path_info = {'scheme': 'ssh',
                          'host': host,
                          'port': port,
                          'user': user,
                          'path': path}
예제 #11
0
 def test_no_path(self):
     config = {"url": "ssh://127.0.0.1"}
     remote = RemoteSSH(None, config)
     self.assertEqual(remote.prefix, "/")
예제 #12
0
def test_ssh_keyfile(mock_file, mock_exists, config, expected_keyfile):
    remote = RemoteSSH(None, config)

    mock_exists.assert_called_with(RemoteSSH.ssh_config_filename())
    mock_file.assert_called_with(RemoteSSH.ssh_config_filename())
    assert remote.keyfile == expected_keyfile
예제 #13
0
def test_ssh_gss_auth(mock_file, mock_exists, config, expected_gss_auth):
    remote = RemoteSSH(None, config)

    mock_exists.assert_called_with(RemoteSSH.ssh_config_filename())
    mock_file.assert_called_with(RemoteSSH.ssh_config_filename())
    assert remote.gss_auth == expected_gss_auth
예제 #14
0
def test_ssh_port(mock_file, mock_exists, config, expected_port):
    remote = RemoteSSH(None, config)

    mock_exists.assert_called_with(RemoteSSH.ssh_config_filename())
    mock_file.assert_called_with(RemoteSSH.ssh_config_filename())
    assert remote.path_info.port == expected_port
예제 #15
0
파일: test_ssh.py 프로젝트: shizacat/dvc
def test_no_path(dvc):
    config = {"url": "ssh://127.0.0.1"}
    remote = RemoteSSH(dvc, config)
    assert remote.path_info.path == ""
예제 #16
0
파일: test_ssh.py 프로젝트: shizacat/dvc
def test_ssh_user(mock_file, mock_exists, dvc, config, expected_user):
    remote = RemoteSSH(dvc, config)

    mock_exists.assert_called_with(RemoteSSH.ssh_config_filename())
    mock_file.assert_called_with(RemoteSSH.ssh_config_filename())
    assert remote.path_info.user == expected_user