def test_prepare_migration_scripts(): configs = [ SourceFiles('source_host1', 'source_dir1', 'target_dir1', rsync_args=['--checksum'], files=[], exclude=[]), SourceFiles('source_host1', 'source_dir2', 'target_dir2', files=['file3', 'file4'], exclude=[]), SourceFiles('source_host2', 'source_dir1', 'target_dir1', files=['file5', 'file6'], exclude=['logs/*', 'file.conf']) ] target_host = 'target_host1' prepare_file_copy_scripts(target_host, configs, SCRIPT_ROOT) _check_file_contents( os.path.join(SCRIPT_ROOT, target_host, FILE_MIGRATION_RSYNC_SCRIPT), os.path.join(TEST_DATA_DIR, FILE_MIGRATION_RSYNC_SCRIPT)) for config in configs[1:]: # first config has no files list file_list_filename = get_file_list_filename(config) file_path = os.path.join(SCRIPT_ROOT, target_host, file_list_filename) file_list = get_file_contents(file_path).splitlines() assert_equal(file_list, config.files)
def test_get_migration_file_configs(plan_name): migration = _get_migration(plan_name) migration_file_configs = _generate_plan_and_rsync_lists(migration, plan_name) for target_host, migration_configs in migration_file_configs.items(): for config in migration_configs: file_name = get_file_list_filename(config) actual = get_file_contents(os.path.join(migration.rsync_files_path, target_host, file_name)) expected = _get_test_file(plan_name, 'expected_{}'.format(file_name)) assert expected == actual, "file lists mismatch:\n\nExpected\n{}\nActual\n{}".format(expected, actual)
def test_prepare_migration_scripts(): configs = [ SourceFiles( 'source_host1', 'source_dir1', 'target_dir1', rsync_args=['--checksum'], files=[], exclude=[] ), SourceFiles( 'source_host1', 'source_dir2', 'target_dir2', files=['file3', 'file4'], exclude=[] ), SourceFiles( 'source_host2', 'source_dir1', 'target_dir1', files=['file5', 'file6'], exclude=['logs/*', 'file.conf'] ) ] target_host = 'target_host1' prepare_file_copy_scripts(target_host, configs, SCRIPT_ROOT) _check_file_contents( os.path.join(SCRIPT_ROOT, target_host, FILE_MIGRATION_RSYNC_SCRIPT), os.path.join(TEST_DATA_DIR, FILE_MIGRATION_RSYNC_SCRIPT) ) for config in configs[1:]: # first config has no files list file_list_filename = get_file_list_filename(config) file_path = os.path.join(SCRIPT_ROOT, target_host, file_list_filename) file_list = get_file_contents(file_path).splitlines() assert_equal(file_list, config.files)
def _get_test_file(plan_name, filename): return get_file_contents(os.path.join(PLANS_DIR, plan_name, filename))
def _check_file_contents(generated_path, expected_path): expected_script = get_file_contents(expected_path) script_source = get_file_contents(generated_path) assert_multi_line_equal.__self__.maxDiff = None assert_multi_line_equal(expected_script.strip(), script_source.strip())