Skip to content

Commit bd31a98

Browse files
authored
ci: merge main to release (#8569)
2 parents 228457a + 7f3488c commit bd31a98

File tree

4 files changed

+66
-33
lines changed

4 files changed

+66
-33
lines changed

docker/scripts/app-configure-blobstore.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright The IETF Trust 2024, All Rights Reserved
33

44
import boto3
5+
import botocore.config
6+
import botocore.exceptions
57
import os
68
import sys
79

@@ -16,13 +18,19 @@ def init_blobstore():
1618
aws_secret_access_key=os.environ.get("BLOB_STORE_SECRET_KEY", "minio_pass"),
1719
aws_session_token=None,
1820
config=botocore.config.Config(signature_version="s3v4"),
19-
verify=False,
2021
)
2122
for bucketname in MORE_STORAGE_NAMES:
22-
blobstore.create_bucket(
23-
Bucket=f"{os.environ.get('BLOB_STORE_BUCKET_PREFIX', '')}{bucketname}".strip()
24-
)
25-
23+
try:
24+
blobstore.create_bucket(
25+
Bucket=f"{os.environ.get('BLOB_STORE_BUCKET_PREFIX', '')}{bucketname}".strip()
26+
)
27+
except botocore.exceptions.ClientError as err:
28+
if err.response["Error"]["Code"] == "BucketAlreadyExists":
29+
print(f"Bucket {bucketname} already exists")
30+
else:
31+
print(f"Error creating {bucketname}: {err.response['Error']['Code']}")
32+
else:
33+
print(f"Bucket {bucketname} created")
2634

2735
if __name__ == "__main__":
2836
sys.exit(init_blobstore())

ietf/doc/storage_utils.py

+47-23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from django.core.files.base import ContentFile, File
99
from django.core.files.storage import storages
1010

11+
from ietf.utils.log import log
12+
1113

1214
# TODO-BLOBSTORE (Future, maybe after leaving 3.9) : add a return type
1315
def _get_storage(kind: str):
@@ -22,16 +24,21 @@ def _get_storage(kind: str):
2224

2325
def exists_in_storage(kind: str, name: str) -> bool:
2426
if settings.ENABLE_BLOBSTORAGE:
25-
store = _get_storage(kind)
26-
return store.exists_in_storage(kind, name)
27-
else:
28-
return False
27+
try:
28+
store = _get_storage(kind)
29+
return store.exists_in_storage(kind, name)
30+
except Exception as err:
31+
log(f"Blobstore Error: Failed to test existence of {kind}:{name}: {repr(err)}")
32+
return False
2933

3034

3135
def remove_from_storage(kind: str, name: str, warn_if_missing: bool = True) -> None:
3236
if settings.ENABLE_BLOBSTORAGE:
33-
store = _get_storage(kind)
34-
store.remove_from_storage(kind, name, warn_if_missing)
37+
try:
38+
store = _get_storage(kind)
39+
store.remove_from_storage(kind, name, warn_if_missing)
40+
except Exception as err:
41+
log(f"Blobstore Error: Failed to remove {kind}:{name}: {repr(err)}")
3542
return None
3643

3744

@@ -46,8 +53,11 @@ def store_file(
4653
) -> None:
4754
# debug.show('f"asked to store {name} into {kind}"')
4855
if settings.ENABLE_BLOBSTORAGE:
49-
store = _get_storage(kind)
50-
store.store_file(kind, name, file, allow_overwrite, doc_name, doc_rev)
56+
try:
57+
store = _get_storage(kind)
58+
store.store_file(kind, name, file, allow_overwrite, doc_name, doc_rev)
59+
except Exception as err:
60+
log(f"Blobstore Error: Failed to store file {kind}:{name}: {repr(err)}")
5161
return None
5262

5363

@@ -60,7 +70,11 @@ def store_bytes(
6070
doc_rev: Optional[str] = None,
6171
) -> None:
6272
if settings.ENABLE_BLOBSTORAGE:
63-
store_file(kind, name, ContentFile(content), allow_overwrite)
73+
try:
74+
store_file(kind, name, ContentFile(content), allow_overwrite)
75+
except Exception as err:
76+
# n.b., not likely to get an exception here because store_file or store_bytes will catch it
77+
log(f"Blobstore Error: Failed to store bytes to {kind}:{name}: {repr(err)}")
6478
return None
6579

