def test_getDIRACPlatform(mocker, mockGCReplyInput, requested, expectedRes, expectedValue): mockGCReply.return_value = mockGCReplyInput mocker.patch("DIRAC.Interfaces.API.Dirac.gConfig.getOptionsDict", side_effect=mockGCReply) res = getDIRACPlatform(requested) assert res["OK"] is expectedRes, res if expectedRes: assert set(res["Value"]) == set(expectedValue), res["Value"]
def test_getDIRACPlatform(self): self.gConfigMock.getOptionsDict.return_value = { 'OK': False, 'Value': '' } res = getDIRACPlatform('plat') self.assertFalse(res['OK']) self.gConfigMock.getOptionsDict.return_value = { 'OK': True, 'Value': '' } res = getDIRACPlatform('plat') self.assertFalse(res['OK']) self.gConfigMock.getOptionsDict.return_value = { 'OK': True, 'Value': { 'plat1': 'OS1, OS2, OS3', 'plat2': 'OS4, OS5', 'plat3': 'OS1, OS4' } } res = getDIRACPlatform('plat') self.assertFalse(res['OK']) res = getDIRACPlatform('OS1') self.assert_(res['OK']) self.assertEqual(res['Value'], ['plat3', 'plat1']) res = getDIRACPlatform('OS2') self.assert_(res['OK']) self.assertEqual(res['Value'], ['plat1']) res = getDIRACPlatform('OS3') self.assert_(res['OK']) self.assertEqual(res['Value'], ['plat1']) res = getDIRACPlatform('OS4') self.assert_(res['OK']) self.assertEqual(res['Value'], ['plat3', 'plat2']) res = getDIRACPlatform('OS5') self.assert_(res['OK']) self.assertEqual(res['Value'], ['plat2']) res = getDIRACPlatform('plat1') self.assertTrue(res['OK'])
def setPlatform(ceDict, queueDict): """Set platform according to CE parameters if not defined""" platform = queueDict.get("Platform", ceDict.get("Platform", "")) if not platform and "OS" in ceDict: architecture = ceDict.get("architecture", "x86_64") platform = "_".join([architecture, ceDict["OS"]]) if "Platform" not in queueDict and platform: result = getDIRACPlatform(platform) if result["OK"]: queueDict["Platform"] = result["Value"][0] else: queueDict["Platform"] = platform
def test_getDIRACPlatform(self): self.gConfigMock.getOptionsDict.return_value = {"OK": False, "Value": ""} res = getDIRACPlatform("plat") self.assertFalse(res["OK"]) self.gConfigMock.getOptionsDict.return_value = {"OK": True, "Value": ""} res = getDIRACPlatform("plat") self.assertFalse(res["OK"]) self.gConfigMock.getOptionsDict.return_value = { "OK": True, "Value": {"plat1": "OS1, OS2, OS3", "plat2": "OS4, OS5", "plat3": "OS1, OS4"}, } res = getDIRACPlatform("plat") self.assertFalse(res["OK"]) res = getDIRACPlatform("OS1") self.assert_(res["OK"]) self.assertEqual(res["Value"], ["plat3", "plat1"]) res = getDIRACPlatform("OS2") self.assert_(res["OK"]) self.assertEqual(res["Value"], ["plat1"]) res = getDIRACPlatform("OS3") self.assert_(res["OK"]) self.assertEqual(res["Value"], ["plat1"]) res = getDIRACPlatform("OS4") self.assert_(res["OK"]) self.assertEqual(res["Value"], ["plat3", "plat2"]) res = getDIRACPlatform("OS5") self.assert_(res["OK"]) self.assertEqual(res["Value"], ["plat2"]) res = getDIRACPlatform("plat1") self.assertTrue(res["OK"])
def test_getDIRACPlatform( self ): self.gConfigMock.getOptionsDict.return_value = {'OK':False, 'Value':''} res = getDIRACPlatform( 'plat' ) self.assertFalse( res['OK'] ) self.gConfigMock.getOptionsDict.return_value = {'OK':True, 'Value':''} res = getDIRACPlatform( 'plat' ) self.assertFalse( res['OK'] ) self.gConfigMock.getOptionsDict.return_value = {'OK':True, 'Value':{'plat1': 'OS1, OS2, OS3', 'plat2': 'OS4, OS5', 'plat3': 'OS1, OS4'}} res = getDIRACPlatform( 'plat' ) self.assertFalse( res['OK'] ) res = getDIRACPlatform( 'OS1' ) self.assertTrue(res['OK']) self.assertEqual( res['Value'], ['plat3', 'plat1'] ) res = getDIRACPlatform( 'OS2' ) self.assertTrue(res['OK']) self.assertEqual( res['Value'], ['plat1'] ) res = getDIRACPlatform( 'OS3' ) self.assertTrue(res['OK']) self.assertEqual( res['Value'], ['plat1'] ) res = getDIRACPlatform( 'OS4' ) self.assertTrue(res['OK']) self.assertEqual( res['Value'], ['plat3', 'plat2'] ) res = getDIRACPlatform( 'OS5' ) self.assertTrue(res['OK']) self.assertEqual( res['Value'], ['plat2'] ) res = getDIRACPlatform( 'plat1' ) self.assertTrue( res['OK'] )
def getQueuesResolved(siteDict): """ Get the list of queue descriptions merging site/ce/queue parameters and adding some derived parameters. :param dict siteDict: dictionary with configuration data as returned by Resources.getQueues() method :return: S_OK/S_ERROR, Value dictionary per queue with configuration data updated, e.g. for SiteDirector """ queueFinalDict = {} for site in siteDict: for ce, ceDict in siteDict[site].items(): qDict = ceDict.pop('Queues') for queue in qDict: queueName = '%s_%s' % (ce, queue) queueDict = qDict[queue] queueDict['Queue'] = queue queueDict['Site'] = site # Evaluate the CPU limit of the queue according to the Glue convention # To Do: should be a utility if "maxCPUTime" in queueDict and "SI00" in queueDict: maxCPUTime = float(queueDict['maxCPUTime']) # For some sites there are crazy values in the CS maxCPUTime = max(maxCPUTime, 0) maxCPUTime = min(maxCPUTime, 86400 * 12.5) si00 = float(queueDict['SI00']) queueCPUTime = 60 / 250 * maxCPUTime * si00 queueDict['CPUTime'] = int(queueCPUTime) # Tags & RequiredTags defined on the Queue level and on the CE level are concatenated # This also converts them from a string to a list if required. for tagFieldName in ('Tag', 'RequiredTag'): ceTags = ceDict.get(tagFieldName, []) if isinstance(ceTags, six.string_types): ceTags = fromChar(ceTags) queueTags = queueDict.get(tagFieldName, []) if isinstance(queueTags, six.string_types): queueTags = fromChar(queueTags) queueDict[tagFieldName] = list(set(ceTags + queueTags)) # Some parameters can be defined on the CE level and are inherited by all Queues for parameter in ['MaxRAM', 'NumberOfProcessors', 'WholeNode']: queueParameter = queueDict.get(parameter, ceDict.get(parameter)) if queueParameter: queueDict[parameter] = queueParameter # If we have a multi-core queue add MultiProcessor tag if queueDict.get('NumberOfProcessors', 1) > 1: queueDict.setdefault('Tag', []).append('MultiProcessor') queueDict['CEName'] = ce queueDict['GridCE'] = ce queueDict['CEType'] = ceDict['CEType'] queueDict['GridMiddleware'] = ceDict['CEType'] queueDict['QueueName'] = queue platform = queueDict.get('Platform', ceDict.get('Platform', '')) if not platform and "OS" in ceDict: architecture = ceDict.get('architecture', 'x86_64') platform = '_'.join([architecture, ceDict['OS']]) queueDict['Platform'] = platform if platform: result = getDIRACPlatform(platform) if result['OK']: queueDict['Platform'] = result['Value'][0] queueFinalDict[queueName] = queueDict return S_OK(queueFinalDict)