def test_base_sha_corrupted(capsys): sleep(1) # make sure the backup timestamps differ with itest_setup( test_file_history, _TestFileData('bar', 'asdfasdfasdf'), _TestFileData('foo', 'asdfasdfasd'), ): BACKUP_ARGS.dry_run = False backup(BACKUP_ARGS) backup_store = get_backup_store('data1_backup') with backup_store.unlock(preserve_scratch=True): backup_store.manifest._cursor.execute( 'update manifest set key_pair=? where abs_file_name like ? ', (b'hjkl', '%bar'), ) backup_store.manifest._commit() VERIFY_ARGS.fast = False verify(VERIFY_ARGS) out, _ = capsys.readouterr() assert 'ERROR' in out # Shouldn't create duplicate entries when we fix with backup_store.unlock(preserve_scratch=True): backup_store.manifest._cursor.execute('select * from manifest') rows = backup_store.manifest._cursor.fetchall() assert len(rows) == 3 # After the fix, verify should be clean verify(VERIFY_ARGS) out, _ = capsys.readouterr() assert 'ERROR' not in out
def contents_changed(): with itest_setup( test_file_history, _TestFileData('foo', 'adz foobar'), _TestFileData('bar', 'hhhhh'), ): yield
def setup_manifest(): clean_up_temp_directories() with itest_setup( test_file_history, _TestFileData('foo', 'asdf'), _TestFileData('bar', 'hjkl'), _TestFileData('baz/buz', 'qwerty'), ): backup(BACKUP_ARGS) yield
def run_backup(use_encryption): global test_file_history test_file_history = dict() clean_up_temp_directories() with itest_setup( test_file_history, _TestFileData('foo', 'asdfasdfasdf'), ): BACKUP_ARGS.dry_run = False backup(BACKUP_ARGS)
def test_f2_lbs_atomicity_1(): sys.settrace(make_trace_func('test_f2_lbs_atomicity_1', abort)) with itest_setup( test_file_history, _TestFileData('new_file_2', '1234'), ): backup(BACKUP_ARGS) file_data_path = os.path.join(DATA_DIR, 'new_file_2') file_backup_path = os.path.join( BACKUP_DIR, sha_to_path(test_file_history[file_data_path][0].sha), ) assert not os.path.exists(file_backup_path)
def test_m1_crash_before_save(): sys.settrace(make_trace_func('test_m1_crash_before_save', abort)) with itest_setup( test_file_history, _TestFileData('foo', 'asdfhjkl'), ), pytest.raises(Exception): backup(BACKUP_ARGS) assert_manifest_correct(before=True) file_data_path = os.path.join(DATA_DIR, 'foo') file_backup_path = os.path.join( BACKUP_DIR, sha_to_path(test_file_history[file_data_path][1].sha), ) assert os.path.exists(file_backup_path)
def test_m2_crash_before_file_save(): sys.settrace(make_trace_func('test_m2_crash_before_file_save', abort)) with itest_setup( test_file_history, _TestFileData('another_file', '1234'), ): backup(BACKUP_ARGS) manifest_conn = sqlite3.connect(get_latest_manifest()) manifest_conn.row_factory = sqlite3.Row manifest_cursor = manifest_conn.cursor() manifest_cursor.execute( 'select * from manifest where abs_file_name like "%another_file"') rows = manifest_cursor.fetchall() assert not rows
def test_f1_crash_file_save(): sys.settrace(make_trace_func('test_f1_crash_file_save', abort)) with itest_setup( test_file_history, _TestFileData('foo', 'asdfhjkl'), _TestFileData('new_file', 'zxcv'), ): backup(BACKUP_ARGS) first_file_data_path = os.path.join(DATA_DIR, 'foo') second_file_data_path = os.path.join(DATA_DIR, 'new_file') first_file_backup_path = os.path.join( BACKUP_DIR, sha_to_path(test_file_history[first_file_data_path][1].sha), ) second_file_backup_path = os.path.join( BACKUP_DIR, sha_to_path(test_file_history[second_file_data_path][0].sha), ) assert not os.path.exists(first_file_backup_path) assert os.path.exists(second_file_backup_path) # reset everything back to "normal" before the next test backup(BACKUP_ARGS)
def initial_backup_files(): with itest_setup( test_file_history, _TestFileData('foo', 'asdf'), _TestFileData('bar', 'hjkl'), _TestFileData('baz/buz', 'qwerty'), _TestFileData('dont_back_me_up_1', 'secrets!'), _TestFileData('baz/dont_back_me_up_2', 'moar secrets!'), _TestFileData('fizzbuzz', 'I am a walrus', data_dir_index=1), ): yield
def test_f3_file_changed_while_saving(): sys.settrace( make_trace_func( 'test_f3_file_changed_while_saving', make_modify_file_func(os.path.join(DATA_DIR, 'new_file_3')), )) with itest_setup( test_file_history, _TestFileData('new_file_3', '12345'), ): backup(BACKUP_ARGS) file_data_path = os.path.join(DATA_DIR, 'new_file_3') file_backup_path = os.path.join( BACKUP_DIR, sha_to_path(test_file_history[file_data_path][0].sha), ) assert not os.path.exists(file_backup_path)
def test_shas_with_bad_key_pairs(both_bad, capsys): with itest_setup( test_file_history, _TestFileData('bar', 'asdfasdfasdf'), ): BACKUP_ARGS.dry_run = False backup(BACKUP_ARGS) VERIFY_ARGS.fast = True backup_store = get_backup_store('data1_backup') with backup_store.unlock(preserve_scratch=True): backup_store.manifest._cursor.execute( 'update manifest set key_pair=? where abs_file_name like ?', (b'asdf', '%bar'), ) if both_bad: backup_store.manifest._cursor.execute( 'update manifest set key_pair=? where abs_file_name like ?', (b'hjkl', '%foo'), ) backup_store.manifest._commit() verify(VERIFY_ARGS) out, _ = capsys.readouterr() assert 'Found 2 entries for' in out if both_bad: assert 'No valid entries' in out else: assert 'seems good' in out # Shouldn't create duplicate entries when we fix with backup_store.unlock(preserve_scratch=True): backup_store.manifest._cursor.execute('select * from manifest') rows = backup_store.manifest._cursor.fetchall() assert len(rows) == 2 # After the fix, verify should be clean VERIFY_ARGS.fast = False verify(VERIFY_ARGS) out, _ = capsys.readouterr() assert 'ERROR' not in out
def old_file_same_contents(): with itest_setup( test_file_history, _TestFileData('bar', 'I am a walrus'), # this points at an original ): yield
def new_file_same_contents(): with itest_setup( test_file_history, _TestFileData('new_file', 'adz foobar'), # this points at a diff ): yield
def contents_changed_after_delete(): with itest_setup( test_file_history, _TestFileData('foo', 'adfoo blah blah blah blah blah'), ): yield
def mode_changed(): with itest_setup( test_file_history, _TestFileData('foo', 'adz foobar', mode=0o100755), ): yield
def file_restored(): with itest_setup( test_file_history, _TestFileData('foo', 'adz foobar'), ): yield
def file_deleted(): with itest_setup( test_file_history, _TestFileData('foo', None), ): yield