def test_rsync_throws_both_remotes(): """raises RemotesError when both source and destination are remotes""" source_ssh = 'host1' source = '/a' target_ssh = 'host2' target = '/b' get_rsync_command(source, target, source_ssh=source_ssh, destination_ssh=target_ssh)
def test_simple_rsync_command_content_false(): source = '/a' target = '/b' expect = 'rsync /a /b'.split() result = get_rsync_command(source, target, sync_source_contents=False) eq_(expect, result)
def test_simple_rsync_command(): source = '/a' target = '/b' expect = 'rsync /a/ /b'.split() result = get_rsync_command(source, target) eq_(expect, result)
def test_rsync_exclusions(): source = '/a' target = '/b' exclusions = ['file1', 'file2'] expect = 'rsync /a/ /b --exclude file1 --exclude file2'.split() result = get_rsync_command(source, target, exclusions=exclusions) eq_(expect, result)
def test_rsync_options(): source = '/a' target = '/b' options = ['-a', '--verbose'] expect = 'rsync -a --verbose /a/ /b'.split() result = get_rsync_command(source, target, options=options) eq_(expect, result)
def test_rsync_private_key(): """test if get_rsync_command raises PrivateKeyError when key missing""" source_dir = '/home/user/files/' target_dir = '/home/server/files' destination_ssh = 'myserver' private_key = 'this_file_does_not_exist' actual = get_rsync_command(source=source_dir, destination=target_dir, destination_ssh=destination_ssh, private_key=private_key)
def test_rsync_exclusions_target_ssh(): source = '/a' target_ssh = 'host1' target = '/b' exclusions = ['file1', 'file2'] expect = 'rsync /a/ host1:/b --exclude file1 --exclude file2'.split() result = get_rsync_command(source, target, exclusions=exclusions, destination_ssh=target_ssh) eq_(expect, result)
def test_rsync_exclusions_source_ssh(): source = '/a' source_ssh = 'host1' target = '/b' exclusions = ['file1', 'file2'] expect = 'rsync host1:/a/ /b --exclude file1 --exclude file2'.split() result = get_rsync_command(source, target, exclusions=exclusions, source_ssh=source_ssh) eq_(expect, result)
def run(cwd=os.getcwd(), strict=True, verbose=False, **kwargs): rsync_command = get_rsync_command(**kwargs) rsync_string = ' '.join(rsync_command) if verbose is True: print(f'[sysrsync runner] running command on "{cwd}":') print(rsync_string) process = subprocess.run(rsync_string, cwd=cwd, shell=True) if strict is True: code = process.returncode _check_return_code(code, rsync_string) return process
def test_rsync_private_key(): """test if correctly creates rsh option when passing a private key""" with TemporaryFile() as temp_file: source_dir = '/home/user/files/' target_dir = '/home/server/files' destination_ssh = 'myserver' expect = [ 'rsync', f"--rsh='ssh -i {temp_file}'", source_dir, f'{destination_ssh}:{target_dir}' ] actual = get_rsync_command(source=source_dir, destination=target_dir, destination_ssh=destination_ssh, private_key=temp_file) eq_(expect, actual)