-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
test/python/WMCore_t/MicroService_t/MSUnmerged_t/test_gfal.py
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,42 @@ | ||
#!/usr/bin/env python | ||
import logging | ||
|
||
try: | ||
import gfal2 | ||
except ImportError: | ||
# in case we do not have gfal2 installed | ||
print("FAILED to import gfal2. Use it only in emulateGfal2=True mode!!!") | ||
gfal2 = None | ||
|
||
def createGfal2Context(logLevel="normal", emulate=False): | ||
""" | ||
Create a gfal2 context object | ||
:param logLevel: string with the gfal2 log level | ||
:param emulate: boolean to be used by unit tests | ||
:return: the gfal2 context object | ||
""" | ||
if emulate: | ||
return None | ||
ctx = gfal2.creat_context() | ||
gfal2.set_verbose(gfal2.verbose_level.names[logLevel]) | ||
return ctx | ||
|
||
def testGFAL(ctx): | ||
logger = logging.getLogger() | ||
rseDirs = ["/store/unmerged/Run3Summer22EENanoAODv11/Wto2Q-3Jets_HT-200to400_TuneCP5_13p6TeV_madgraphMLM-pythia8/NANOAODSIM/126X_mcRun3_2022_realistic_postEE_v1-v3", | ||
"/store/unmerged/RunIISummer20UL18NanoAODv9/GluGluHoffshell_HToWWToENuTauNu_TuneCP5_13TeV_MCFM701-pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v2"] | ||
|
||
for dirPfn in rseDirs: | ||
try: | ||
# NOTE: For gfal2 rmdir() exit status of 0 is success | ||
rmdirSuccess = ctx.rmdir(dirPfn) == 0 | ||
except gfal2.GError as gfalExc: | ||
logger.warning("MISSING directory: %s, gfal code=%s", dirPfn, gfalExc.code) | ||
|
||
def main(): | ||
ctx = createGfal2Context() | ||
testGFAL(ctx) | ||
print("succeeded") | ||
|
||
if __name__ == '__main__': | ||
main() |