6680

@@ -73,31 +87,41 @@ def store_str(
7387
doc_rev: Optional[str] = None,
7488
) -> None:
7589
if settings.ENABLE_BLOBSTORAGE:
76-
content_bytes = content.encode("utf-8")
77-
store_bytes(kind, name, content_bytes, allow_overwrite)
90+
try:
91+
content_bytes = content.encode("utf-8")
92+
store_bytes(kind, name, content_bytes, allow_overwrite)
93+
except Exception as err:
94+
# n.b., not likely to get an exception here because store_file or store_bytes will catch it
95+
log(f"Blobstore Error: Failed to store string to {kind}:{name}: {repr(err)}")
7896
return None
7997

8098

8199
def retrieve_bytes(kind: str, name: str) -> bytes:
82100
from ietf.doc.storage_backends import maybe_log_timing
83101
content = b""
84102
if settings.ENABLE_BLOBSTORAGE:
85-
store = _get_storage(kind)
86-
with store.open(name) as f:
87-
with maybe_log_timing(
88-
hasattr(store, "ietf_log_blob_timing") and store.ietf_log_blob_timing,
89-
"read",
90-
bucket_name=store.bucket_name if hasattr(store, "bucket_name") else "",
91-
name=name,
92-
):
93-
content = f.read()
103+
try:
104+
store = _get_storage(kind)
105+
with store.open(name) as f:
106+
with maybe_log_timing(
107+
hasattr(store, "ietf_log_blob_timing") and store.ietf_log_blob_timing,
108+
"read",
109+
bucket_name=store.bucket_name if hasattr(store, "bucket_name") else "",
110+
name=name,
111+
):
112+
content = f.read()
113+
except Exception as err:
114+
log(f"Blobstore Error: Failed to read bytes from {kind}:{name}: {repr(err)}")
94115
return content
95116

96117

97118
def retrieve_str(kind: str, name: str) -> str:
98119
content = ""
99120
if settings.ENABLE_BLOBSTORAGE:
100-
content_bytes = retrieve_bytes(kind, name)
101-
# TODO-BLOBSTORE: try to decode all the different ways doc.text() does
102-
content = content_bytes.decode("utf-8")
121+
try:
122+
content_bytes = retrieve_bytes(kind, name)
123+
# TODO-BLOBSTORE: try to decode all the different ways doc.text() does
124+
content = content_bytes.decode("utf-8")
125+
except Exception as err:
126+
log(f"Blobstore Error: Failed to read string from {kind}:{name}: {repr(err)}")
103127
return content

ietf/doc/tests_status_change.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,9 @@ def test_initial_submission(self):
564564
ftp_filepath = Path(settings.FTP_DIR) / "status-changes" / basename
565565
self.assertFalse(filepath.exists())
566566
self.assertFalse(ftp_filepath.exists())
567-
with self.assertRaises(FileNotFoundError):
568-
retrieve_str("statchg",basename)
567+
# TODO-BLOBSTORE: next assert is disabled because we currently suppress all exceptions
568+
# with self.assertRaises(FileNotFoundError):
569+
# retrieve_str("statchg",basename)
569570
r = self.client.post(url,dict(content="Some initial review text\n",submit_response="1"))
570571
self.assertEqual(r.status_code,302)
571572
doc = Document.objects.get(name='status-change-imaginary-mid-review')

ietf/utils/storage.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ def save(self, name, content, max_length=None):
4141
saved_name = super().save(name, content, max_length)
4242

4343
if settings.ENABLE_BLOBSTORAGE:
44-
# Retrieve the content and write to the blob store
45-
blob_name = Path(saved_name).name # strips path
4644
try:
45+
# Retrieve the content and write to the blob store
46+
blob_name = Path(saved_name).name # strips path
4747
with self.open(saved_name, "rb") as f:
4848
store_file(self.kind, blob_name, f, allow_overwrite=True)
4949
except Exception as err:
50-
log(f"Failed to shadow {saved_name} at {self.kind}:{blob_name}: {err}")
50+
log(f"Blobstore Error: Failed to shadow {saved_name} at {self.kind}:{blob_name}: {repr(err)}")
5151
return saved_name # includes the path!
5252

5353
def deconstruct(self):

0 commit comments

Comments
 (0)