Exemple #1
0
def _ssh_factory(cloud):
    yield SSHFileSystem(
        host=cloud.host,
        port=cloud.port,
        user=TEST_SSH_USER,
        keyfile=TEST_SSH_KEY_PATH,
    )
Exemple #2
0
def test_ssh_host_override_from_config(mock_file, mock_exists, dvc, config,
                                       expected_host):
    fs = SSHFileSystem(dvc, config)

    mock_exists.assert_called_with(SSHFileSystem.ssh_config_filename())
    mock_file.assert_called_with(SSHFileSystem.ssh_config_filename())
    assert fs.path_info.host == expected_host
Exemple #3
0
def test_ssh_allow_agent(mock_file, mock_exists, dvc, config,
                         expected_allow_agent):
    fs = SSHFileSystem(dvc, config)

    mock_exists.assert_called_with(SSHFileSystem.ssh_config_filename())
    mock_file.assert_called_with(SSHFileSystem.ssh_config_filename())
    assert fs.allow_agent == expected_allow_agent
Exemple #4
0
def test_init():
    fs = SSHFileSystem(user="******",
                       host="12.34.56.78",
                       port="1234",
                       password="******")
    assert fs.fs_args["username"] == "test"
    assert fs.fs_args["host"] == "12.34.56.78"
    assert fs.fs_args["port"] == "1234"
    assert fs.fs_args["password"] == fs.fs_args["passphrase"] == "xxx"
Exemple #5
0
def test_url(dvc):
    user = "******"
    host = "123.45.67.89"
    port = 1234
    path = "/path/to/dir"

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

    fs = SSHFileSystem(dvc, config)
    assert fs.path_info == url

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

    fs = SSHFileSystem(dvc, config)
    assert fs.path_info == url
Exemple #6
0
def _sshfs(resource: dict):
    from tpi import TerraformProviderIterative

    with TerraformProviderIterative.pemfile(resource) as pem:
        fs = SSHFileSystem(
            host=resource["instance_ip"],
            user="******",
            keyfile=pem,
        )
        yield fs
Exemple #7
0
 def get_sshfs(  # pylint: disable=unused-argument
         self,
         name: Optional[str] = None,
         **config) -> Iterator["SSHFileSystem"]:
     resource = self._default_resource(name)
     with TerraformProviderIterative.pemfile(resource) as pem:
         fs = SSHFileSystem(
             host=resource["instance_ip"],
             user="******",
             keyfile=pem,
         )
         yield fs
Exemple #8
0
def test_hardlink_optimization(dvc, tmp_dir, ssh):
    fs = SSHFileSystem(dvc, ssh.config)

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

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

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

    fs.hardlink(from_info, to_info)
    assert not System.is_hardlink(link_path)
Exemple #9
0
def test_ssh_host_override_from_config(mock_file, config, expected_host):
    fs = SSHFileSystem(**config)
    assert fs.fs_args["host"] == expected_host
Exemple #10
0
def test_ssh_keyfile(mock_file, config, expected_keyfile):
    fs = SSHFileSystem(**config)
    assert fs.fs_args.get("client_keys") == expected_keyfile
Exemple #11
0
def test_ssh_ask_password(mocker):
    mocker.patch("dvc.fs.ssh.ask_password", return_value="fish")
    fs = SSHFileSystem(user="******", host="2.2.2.2", ask_password=True)
    assert fs.fs_args["password"] == fs.fs_args["passphrase"] == "fish"
Exemple #12
0
def test_ssh_multi_identity_files(mock_file):
    fs = SSHFileSystem(host="example.com")
    assert fs.fs_args.get("client_keys") == ["file_1", "file_2"]
Exemple #13
0
def test_ssh_gss_auth(mock_file, config, expected_gss_auth):
    fs = SSHFileSystem(**config)
    assert fs.fs_args["gss_auth"] == expected_gss_auth
Exemple #14
0
def test_ssh_port(mock_file, config, expected_port):
    fs = SSHFileSystem(**config)
    assert fs.fs_args["port"] == expected_port
Exemple #15
0
def test_ssh_keyfile(mock_file, config, expected_keyfile):
    fs = SSHFileSystem(**config)
    expected_keyfiles = ([
        os.path.expanduser(path) for path in expected_keyfile
    ] if expected_keyfile else expected_keyfile)
    assert fs.fs_args.get("client_keys") == expected_keyfiles
Exemple #16
0
def test_ssh_fs_path_management(url, path):
    fs = SSHFileSystem(host="x.y.z")

    path_info = fs.PATH_CLS(url)
    assert fs._with_bucket(path_info) == path
Exemple #17
0
def test_ssh_user(mock_file, config, expected_user):
    fs = SSHFileSystem(**config)
    assert fs.fs_args["username"] == expected_user
Exemple #18
0
def test_init():
    fs = SSHFileSystem(user="******", host="12.34.56.78", port="1234")
    assert fs.user == "test"
    assert fs.host == "12.34.56.78"
    assert fs.port == "1234"
Exemple #19
0
def test_ssh_user(mock_file, mock_exists, config, expected_user):
    fs = SSHFileSystem(**config)

    mock_exists.assert_called_with(SSHFileSystem.ssh_config_filename())
    mock_file.assert_called_with(SSHFileSystem.ssh_config_filename())
    assert fs.user == expected_user
Exemple #20
0
def test_ssh_port(mock_file, mock_exists, dvc, config, expected_port):
    fs = SSHFileSystem(dvc, config)

    mock_exists.assert_called_with(SSHFileSystem.ssh_config_filename())
    mock_file.assert_called_with(SSHFileSystem.ssh_config_filename())
    assert fs.path_info.port == expected_port
Exemple #21
0
def test_ssh_gss_auth(mock_file, mock_exists, dvc, config, expected_gss_auth):
    fs = SSHFileSystem(dvc, config)

    mock_exists.assert_called_with(SSHFileSystem.ssh_config_filename())
    mock_file.assert_called_with(SSHFileSystem.ssh_config_filename())
    assert fs.gss_auth == expected_gss_auth
Exemple #22
0
def test_ssh_keyfile(mock_file, mock_exists, dvc, config, expected_keyfile):
    fs = SSHFileSystem(dvc, config)

    mock_exists.assert_called_with(SSHFileSystem.ssh_config_filename())
    mock_file.assert_called_with(SSHFileSystem.ssh_config_filename())
    assert fs.keyfile == expected_keyfile
Exemple #23
0
def _sshfs(fs_factory, **kwargs):
    if fs_factory:
        with fs_factory() as fs:
            yield fs
        return
    yield SSHFileSystem(**kwargs)
Exemple #24
0
def test_no_path(dvc):
    config = {"url": "ssh://127.0.0.1"}
    fs = SSHFileSystem(dvc, config)
    assert fs.path_info.path == ""