Skip to content

Commit

Permalink
feat: using CVMFS_locations for discovering the pilot files
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Dec 18, 2023
1 parent c619b45 commit 8cf7cda
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
38 changes: 29 additions & 9 deletions src/DIRAC/WorkloadManagementSystem/Utilities/PilotWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
_writePilotWrapperFile(localPilot=localPilot)
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import os
import tempfile
import base64
import bz2
import os
import tempfile

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


def pilotWrapperScript(
pilotFilesCompressedEncodedDict=None, pilotOptions="", pilotExecDir="", envVariables=None, location=""
pilotFilesCompressedEncodedDict=None,
pilotOptions="",
pilotExecDir="",
envVariables=None,
location="",
CVMFS_locations=None,
):
"""Returns the content of the pilot wrapper script.
Expand All @@ -95,6 +98,8 @@ def pilotWrapperScript(
:type envVariables: dict
:param location: location where to get the pilot files
:type location: string
:param location: optional CVMFS locations of where to get the pilot files
:type location: list
:returns: content of the pilot wrapper
:rtype: string
Expand All @@ -106,6 +111,20 @@ def pilotWrapperScript(
if envVariables is None:
envVariables = {}

if CVMFS_locations is None:
# What is in this location is almost certainly incorrect, especially the pilot.json
CVMFS_locs = '["file:/cvmfs/dirac.egi.eu/pilot"]'
else:
# Here we are making the assumption that, if CVMFS_locations is, e.g., ['/cvmfs/somewhere', '/cvmfs/elsewhere']
# and the project is 'LHCb',
# then the pilot can maybe be found at locations
# - file:/cvmfs/somewhere/lhcbdirac/pilot
# - file:/cvmfs/elsewhere/lhcbdirac/pilot
project = "dirac"
if "-l" in pilotOptions:
project = pilotOptions.split(" ")[pilotOptions.split(" ").index("-l") + 1].lower() + "dirac"
CVMFS_locs = "[" + ",".join('"file:' + os.path.join(loc, project, 'pilot"') for loc in CVMFS_locations) + "]"

compressedString = ""
# are there some pilot files to unpack? Then we create the unpacking string
for pfName, encodedPf in pilotFilesCompressedEncodedDict.items():
Expand Down Expand Up @@ -178,8 +197,8 @@ def pilotWrapperScript(
# we try from the available locations
locs = [os.path.join('https://', loc) for loc in location]
locations = locs + [os.path.join(loc, 'pilot') for loc in locs]
# adding also, as last the cvmfs location dirac.egi.eu, but this won't contain a valid JSON
locations += ['file:/cvmfs/dirac.egi.eu/pilot/']
# adding also the cvmfs locations
locations += %(CVMFS_locs)s
for loc in locations:
print('Trying %%s' %% loc)
Expand Down Expand Up @@ -262,7 +281,8 @@ def pilotWrapperScript(
logger.debug('Checksum matched')
""" % {
"location": location
"location": location,
"CVMFS_locs": CVMFS_locs,
}

localPilot += (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" This is a test of the creation of the pilot wrapper
"""

import os
import base64
import bz2
import os

from DIRAC.WorkloadManagementSystem.Utilities.PilotWrapper import pilotWrapperScript

Expand Down Expand Up @@ -87,3 +87,37 @@ def test_scriptPilot3():

assert 'os.environ["someName"]="someValue"' in res
assert "lhcb-portal.cern.ch" in res
assert """locations += ["file:/cvmfs/dirac.egi.eu/pilot"]""" in res


def test_scriptPilot3_2():
"""test script creation"""
res = pilotWrapperScript(
pilotFilesCompressedEncodedDict={"proxy": "thisIsSomeProxy"},
pilotOptions="-c 123 --foo bar",
envVariables={"someName": "someValue", "someMore": "oneMore"},
location="lhcb-portal.cern.ch",
CVMFS_locations=["/cvmfs/lhcb.cern.ch", "/cvmfs/dirac.egi.eu"],
)

assert 'os.environ["someName"]="someValue"' in res
assert "lhcb-portal.cern.ch" in res
assert """locations += ["file:/cvmfs/lhcb.cern.ch/dirac/pilot","file:/cvmfs/dirac.egi.eu/dirac/pilot"]""" in res


def test_scriptPilot3_3():
"""test script creation"""
res = pilotWrapperScript(
pilotFilesCompressedEncodedDict={"proxy": "thisIsSomeProxy"},
pilotOptions="-c 123 --foo bar -l LHCb -h pippo",
envVariables={"someName": "someValue", "someMore": "oneMore"},
location="lhcb-portal.cern.ch",
CVMFS_locations=["/cvmfs/lhcb.cern.ch", "/cvmfs/dirac.egi.eu"],
)

assert 'os.environ["someName"]="someValue"' in res
assert "lhcb-portal.cern.ch" in res
assert (
"""locations += ["file:/cvmfs/lhcb.cern.ch/lhcbdirac/pilot","file:/cvmfs/dirac.egi.eu/lhcbdirac/pilot"]"""
in res
)

0 comments on commit 8cf7cda

Please sign in to comment.