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)
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)
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
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)
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)
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)
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)
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)
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
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}
def test_no_path(self): config = {"url": "ssh://127.0.0.1"} remote = RemoteSSH(None, config) self.assertEqual(remote.prefix, "/")
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
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
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
def test_no_path(dvc): config = {"url": "ssh://127.0.0.1"} remote = RemoteSSH(dvc, config) assert remote.path_info.path == ""
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