| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import os |
| 8 |
import shutil |
| 9 |
import subprocess |
| 10 |
|
| 11 |
from rsyncfns import ( |
| 12 |
CHKDIR, FROMDIR, SCRATCHDIR, TMPDIR, TODIR, |
| 13 |
build_rsyncd_conf, checkit, hands_setup, rmtree, |
| 14 |
run_rsync, start_test_daemon, test_fail, |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
DAEMON_PORT = 12874 |
| 19 |
|
| 20 |
conf = build_rsyncd_conf() |
| 21 |
hands_setup() |
| 22 |
|
| 23 |
os.chdir(TMPDIR) |
| 24 |
|
| 25 |
|
| 26 |
run_rsync('-av', '--exclude=foobar.baz', f'{FROMDIR}/', f'{CHKDIR}/') |
| 27 |
|
| 28 |
|
| 29 |
run_rsync('-av', '--only-write-batch=BATCH', '--exclude=foobar.baz', |
| 30 |
f'{FROMDIR}/', f'{TODIR}/missing/') |
| 31 |
if (TODIR / 'missing').is_dir(): |
| 32 |
test_fail("--only-write-batch should not have created destination dir") |
| 33 |
|
| 34 |
print("Test --read-batch (only):") |
| 35 |
checkit(['-av', '--read-batch=BATCH', str(TODIR)], CHKDIR, TODIR) |
| 36 |
|
| 37 |
|
| 38 |
rmtree(TODIR) |
| 39 |
for batch in TMPDIR.glob('BATCH*'): |
| 40 |
batch.unlink() |
| 41 |
|
| 42 |
print("Test local --write-batch:") |
| 43 |
checkit(['-av', '--write-batch=BATCH', f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR) |
| 44 |
|
| 45 |
rmtree(TODIR) |
| 46 |
print("Test --read-batch:") |
| 47 |
checkit(['-av', '--read-batch=BATCH', str(TODIR)], FROMDIR, TODIR) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 52 |
|
| 53 |
rmtree(TODIR) |
| 54 |
print("Test daemon sender --write-batch:") |
| 55 |
checkit(['-av', '--write-batch=BATCH', |
| 56 |
f'{url}test-from/', str(TODIR)], |
| 57 |
CHKDIR, TODIR, allowed_codes=(0, 23)) |
| 58 |
|
| 59 |
rmtree(TODIR) |
| 60 |
print("Test --read-batch from daemon:") |
| 61 |
checkit(['-av', '--read-batch=BATCH', str(TODIR)], CHKDIR, TODIR) |
| 62 |
|
| 63 |
rmtree(TODIR) |
| 64 |
print("Test BATCH.sh use of --read-batch:") |
| 65 |
|
| 66 |
|
| 67 |
from rsyncfns import verify_dirs |
| 68 |
proc = subprocess.run(['sh', './BATCH.sh']) |
| 69 |
if proc.returncode != 0: |
| 70 |
test_fail(f"BATCH.sh exited {proc.returncode}") |
| 71 |
verify_dirs(CHKDIR, TODIR, label="BATCH.sh use of --read-batch") |
| 72 |
|
| 73 |
print("Test do-nothing re-run of batch:") |
| 74 |
proc = subprocess.run(['sh', './BATCH.sh']) |
| 75 |
if proc.returncode != 0: |
| 76 |
test_fail(f"BATCH.sh (re-run) exited {proc.returncode}") |
| 77 |
verify_dirs(CHKDIR, TODIR, label="do-nothing re-run of batch") |
| 78 |
|
| 79 |
rmtree(TODIR) |
| 80 |
TODIR.mkdir() |
| 81 |
print("Test daemon recv --write-batch:") |
| 82 |
|
| 83 |
|
| 84 |
ignore23 = SCRATCHDIR / 'ignore23' |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
from rsyncfns import rsync_argv |
| 89 |
proc = subprocess.run( |
| 90 |
[str(ignore23), *rsync_argv('-av', '--write-batch=BATCH', |
| 91 |
f'{FROMDIR}/', f'{url}test-to')], |
| 92 |
) |
| 93 |
if proc.returncode != 0: |
| 94 |
test_fail(f"daemon recv --write-batch exited {proc.returncode}") |
| 95 |
verify_dirs(CHKDIR, TODIR, label="daemon recv --write-batch") |