def test_ssh_host_override_from_config(mock_file, mock_exists, dvc, config, expected_host): remote = SSHRemote(dvc, config) mock_exists.assert_called_with(SSHRemoteTree.ssh_config_filename()) mock_file.assert_called_with(SSHRemoteTree.ssh_config_filename()) assert remote.tree.path_info.host == expected_host
def test_hardlink_optimization(dvc, tmp_dir, ssh_server): port = ssh_server.test_creds["port"] user = ssh_server.test_creds["username"] config = { "url": SSHMocked.get_url(user, port), "port": port, "user": user, "keyfile": ssh_server.test_creds["key_filename"], } tree = SSHRemoteTree(dvc, config) from_info = tree.path_info / "empty" to_info = tree.path_info / "link" with tree.open(from_info, "wb"): pass if os.name == "nt": link_path = "c:" + to_info.path.replace("/", "\\") else: link_path = to_info.path tree.hardlink(from_info, to_info) assert not System.is_hardlink(link_path)
def test_hardlink_optimization(dvc, tmp_dir, ssh): tree = SSHRemoteTree(dvc, ssh.config) from_info = tree.path_info / "empty" to_info = tree.path_info / "link" with tree.open(from_info, "wb"): pass if os.name == "nt": link_path = "c:" + to_info.path.replace("/", "\\") else: link_path = to_info.path tree.hardlink(from_info, to_info) assert not System.is_hardlink(link_path)
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} tree = SSHRemoteTree(dvc, config) assert tree.path_info == url # SCP-like URL ssh://[user@]host.xz:/absolute/path url = f"ssh://{user}@{host}:{path}" config = {"url": url} tree = SSHRemoteTree(dvc, config) assert tree.path_info == url
def test_ssh_user(mock_file, mock_exists, dvc, config, expected_user): tree = SSHRemoteTree(dvc, config) mock_exists.assert_called_with(SSHRemoteTree.ssh_config_filename()) mock_file.assert_called_with(SSHRemoteTree.ssh_config_filename()) assert tree.path_info.user == expected_user
def test_no_path(dvc): config = {"url": "ssh://127.0.0.1"} tree = SSHRemoteTree(dvc, config) assert tree.path_info.path == ""
def test_ssh_gss_auth(mock_file, mock_exists, dvc, config, expected_gss_auth): tree = SSHRemoteTree(dvc, config) mock_exists.assert_called_with(SSHRemoteTree.ssh_config_filename()) mock_file.assert_called_with(SSHRemoteTree.ssh_config_filename()) assert tree.gss_auth == expected_gss_auth
def test_ssh_keyfile(mock_file, mock_exists, dvc, config, expected_keyfile): tree = SSHRemoteTree(dvc, config) mock_exists.assert_called_with(SSHRemoteTree.ssh_config_filename()) mock_file.assert_called_with(SSHRemoteTree.ssh_config_filename()) assert tree.keyfile == expected_keyfile
def test_ssh_port(mock_file, mock_exists, dvc, config, expected_port): remote = SSHRemote(dvc, config) mock_exists.assert_called_with(SSHRemoteTree.ssh_config_filename()) mock_file.assert_called_with(SSHRemoteTree.ssh_config_filename()) assert remote.path_info.port == expected_port