Skip to content

Commit 9880e58

Browse files
authored
Merge pull request #8075 from DIRACGridBot/cherry-pick-2-1f3069978-integration
[sweep:integration] feat (Storage): disable bearer plugins unless copying files
2 parents 1471164 + 333ba12 commit 9880e58

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/DIRAC/Resources/Storage/GFAL2_StorageBase.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ def __init__(self, storageName: str, parameters: dict[str, str]):
165165
os.environ.get("DIRAC_GFAL_GRIDFTP_ENABLE_IPV6", "true").lower() not in ["false", "no"],
166166
)
167167

168+
# Disable retrieving the bearer token for every operations.
169+
# It is only useful for TPC
170+
self.ctx.set_opt_boolean("HTTP PLUGIN", "RETRIEVE_BEARER_TOKEN", False)
171+
168172
# spaceToken used for copying from and to the storage element
169173
self.spaceToken = parameters.get("SpaceToken", "")
170174
# stageTimeout, default timeout to try and stage/pin a file
@@ -305,20 +309,23 @@ def putFile(self, path, sourceSize: int = 0):
305309
failed = {}
306310
successful = {}
307311

308-
for dest_url, src_file in urls.items():
309-
if not src_file:
310-
errStr = "GFAL2_StorageBase.putFile: Source file not set. Argument must be a dictionary \
311-
(or a list of a dictionary) {url : local path}"
312-
self.log.debug(errStr)
313-
failed[dest_url] = errStr
314-
continue
312+
# In principle we only need the bearer token when doing TPC, however it's a
313+
# bit cumbersome to test, so we always re-enable it when uploading
314+
with setGfalSetting(self.ctx, "HTTP PLUGIN", "RETRIEVE_BEARER_TOKEN", True):
315+
for dest_url, src_file in urls.items():
316+
if not src_file:
317+
errStr = "GFAL2_StorageBase.putFile: Source file not set. Argument must be a dictionary \
318+
(or a list of a dictionary) {url : local path}"
319+
self.log.debug(errStr)
320+
failed[dest_url] = errStr
321+
continue
315322

316-
try:
317-
successful[dest_url] = self._putSingleFile(src_file, dest_url, sourceSize)
318-
except (gfal2.GError, ValueError, RuntimeError) as e:
319-
detailMsg = f"Failed to copy {src_file} to {dest_url}: {repr(e)}"
320-
self.log.debug("Exception while copying", detailMsg)
321-
failed[dest_url] = detailMsg
323+
try:
324+
successful[dest_url] = self._putSingleFile(src_file, dest_url, sourceSize)
325+
except (gfal2.GError, ValueError, RuntimeError) as e:
326+
detailMsg = f"Failed to copy {src_file} to {dest_url}: {repr(e)}"
327+
self.log.debug("Exception while copying", detailMsg)
328+
failed[dest_url] = detailMsg
322329

323330
return {"Failed": failed, "Successful": successful}
324331

0 commit comments

Comments
 (0)