Debian Codegraph @

testsuite/ssh-basic_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/ssh-basic.test.
3 #
4 # Basic two-step "remote shell" transfer via lsh.sh (or real ssh if
5 # rsync_enable_ssh_tests=yes is set in shconfig). Confirms that an -e
6 # RSH transfer reproduces the source tree on the destination, and that
7 # a follow-up --delete pass cleans up after a destination-side rename.
8
9 import os
10 import shutil
11 import subprocess
12
13 from rsyncfns import (
14 FROMDIR, SRCDIR, TODIR,
15 checkit, hands_setup, runtest, test_skipped, rsync_path_arg, rsh_cmd,
16 )
17
18
19 SSH = rsh_cmd()
20
21 # Allow opting into real ssh via the shconfig variable, like the shell test.
22 if os.environ.get('rsync_enable_ssh_tests') == 'yes':
23 real_ssh = shutil.which('ssh')
24 if real_ssh:
25 SSH = real_ssh
26
27 probe = subprocess.run(
28 [SSH, '-oBatchMode yes', 'localhost', 'echo', 'yes'],
29 capture_output=True, text=True,
30 )
31 if probe.stdout.strip() != 'yes':
32 test_skipped(
33 "Skipping SSH tests because ssh connection to localhost not authorised"
34 )
35
36 print(f"Using remote shell: {SSH}")
37
38 hands_setup()
39
40 # RSYNC may be a multi-word command line; pass it through --rsync-path.
41 from rsyncfns import RSYNC, RSYNC_PEER
42
43
44 def _basic():
45 checkit(['-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}',
46 f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
47
48
49 def _delete_after_rename():
50 shutil.move(str(TODIR / 'text'), str(TODIR / 'ThisShouldGo'))
51 checkit(['--delete', '-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}',
52 f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
53
54
55 runtest("ssh: basic test", _basic)
56 runtest("ssh: renamed file", _delete_after_rename)