-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement persistent bucket fixtures for integration tests (#1046)
* Add persistent bucket fixtures * Refactor integration tests to use persistent bucket where applicable * Adjust SSE-C¬ifcation rules tests to use const bucket \w subfolders * Remove account_info_file dependency in persistent bucket creation * Clean up * Refactor persistent bucket cleanup in tests: manual clear, remove auto-teardown, add error handling * Add changelog * Add full-stops * Format * Retry on duplicate bucket in persistent bucket get_or_create * Improve changelog * Don't clean up the persistent bucket's subfolder after each test case * Rename persistent bucket fixture * Delete forgotten pass stmt * Change changelog catregory * Don't clean up persistent bucket after on teardown * Revert changes to cleanup_buckets.py * Clean dead code
- Loading branch information
1 parent
2f942e0
commit f768453
Showing
5 changed files
with
538 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve internal testing infrastructure by updating integration tests to use persistent buckets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
###################################################################### | ||
# | ||
# File: test/integration/persistent_bucket.py | ||
# | ||
# Copyright 2024 Backblaze Inc. All Rights Reserved. | ||
# | ||
# License https://www.backblaze.com/using_b2_code.html | ||
# | ||
###################################################################### | ||
import hashlib | ||
import os | ||
from dataclasses import dataclass | ||
from functools import cached_property | ||
from test.integration.helpers import BUCKET_NAME_LENGTH, Api | ||
|
||
import backoff | ||
from b2sdk.v2 import Bucket | ||
from b2sdk.v2.exception import DuplicateBucketName, NonExistentBucket | ||
|
||
PERSISTENT_BUCKET_NAME_PREFIX = "constst" | ||
|
||
|
||
@dataclass | ||
class PersistentBucketAggregate: | ||
bucket_name: str | ||
subfolder: str | ||
|
||
@cached_property | ||
def virtual_bucket_name(self): | ||
return f"{self.bucket_name}/{self.subfolder}" | ||
|
||
|
||
def get_persistent_bucket_name(b2_api: Api) -> str: | ||
bucket_base = os.environ.get("GITHUB_REPOSITORY_ID", b2_api.api.get_account_id()) | ||
bucket_hash = hashlib.sha256(bucket_base.encode()).hexdigest() | ||
return f"{PERSISTENT_BUCKET_NAME_PREFIX}-{bucket_hash}" [:BUCKET_NAME_LENGTH] | ||
|
||
|
||
@backoff.on_exception( | ||
backoff.expo, | ||
DuplicateBucketName, | ||
max_tries=3, | ||
jitter=backoff.full_jitter, | ||
) | ||
def get_or_create_persistent_bucket(b2_api: Api) -> Bucket: | ||
bucket_name = get_persistent_bucket_name(b2_api) | ||
try: | ||
bucket = b2_api.api.get_bucket_by_name(bucket_name) | ||
except NonExistentBucket: | ||
bucket = b2_api.api.create_bucket( | ||
bucket_name, | ||
bucket_type="allPublic", | ||
lifecycle_rules=[ | ||
{ | ||
"daysFromHidingToDeleting": 1, | ||
"daysFromUploadingToHiding": 1, | ||
"fileNamePrefix": "", | ||
} | ||
], | ||
) | ||
# add the new bucket name to the list of bucket names | ||
b2_api.bucket_name_log.append(bucket_name) | ||
return bucket |
Oops, something went wrong.