Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mesmith75 authored Apr 15, 2024
2 parents 901ec9f + b0a6744 commit a4d5d92
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ganga/GangaCore/Lib/Virtualization/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Docker(IVirtualization):
_schema = IVirtualization._schema.inherit_copy()
_schema.datadict['mode'] = SimpleItem(defvalue="P1", doc='Mode of container execution')

def __init__(self, image, mode):
def __init__(self, image='', mode='P1'):
super().__init__(image)
self.mode = mode

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from GangaCore.testlib.GangaUnitTest import GangaUnitTest
from GangaCore.Lib.Virtualization import Docker
from GangaTest.Framework.utils import sleep_until_completed


class TestDocker(GangaUnitTest):
def test_DockerNoImageArg(self):
"""
The test_DockerNoImageArg function tests that Ganga can
submit a virtualization job using the default Docker image.
This test will fail if Ganga cannot find the job in the registry or
it cannot intialize the container with the default Docker image.
"""
from GangaCore.GPI import Job
j = Job(name="dockertest")
self.assertEqual(j.name, 'dockertest', "Something wrong with how\
Job was imported or initialized.")
j.virtualization = Docker()
self.assertEqual(j.virtualization.image, '', "Docker image was not\
passed correctly as an argument.")
j.submit()
sleep_until_completed(j)
j.remove()

def test_DockerBareImageArg(self):
"""
The test_DockerBareImageArg function tests that the Docker image
is passed correctly as an argument without the 'image=' prefix.
This test will fail if Ganga cannot find the job in the registry or
it cannot intialize the container with the desired Docker image.
"""
from GangaCore.GPI import Job
j = Job(name="dockertest")
self.assertEqual(j.name, 'dockertest', "Something wrong with how\
Job was imported or initialized.")
j.virtualization = Docker('fedora:latest')
self.assertEqual(j.virtualization.image, 'fedora:latest', "Docker\
image was not passed correctly as an argument.")
j.submit()
sleep_until_completed(j)
j.remove()

def test_DockerImageArg(self):
"""
The DockerImageArg function tests that the Docker image
is passed correctly as an argument with the 'image=' prefix.
This test will fail if Ganga cannot find the job in the registry or
it cannot intialize the container with the desired Docker image.
"""
from GangaCore.GPI import Job
j = Job(name="dockertest")
self.assertEqual(j.name, 'dockertest', "Something wrong with how\
Job was imported or initialized.")
j.virtualization = Docker(image='fedora:latest')
self.assertEqual(j.virtualization.image, 'fedora:latest', "Docker\
image was not passed correctly as an argument.")
j.submit()
sleep_until_completed(j)
j.remove()

def test_DockerImageArgWithMode(self):
"""
The DockerImageArgWithMode function tests that the Docker image
is passed correctly as an argument with the 'image=' prefix. It
also test if mode is explicitly set to 'P1'.
This test will fail if Ganga cannot find the job in the registry
or it cannot intialize the container with the desired Docker image
and mode.
"""
from GangaCore.GPI import Job
j = Job(name="dockertest")
self.assertEqual(j.name, 'dockertest', "Something wrong with how\
Job was imported or initialized.")
j.virtualization = Docker(image='fedora:latest', mode='P1')
self.assertEqual(j.virtualization.image, 'fedora:latest', "Docker\
image was not passed correctly as an argument.")
self.assertEqual(j.virtualization.mode, 'P1', "Mode was not passed\
correctly as an argument.")
j.submit()
sleep_until_completed(j)
j.remove()
17 changes: 15 additions & 2 deletions ganga/GangaLHCb/Lib/Applications/GaudiExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ class GaudiExec(IPrepareApp):
'nMakeCores': SimpleItem(defvalue=1,
doc='Number of cores to be provided via the "-j" option to the "make" command'\
'when building the ganga-input-sandbox'),

'apptainerBuild' : SimpleItem(defvalue=False, doc="Run the build command in apptainer"),
'containerLocation' : SimpleItem(defvalue='/cvmfs/cernvm-prod.cern.ch/cvm4',
doc='Where is the container to use for the build located'),
# Prepared job object
'is_prepared': SimpleItem(defvalue=None, strict_sequence=0, visitable=1, copyable=1, hidden=0,
typelist=[None, ShareDir], protected=0, comparable=1,
Expand Down Expand Up @@ -564,7 +566,18 @@ def execCmd(self, cmd):
if cmd != 'make':
rc, stdout, stderr = _exec_cmd(cmd_file.name, self.directory)
else:
rc, stdout, stderr = _exec_cmd(cmd_file.name, self.directory)
if self.apptainerBuild or 'slc6' in self.platform:
try:
logger.info('Building inside apptainer: %s' % self.containerLocation)
cmd_to_run = 'apptainer exec --env "PATH=$PATH" --bind $PWD --bind /cvmfs:/cvmfs:ro '\
+ self.containerLocation + ' ' + cmd_file.name
rc, stdout, stderr = _exec_cmd(cmd_to_run, self.directory)
except:
logger.error('Failed to build the application inside a container. '
'Perhaps the specified container location is not accessible.')
raise GangaException('Failed to execute make command')
else:
rc, stdout, stderr = _exec_cmd(cmd_file.name, self.directory)
if rc != 0:
logger.error("Failed to execute command: %s" % cmd_file.name)
logger.error("Tried to execute command in: %s" % self.directory)
Expand Down

0 comments on commit a4d5d92

Please sign in to comment.