Skip to content

Commit

Permalink
Merge pull request #11088 from amaltaro/fix-11081-take2
Browse files Browse the repository at this point in the history
Enhance logic to map ScramArch to OS
  • Loading branch information
amaltaro authored Apr 12, 2022
2 parents 9bad6a8 + dacc5b9 commit 73fa2c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
36 changes: 17 additions & 19 deletions src/python/WMCore/BossAir/Plugins/BasePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from builtins import object, str, bytes
from future.utils import viewitems, viewvalues
from future.utils import viewvalues

from Utils.Utilities import decodeBytesToUnicode
from WMCore.WMException import WMException
Expand Down Expand Up @@ -130,27 +130,25 @@ def updateSiteInformation(self, jobs, siteName, excludeSite):
@staticmethod
def scramArchtoRequiredOS(scramArch=None):
"""
Matches a ScramArch - or a list of it - against a map of Scram
to Operating System
Args:
scramArch: string or list of scramArches that are acceptable for the job
Returns:
string to be matched for OS requirements for job
:param scramArch: string or list of scramArches defined for a given job
:return: a string with the required OS to use
"""
requiredOSes = set()
defaultValue = 'any'
if not scramArch:
requiredOSes.add('any')
elif isinstance(scramArch, (str, bytes)):
for arch, validOSes in viewitems(ARCH_TO_OS):
if arch in scramArch:
requiredOSes.update(validOSes)
elif isinstance(scramArch, list):
for validArch in scramArch:
for arch, validOSes in viewitems(ARCH_TO_OS):
if arch in validArch:
requiredOSes.update(validOSes)
else:
requiredOSes.add('any')
return defaultValue

requiredOSes = set()
if isinstance(scramArch, (str, bytes)):
scramArch = [scramArch]
elif not isinstance(scramArch, (list, tuple)):
return defaultValue

for validArch in scramArch:
scramOS = validArch.split("_")[0]
requiredOSes.update(ARCH_TO_OS.get(scramOS, []))

return ','.join(sorted(requiredOSes))

Expand Down
5 changes: 4 additions & 1 deletion test/python/WMCore_t/BossAir_t/BasePlugin_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ def testScramArchToOS(self):
self.assertEqual(bp.scramArchtoRequiredOS('cc8_blah_blah'), 'rhel8')
self.assertEqual(bp.scramArchtoRequiredOS('cs8_blah_blah'), 'rhel8')
self.assertEqual(bp.scramArchtoRequiredOS('alma8_blah_blah'), 'rhel8')
self.assertEqual(bp.scramArchtoRequiredOS('el88_blah_blah'), 'rhel8')
self.assertEqual(bp.scramArchtoRequiredOS('el8_blah_blah'), 'rhel8')

self.assertEqual(bp.scramArchtoRequiredOS(None), 'any')
self.assertEqual(bp.scramArchtoRequiredOS(""), 'any')
self.assertEqual(bp.scramArchtoRequiredOS([]), 'any')

self.assertEqual(bp.scramArchtoRequiredOS(['slc6_blah_blah', 'slc7_blah_blah']), 'rhel6,rhel7')
self.assertEqual(bp.scramArchtoRequiredOS(['slc6_blah_blah', 'alma8_blah_blah']), 'rhel6,rhel8')

# unexpected case, a ScramArch being requested without the map implemented
self.assertEqual(bp.scramArchtoRequiredOS('slc1_blah_blah'), '')
return

def testScramArchtoRequiredArch(self):
Expand Down

0 comments on commit 73fa2c9

Please sign in to comment.