def test_delete_keys(tmpdir): """Verify keys are deleted and bucket is trimmed""" base = str(tmpdir.mkdir("base")) file_list = [base + "/subdir1/file.txt", base + "/subdir2/file.txt"] create_files(file_list) store = StorageLayout("file://localhost/" + base) backup = FileBackup(store, "", "") conn = backup.cinfo.connect("") bucket = conn.get_bucket("") bucket.delete_keys(file_list) assert len(os.listdir(base)) == 0
def test_bucket_list(tmpdir): """Verify bucket keys can be listed""" base = str(tmpdir.mkdir("base")) file_list = [base + "/subdirfile.txt", base + "/subdir/file.txt"] create_files(file_list) store = StorageLayout("file://localhost/" + base) backup = FileBackup(store, "", "") conn = backup.cinfo.connect("") bucket = conn.get_bucket("") result = bucket.list(base) assert len(result) == len(file_list) for f in file_list: matches = [x for x in result if x.path == f] assert len(matches) == 1 assert hasattr(matches[0], 'size') is True assert hasattr(matches[0], 'last_modified') is True
def test_write_and_return_error_with_error(tmpdir): """Verify exception as result in error operation""" base = str(tmpdir.mkdir("base")) file_list = [base + "/src.txt"] create_files(file_list) store = StorageLayout("file://localhost/" + base) backup = FileBackup(store, "", "") conn = backup.cinfo.connect("") bucket = conn.get_bucket("") f = open(base + "/dst.txt", "wb") key = bucket.get_key(base + "/missing.txt") with pytest.raises(IOError) as e: result = write_and_return_error(key, f) raise result assert e.value.errno == errno.ENOENT
def test_write_and_return_error(tmpdir): """Verify None as result in normal operation""" base = str(tmpdir.mkdir("base")) file_list = [base + "/src.txt"] create_files(file_list) store = StorageLayout("file://localhost/" + base) backup = FileBackup(store, "", "") conn = backup.cinfo.connect("") bucket = conn.get_bucket("") f = open(base + "/dst.txt", "wb") key = bucket.get_key(base + "/src.txt") result = write_and_return_error(key, f) assert result is None with open(base + "/dst.txt", "rb") as dst_file: assert dst_file.read() == file_list[0].encode('utf-8')
def test_backup_list(sts_conn): """Test BackupList's compatibility with a test policy.""" bn = 'wal-e.sts.backup.list' h = 's3-us-west-1.amazonaws.com' cf = connection.OrdinaryCallingFormat() fed = sts_conn.get_federation_token('wal-e-test-backup-list', policy=make_policy(bn, 'test-prefix')) layout = StorageLayout('s3://{0}/test-prefix'.format(bn)) creds = Credentials(fed.credentials.access_key, fed.credentials.secret_key, fed.credentials.session_token) with FreshBucket(bn, calling_format=cf, host=h) as fb: fb.create(location='us-west-1') cinfo = calling_format.from_store_name(bn) conn = cinfo.connect(creds) conn.host = h backups = list(BackupList(conn, layout, True)) assert not backups
def test_invalid_prefix(): with pytest.raises(exception.UserException): StorageLayout("notfile://localhost/tmp")
def test_valid_prefix(): store = StorageLayout("file://localhost/tmp") assert store.is_file is True