Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance logic to map ScramArch to OS #11088

Merged
merged 2 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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