def _ssh_factory(cloud): yield SSHFileSystem( host=cloud.host, port=cloud.port, user=TEST_SSH_USER, keyfile=TEST_SSH_KEY_PATH, )
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
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
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"
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
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
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
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)
def test_ssh_host_override_from_config(mock_file, config, expected_host): fs = SSHFileSystem(**config) assert fs.fs_args["host"] == expected_host
def test_ssh_keyfile(mock_file, config, expected_keyfile): fs = SSHFileSystem(**config) assert fs.fs_args.get("client_keys") == expected_keyfile
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"
def test_ssh_multi_identity_files(mock_file): fs = SSHFileSystem(host="example.com") assert fs.fs_args.get("client_keys") == ["file_1", "file_2"]
def test_ssh_gss_auth(mock_file, config, expected_gss_auth): fs = SSHFileSystem(**config) assert fs.fs_args["gss_auth"] == expected_gss_auth
def test_ssh_port(mock_file, config, expected_port): fs = SSHFileSystem(**config) assert fs.fs_args["port"] == expected_port
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
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
def test_ssh_user(mock_file, config, expected_user): fs = SSHFileSystem(**config) assert fs.fs_args["username"] == expected_user
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"
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
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
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
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
def _sshfs(fs_factory, **kwargs): if fs_factory: with fs_factory() as fs: yield fs return yield SSHFileSystem(**kwargs)
def test_no_path(dvc): config = {"url": "ssh://127.0.0.1"} fs = SSHFileSystem(dvc, config) assert fs.path_info.path == ""