Skip to content

Commit 121eea5

Browse files
authored
Merge pull request #7371 from fstagni/use_CVMFS_locations
[8.0] using CVMFS_locations for discovering the pilot files
2 parents ef6e51f + bb97255 commit 121eea5

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed

src/DIRAC/WorkloadManagementSystem/Utilities/PilotWrapper.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
localPilot = pilotWrapperScript(pilotFilesCompressedEncodedDict,
99
pilotOptions,
1010
pilotExecDir)
11-
_writePilotWrapperFile(localPilot=localPilot)
11+
_writePilotWrapperFile(localPilot=localPilot)
1212
1313
"""
14-
from __future__ import absolute_import
15-
from __future__ import division
16-
from __future__ import print_function
14+
from __future__ import absolute_import, division, print_function
1715

18-
import os
19-
import tempfile
2016
import base64
2117
import bz2
18+
import os
19+
import tempfile
2220

2321
pilotWrapperContent = """#!/bin/bash
2422
if command -v python &> /dev/null; then
@@ -78,7 +76,12 @@
7876

7977

8078
def pilotWrapperScript(
81-
pilotFilesCompressedEncodedDict=None, pilotOptions="", pilotExecDir="", envVariables=None, location=""
79+
pilotFilesCompressedEncodedDict=None,
80+
pilotOptions="",
81+
pilotExecDir="",
82+
envVariables=None,
83+
location="",
84+
CVMFS_locations=None,
8285
):
8386
"""Returns the content of the pilot wrapper script.
8487
@@ -95,6 +98,8 @@ def pilotWrapperScript(
9598
:type envVariables: dict
9699
:param location: location where to get the pilot files
97100
:type location: string
101+
:param CVMFS_locations: optional CVMFS locations of where to get the pilot files
102+
:type CVMFS_locations: list
98103
99104
:returns: content of the pilot wrapper
100105
:rtype: string
@@ -106,6 +111,20 @@ def pilotWrapperScript(
106111
if envVariables is None:
107112
envVariables = {}
108113

114+
if CVMFS_locations is None:
115+
# What is in this location is almost certainly incorrect, especially the pilot.json
116+
CVMFS_locs = '["file:/cvmfs/dirac.egi.eu/pilot"]'
117+
else:
118+
# Here we are making the assumption that, if CVMFS_locations is, e.g., ['/cvmfs/somewhere', '/cvmfs/elsewhere']
119+
# and the project is 'LHCb',
120+
# then the pilot can maybe be found at locations
121+
# - file:/cvmfs/somewhere/lhcbdirac/pilot
122+
# - file:/cvmfs/elsewhere/lhcbdirac/pilot
123+
project = "dirac"
124+
if "-l" in pilotOptions:
125+
project = pilotOptions.split(" ")[pilotOptions.split(" ").index("-l") + 1].lower() + "dirac"
126+
CVMFS_locs = "[" + ",".join('"file:' + os.path.join(loc, project, 'pilot"') for loc in CVMFS_locations) + "]"
127+
109128
compressedString = ""
110129
# are there some pilot files to unpack? Then we create the unpacking string
111130
for pfName, encodedPf in pilotFilesCompressedEncodedDict.items():
@@ -178,8 +197,8 @@ def pilotWrapperScript(
178197
# we try from the available locations
179198
locs = [os.path.join('https://', loc) for loc in location]
180199
locations = locs + [os.path.join(loc, 'pilot') for loc in locs]
181-
# adding also, as last the cvmfs location dirac.egi.eu, but this won't contain a valid JSON
182-
locations += ['file:/cvmfs/dirac.egi.eu/pilot/']
200+
# adding also the cvmfs locations
201+
locations += %(CVMFS_locs)s
183202
184203
for loc in locations:
185204
print('Trying %%s' %% loc)
@@ -262,7 +281,8 @@ def pilotWrapperScript(
262281
logger.debug('Checksum matched')
263282
264283
""" % {
265-
"location": location
284+
"location": location,
285+
"CVMFS_locs": CVMFS_locs,
266286
}
267287

268288
localPilot += (

src/DIRAC/WorkloadManagementSystem/Utilities/test/Test_PilotWrapper.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""" This is a test of the creation of the pilot wrapper
22
"""
33

4-
import os
54
import base64
65
import bz2
6+
import os
77

88
from DIRAC.WorkloadManagementSystem.Utilities.PilotWrapper import pilotWrapperScript
99

@@ -87,3 +87,37 @@ def test_scriptPilot3():
8787

8888
assert 'os.environ["someName"]="someValue"' in res
8989
assert "lhcb-portal.cern.ch" in res
90+
assert """locations += ["file:/cvmfs/dirac.egi.eu/pilot"]""" in res
91+
92+
93+
def test_scriptPilot3_2():
94+
"""test script creation"""
95+
res = pilotWrapperScript(
96+
pilotFilesCompressedEncodedDict={"proxy": "thisIsSomeProxy"},
97+
pilotOptions="-c 123 --foo bar",
98+
envVariables={"someName": "someValue", "someMore": "oneMore"},
99+
location="lhcb-portal.cern.ch",
100+
CVMFS_locations=["/cvmfs/lhcb.cern.ch", "/cvmfs/dirac.egi.eu"],
101+
)
102+
103+
assert 'os.environ["someName"]="someValue"' in res
104+
assert "lhcb-portal.cern.ch" in res
105+
assert """locations += ["file:/cvmfs/lhcb.cern.ch/dirac/pilot","file:/cvmfs/dirac.egi.eu/dirac/pilot"]""" in res
106+
107+
108+
def test_scriptPilot3_3():
109+
"""test script creation"""
110+
res = pilotWrapperScript(
111+
pilotFilesCompressedEncodedDict={"proxy": "thisIsSomeProxy"},
112+
pilotOptions="-c 123 --foo bar -l LHCb -h pippo",
113+
envVariables={"someName": "someValue", "someMore": "oneMore"},
114+
location="lhcb-portal.cern.ch",
115+
CVMFS_locations=["/cvmfs/lhcb.cern.ch", "/cvmfs/dirac.egi.eu"],
116+
)
117+
118+
assert 'os.environ["someName"]="someValue"' in res
119+
assert "lhcb-portal.cern.ch" in res
120+
assert (
121+
"""locations += ["file:/cvmfs/lhcb.cern.ch/lhcbdirac/pilot","file:/cvmfs/dirac.egi.eu/lhcbdirac/pilot"]"""
122+
in res
123+
)

0 commit comments

Comments
 (0)