def test_getMaxJobsTable_nofile(self): try: workspace = Workspace(vomap = self.vomap) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) result = DynSchedUtils.getMaxJobsTable(config) except DynSchedUtils.UtilsException, test_error: msg = str(test_error) self.assertTrue(msg.startswith("Error running"))
def test_getMaxJobsTable_ok(self): workspace = Workspace(vomap = self.vomap) workspace.setMaxJobCmd(self.mjTable) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) result = DynSchedUtils.getMaxJobsTable(config) self.assertTrue('atlas' in result and result['atlas'] == 50 and 'dteam' in result and result['dteam'] == 150 and 'infngrid' in result and result['infngrid'] == 360)
def test_getMaxJobsTable_wrongexit(self): try: workspace = Workspace(vomap = self.vomap) script = """#!/bin/bash exit 1 """ workspace.setMaxJobCmd(script) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) result = DynSchedUtils.getMaxJobsTable(config) except DynSchedUtils.UtilsException, test_error: msg = str(test_error) self.assertTrue(msg.startswith("VO max jobs backend command returned"))
def test_process_ok(self): glue2shareid = 'GLUE2ShareID=creamtest1_dteam_abc,GLUE2ServiceID=abc,GLUE2GroupID=resource,o=glue' ldif = """ dn: GLUE2PolicyID=creamtest1_dteam_abc_policy,%s GLUE2PolicyUserDomainForeignKey: dteam GLUE2MappingPolicyShareForeignKey: creamtest1_dteam_abc dn: %s GLUE2ShareID: creamtest1_dteam_abc GLUE2ComputingShareMappingQueue: creamtest1 """ % (glue2shareid, glue2shareid) workspace = Workspace(vomap = self.vomap) workspace.setLRMSCmd(self._script()) workspace.setGLUE2StaticFile(ldif) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) dOut = DummyOutput() collector = Analyzer.analyze(config, {}) GLUE2Handler.process(config, collector, dOut) result = dOut.queued[glue2shareid] == 1 result = result and dOut.running[glue2shareid] == 2 self.assertTrue(result)
def test_process_missing_vo_in_policy(self): try: glue2shareid = 'GLUE2ShareID=creamtest1_dteam_abc,GLUE2ServiceID=abc,GLUE2GroupID=resource,o=glue' ldif = """ dn: %s GLUE2ShareID: creamtest1_dteam_abc GLUE2ComputingShareMappingQueue: creamtest1 dn: GLUE2PolicyID=creamtest1_dteam_abc_policy,%s GLUE2MappingPolicyShareForeignKey: creamtest1_dteam_abc """ % (glue2shareid, glue2shareid) workspace = Workspace(vomap = self.vomap) workspace.setLRMSCmd(self._script()) workspace.setGLUE2StaticFile(ldif) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) collector = Analyzer.analyze(config, {}) GLUE2Handler.process(config, collector, DummyOutput()) self.fail("No exception detected") except GLUE2Handler.GLUE2Exception, glue_error: msg = str(glue_error) self.assertTrue(msg == "Missing mandatory attribute GLUE2PolicyUserDomainForeignKey")
def test_analyze_with_maxjobforvo(self): jTable = [ ("atlasprod", "creamtest1", 'running', 1327564866, "creXX_23081970"), ("dteamgold", 'creamtest2', 'running', 1327566866, "creXX_23081972"), ("dteamgold", "creamtest1", 'running', 1327567866, "creXX_23081973"), ("infngridlow", 'creamtest1', 'running', 1327569866, "creXX_23081975"), ("infngridlow", 'creamtest2', 'running', 1327570866, "creXX_23081976"), ("infngridhigh", 'creamtest2', 'running', 1327572866, "creXX_23081978") ] workspace = Workspace(vomap = self.vomap) script = self.headerfmt % (10, 4, 1327574866, 26) for jItem in jTable: script += self.dictfmt % jItem script += self.footerfmt mJobTable = {'dteam': 5, 'atlas': 5, 'infngrid':5} workspace.setLRMSCmd(script) workspace.setMaxJobCmd(mJobTable) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) collector = Analyzer.analyze(config, mJobTable) self.assertTrue(collector.freeSlots(None, 'dteam') == 3)
def test_process_ok(self): glueceuniqueid = 'GlueCEUniqueID=cream-38.pd.infn.it:8443/cream-pbs-creamtest1,mds-vo-name=resource,o=grid' gluevoviewid = 'GlueVOViewLocalID=dteam,' + glueceuniqueid ldif = """ dn: %s GlueVOViewLocalID: dteam GlueChunkKey: GlueCEUniqueID=cream-38.pd.infn.it:8443/cream-pbs-creamtest1 GlueCEAccessControlBaseRule: VO:dteam dn: %s GlueCEUniqueID: cream-38.pd.infn.it:8443/cream-pbs-creamtest1 GlueCEName: creamtest1 GlueCEAccessControlBaseRule: VO:infngrid GlueCEAccessControlBaseRule: VO:dteam """ % (gluevoviewid, glueceuniqueid) workspace = Workspace(vomap = self.vomap) workspace.setLRMSCmd(self._script()) workspace.setGLUE1StaticFile(ldif) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) dOut = DummyOutput() collector = Analyzer.analyze(config, {}) GLUE1Handler.process(config, collector, dOut) result = dOut.queued[glueceuniqueid] == 2 result = result and dOut.running[glueceuniqueid] == 4 result = result and dOut.queued[gluevoviewid] == 1 result = result and dOut.running[gluevoviewid] == 2 self.assertTrue(result)
def test_process_missingce(self): try: glueceuniqueid = 'GlueCEUniqueID=cream-38.pd.infn.it:8443/cream-pbs-creamtest1,mds-vo-name=resource,o=grid' gluevoviewid = 'GlueVOViewLocalID=dteam,' + glueceuniqueid ldif = """ dn: %s GlueVOViewLocalID: dteam GlueChunkKey: GlueCEUniqueID=cream-38.pd.infn.it:8443/cream-pbs-creamtest1 GlueCEAccessControlBaseRule: VO:dteam """ % gluevoviewid workspace = Workspace(vomap = self.vomap) workspace.setLRMSCmd(self._script()) workspace.setGLUE1StaticFile(ldif) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) dOut = DummyOutput() collector = Analyzer.analyze(config, {}) GLUE1Handler.process(config, collector, dOut) self.fail("No exception detected") except GLUE1Handler.GLUE1Exception, glue_error: msg = str(glue_error) self.assertTrue(msg.startswith("Invalid foreign key"))
def test_analyze_err_from_script(self): try: workspace = Workspace(vomap = self.vomap) script = """#!/usr/bin/python import sys sys.stderr.write("Dummy error message") sys.exit(1) """ workspace.setLRMSCmd(script) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) collector = Analyzer.analyze(config, {}) self.fail("Exception not handled") except Analyzer.AnalyzeException, test_error: msg = str(test_error) self.assertTrue(msg.startswith("Dummy error message"))
def process(config, collector, out=sys.stdout): shareTable = dict() policyTable = dict() share_fkeys = dict() ldifList = DynSchedUtils.getLDIFFilelist(config, 'ComputingShare.ldif') for ldifFilename in ldifList: parseGLUETemplate(ldifFilename, shareTable, policyTable, share_fkeys) for shareDN in shareTable: shareData = shareTable[shareDN] policyData = share_fkeys[shareData.id] out.write("%s\n" % shareDN) nwait = collector.queuedJobsOnQueueForVO(shareData.mqueue, policyData.vo) nrun = collector.runningJobsOnQueueForVO(shareData.mqueue, policyData.vo) out.write("GLUE2ComputingShareRunningJobs: %d\n" % nrun) out.write("GLUE2ComputingShareWaitingJobs: %d\n" % nwait) out.write("GLUE2ComputingShareTotalJobs: %d\n" % (nrun + nwait)) if collector.isSetERT(shareData.mqueue): out.write("GLUE2ComputingShareEstimatedAverageWaitingTime: %d\n" % collector.getERT(shareData.mqueue)) else: out.write("GLUE2ComputingShareEstimatedAverageWaitingTime: 0\n") if collector.isSetWRT(shareData.mqueue): out.write("GLUE2ComputingShareEstimatedWorstWaitingTime: %d\n" % collector.getWRT(shareData.mqueue)) else: out.write("GLUE2ComputingShareEstimatedWorstWaitingTime: 0\n") nfreeSlots = collector.freeSlots(shareData.mqueue, policyData.vo) if nfreeSlots >= 0: out.write("GLUE2ComputingShareFreeSlots: %d\n" % nfreeSlots) out.write("\n")
def test_process_missing_share(self): try: ldif = """ dn: GLUE2PolicyID=creamtest1_dteam_abc_policy,GLUE2ShareID=creamtest1_dteam_abc,GLUE2ServiceID=abc,GLUE2GroupID=resource,o=glue GLUE2PolicyUserDomainForeignKey: dteam GLUE2MappingPolicyShareForeignKey: creamtest1_dteam_abc """ workspace = Workspace(vomap = self.vomap) workspace.setLRMSCmd(self._script()) workspace.setGLUE2StaticFile(ldif) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) collector = Analyzer.analyze(config, {}) GLUE2Handler.process(config, collector, DummyOutput()) self.fail("No exception detected") except GLUE2Handler.GLUE2Exception, glue_error: msg = str(glue_error) self.assertTrue(msg.startswith("Invalid foreign key"))
def test_analyze_ok(self): jTable = [ ("atlasprod", "creamtest1", 'running', 1327564866, "creXX_23081970"), ("atlasprod", 'creamtest2', 'queued', 1327565866, "creXX_23081971"), ("dteamgold", 'creamtest2', 'running', 1327566866, "creXX_23081972"), ("dteamgold", "creamtest1", 'running', 1327567866, "creXX_23081973"), ("dteamgold", 'creamtest2', 'queued', 1327568866, "creXX_23081974"), ("infngridlow", 'creamtest1', 'running', 1327569866, "creXX_23081975"), ("infngridlow", 'creamtest2', 'running', 1327570866, "creXX_23081976"), ("infngridhigh", 'creamtest1', 'running', 1327571866, "creXX_23081977"), ("infngridhigh", 'creamtest2', 'running', 1327572866, "creXX_23081978"), ("infngridhigh", 'creamtest1', 'queued', 1327573866, "creXX_23081979") ] workspace = Workspace(vomap = self.vomap) script = self.headerfmt % (5, 0, 1327574866, 26) for jItem in jTable: script += self.dictfmt % jItem script += self.footerfmt workspace.setLRMSCmd(script) cfgfile = workspace.getConfigurationFile() config = DynSchedUtils.readConfigurationFromFile(cfgfile) collector = Analyzer.analyze(config, {}) result = collector.runningJobsForVO('atlas') == 1 result = result and collector.queuedJobsForVO('atlas') == 1 result = result and collector.runningJobsForVO('dteam') == 2 result = result and collector.queuedJobsForVO('dteam') == 1 result = result and collector.runningJobsForVO('infngrid') == 4 result = result and collector.queuedJobsForVO('infngrid') == 1 self.assertTrue(result)
def process(config, collector, out=sys.stdout): glueCETable = dict() voViewTable = dict() ce_fkeys = dict() ldifList = DynSchedUtils.getLDIFFilelist(config, 'static-file-CE.ldif') for ldifFilename in ldifList: parseGLUETemplate(ldifFilename, glueCETable, voViewTable, ce_fkeys) for glueceDN in glueCETable: ceData = glueCETable[glueceDN] out.write("%s\n" % glueceDN) nwait = collector.queuedJobsOnQueue(ceData.queue) nrun = collector.runningJobsOnQueue(ceData.queue) out.write("GlueCEStateWaitingJobs: %d\n" % nwait) out.write("GlueCEStateRunningJobs: %d\n" % nrun) out.write("GlueCEStateTotalJobs: %d\n" % (nrun + nwait)) if collector.isSetERT(ceData.queue): out.write("GlueCEStateEstimatedResponseTime: %d\n" % collector.getERT(ceData.queue)) else: out.write("GlueCEStateEstimatedResponseTime: 0\n") if collector.isSetWRT(ceData.queue): out.write("GlueCEStateWorstResponseTime: %d\n" % collector.getWRT(ceData.queue)) else: out.write("GlueCEStateWorstResponseTime: 0\n") if collector.free >= 0: out.write("GlueCEStateFreeJobSlots: %d\n" % collector.free) out.write("\n"); for voviewDN in voViewTable: voData = voViewTable[voviewDN] out.write("%s\n" % voviewDN) if not voData.fkey in ce_fkeys: raise GLUE1Exception("Invalid foreign key for " + voviewDN) queue = ce_fkeys[voData.fkey] nwait = collector.queuedJobsOnQueueForVO(queue, voData.name) nrun = collector.runningJobsOnQueueForVO(queue, voData.name) out.write("GlueCEStateWaitingJobs: %d\n" % nwait) out.write("GlueCEStateRunningJobs: %d\n" % nrun) out.write("GlueCEStateTotalJobs: %d\n" % (nrun + nwait)) if collector.isSetERT(queue): out.write("GlueCEStateEstimatedResponseTime: %d\n" % collector.getERT(queue)) else: out.write("GlueCEStateEstimatedResponseTime: 0\n") if collector.isSetWRT(queue): out.write("GlueCEStateWorstResponseTime: %d\n" % collector.getWRT(queue)) else: out.write("GlueCEStateWorstResponseTime: 0\n") nfreeSlots = collector.freeSlots(queue, voData.name) if nfreeSlots >= 0: out.write("GlueCEStateFreeJobSlots: %d\n" % nfreeSlots) out.write("\n");