def testDrain(self): """Drain a site""" myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 20, "testSE1", "testCE1") myResourceControl.insertThreshold("testSite1", "Processing", 10, priority=1) myResourceControl.drainSite("testSite1") result = myResourceControl.listThresholdsForCreate() self.assertTrue(result["testSite1"]["drain"]) # re-renable myResourceControl.drainSite("testSite1", drain=False) result = myResourceControl.listThresholdsForCreate() self.assertFalse(result["testSite1"]["drain"])
def testChangeState(self): """ _testChangeState_ Check that we can change the state between different values and retrieve it through the threshold methods """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 20, 40, "testSE1", "testCE1") myResourceControl.insertThreshold("testSite1", "Processing", 10, 5) result = myResourceControl.listThresholdsForCreate() self.assertEqual(result['testSite1']['state'], 'Normal', 'Error: Wrong site state') myResourceControl.changeSiteState("testSite1", "Down") result = myResourceControl.listThresholdsForCreate() self.assertEqual(result['testSite1']['state'], 'Down', 'Error: Wrong site state')
def testChangeSiteState(self): """ _testNewState_ Check that we can change the state between different values and retrieve it through the threshold methods """ self.tempDir = self.testInit.generateWorkDir() config = self.createConfig() myResourceControl = ResourceControl(config) myResourceControl.insertSite("testSite1", 20, 40, "testSE1", "testCE1") myResourceControl.insertThreshold("testSite1", "Processing", 10, 5) result = myResourceControl.listThresholdsForCreate() self.assertEqual(result['testSite1']['state'], 'Normal', 'Error: Wrong site state') myResourceControl.changeSiteState("testSite1", "Down") result = myResourceControl.listThresholdsForCreate() self.assertEqual(result['testSite1']['state'], 'Down', 'Error: Wrong site state')
def testChangeState(self): """ _testChangeState_ Check that we can change the state between different values and retrieve it through the threshold methods """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 20, 40, "testSE1", "testCE1") myResourceControl.insertThreshold("testSite1", "Processing", 10, 5, priority=1) result = myResourceControl.listThresholdsForCreate() self.assertEqual(result['testSite1']['state'], 'Normal', 'Error: Wrong site state') myResourceControl.changeSiteState("testSite1", "Down") result = myResourceControl.listThresholdsForCreate() self.assertEqual(result['testSite1']['state'], 'Down', 'Error: Wrong site state')
def testList(self): """ _testList_ Test the functions that list thresholds for creating jobs and submitting jobs. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1", "T1_US_FNAL", "LsfPlugin") myResourceControl.insertSite("testSite2", 20, 40, "testSE2", "testCE2", "T3_US_FNAL", "LsfPlugin") myResourceControl.insertThreshold("testSite1", "Processing", 20, 10) myResourceControl.insertThreshold("testSite1", "Merge", 200, 100) myResourceControl.insertThreshold("testSite2", "Processing", 50, 25) myResourceControl.insertThreshold("testSite2", "Merge", 135, 65) self.createJobs() createThresholds = myResourceControl.listThresholdsForCreate() submitThresholds = myResourceControl.listThresholdsForSubmit() self.assertEqual(len(createThresholds.keys()), 2, "Error: Wrong number of sites in create thresholds") self.assertEqual(createThresholds["testSite1"]["total_slots"], 10, "Error: Wrong number of slots for site 1") self.assertEqual(createThresholds["testSite2"]["total_slots"], 20, "Error: Wrong number of slots for site 2") # We should have two running jobs with locations at site one, # two running jobs without locations at site two, and one running # job without a location at site one and two. self.assertEqual(createThresholds["testSite1"]["pending_jobs"], {0: 4}, "Error: Wrong number of pending jobs for site 1") # We should have one running job with a location at site 2 and # another running job without a location. self.assertEqual(createThresholds["testSite2"]["pending_jobs"], {0: 2}, "Error: Wrong number of pending jobs for site 2") # We should also have a phedex_name self.assertEqual(createThresholds["testSite1"]["cms_name"], "T1_US_FNAL") self.assertEqual(createThresholds["testSite2"]["cms_name"], "T3_US_FNAL") mergeThreshold1 = None mergeThreshold2 = None procThreshold1 = None procThreshold2 = None self.assertEqual(set(submitThresholds.keys()), set(["testSite1", "testSite2"])) for taskType, threshold in submitThresholds["testSite1"]["thresholds"].items(): if taskType == "Merge": mergeThreshold1 = threshold elif taskType == "Processing": procThreshold1 = threshold for taskType, threshold in submitThresholds["testSite2"]["thresholds"].items(): if taskType == "Merge": mergeThreshold2 = threshold elif taskType == "Processing": procThreshold2 = threshold self.assertEqual(submitThresholds["testSite1"]["total_running_jobs"], 0, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite2"]["total_running_jobs"], 1, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite1"]["total_pending_jobs"], 1, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite2"]["total_pending_jobs"], 0, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual(mergeThreshold1["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold1["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold1["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold1["task_pending_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold2["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold2["task_running_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") return
def testInsert(self): """ _testInsert_ Verify that inserting sites and thresholds works correctly, even if the site or threshold already exists. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1") myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1") myResourceControl.insertSite("testSite2", 100, 200, "testSE2", "testCE2") myResourceControl.insertThreshold("testSite1", "Processing", 20, 10) myResourceControl.insertThreshold("testSite1", "Merge", 200, 100) myResourceControl.insertThreshold("testSite1", "Merge", 250, 150) myResourceControl.insertThreshold("testSite2", "Processing", 50, 30) myResourceControl.insertThreshold("testSite2", "Merge", 135, 100) createThresholds = myResourceControl.listThresholdsForCreate() self.assertEqual(len(createThresholds.keys()), 2, "Error: Wrong number of site in Resource Control DB") self.assertTrue("testSite1" in createThresholds.keys(), "Error: Test Site 1 missing from thresholds.") self.assertTrue("testSite2" in createThresholds.keys(), "Error: Test Site 2 missing from thresholds.") self.assertEqual(createThresholds["testSite1"]["total_slots"], 10, "Error: Wrong number of total slots.") self.assertEqual(createThresholds["testSite1"]["pending_jobs"], {0: 0}, "Error: Wrong number of running jobs: %s" % createThresholds["testSite1"]["pending_jobs"]) self.assertEqual(createThresholds["testSite2"]["total_slots"], 100, "Error: Wrong number of total slots.") self.assertEqual(createThresholds["testSite2"]["pending_jobs"], {0: 0}, "Error: Wrong number of running jobs.") thresholds = myResourceControl.listThresholdsForSubmit() self.assertEqual(len(thresholds.keys()), 2, "Error: Wrong number of sites in Resource Control DB") self.assertTrue("testSite1" in thresholds.keys(), "Error: testSite1 missing from thresholds.") self.assertTrue("testSite2" in thresholds.keys(), "Error: testSite2 missing from thresholds.") site1Info = thresholds["testSite1"] site2Info = thresholds["testSite2"] site1Thresholds = site1Info["thresholds"] site2Thresholds = site2Info["thresholds"] procThreshold1 = None procThreshold2 = None mergeThreshold1 = None mergeThreshold2 = None for taskType, threshold in site1Thresholds.items(): if taskType == "Merge": mergeThreshold1 = threshold elif taskType == "Processing": procThreshold1 = threshold for taskType, threshold in site2Thresholds.items(): if taskType == "Merge": mergeThreshold2 = threshold elif taskType == "Processing": procThreshold2 = threshold self.assertEqual(len(site1Thresholds), 2, "Error: Wrong number of task types.") self.assertEqual(len(site2Thresholds), 2, "Error: Wrong number of task types.") self.assertNotEqual(procThreshold1, None) self.assertNotEqual(procThreshold2, None) self.assertNotEqual(mergeThreshold1, None) self.assertNotEqual(mergeThreshold2, None) self.assertEqual(site1Info["total_pending_slots"], 10, "Error: Site thresholds wrong") self.assertEqual(site1Info["total_running_slots"], 20, "Error: Site thresholds wrong") self.assertEqual(site1Info["total_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(site1Info["total_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["max_slots"], 20, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["pending_slots"], 10, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["max_slots"], 250, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["pending_slots"], 150, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_pending_slots"], 100, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_running_slots"], 200, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["max_slots"], 50, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["pending_slots"], 30, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["max_slots"], 135, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["pending_slots"], 100, "Error: Site thresholds wrong")
def testInsert(self): """ _testInsert_ Verify that inserting sites and thresholds works correctly, even if the site or threshold already exists. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1") myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1") myResourceControl.insertSite("testSite2", 100, 200, "testSE2", "testCE2") myResourceControl.insertThreshold("testSite1", "Processing", 20, 10) myResourceControl.insertThreshold("testSite1", "Merge", 200, 100) myResourceControl.insertThreshold("testSite1", "Merge", 250, 150) myResourceControl.insertThreshold("testSite2", "Processing", 50, 30) myResourceControl.insertThreshold("testSite2", "Merge", 135, 100) createThresholds = myResourceControl.listThresholdsForCreate() self.assertEqual(len(createThresholds.keys()), 2, "Error: Wrong number of site in Resource Control DB") self.assertTrue("testSite1" in createThresholds.keys(), "Error: Test Site 1 missing from thresholds.") self.assertTrue("testSite2" in createThresholds.keys(), "Error: Test Site 2 missing from thresholds.") self.assertEqual(createThresholds["testSite1"]["total_slots"], 10, "Error: Wrong number of total slots.") self.assertEqual( createThresholds["testSite1"]["pending_jobs"], 0, "Error: Wrong number of running jobs: %s" % createThresholds["testSite1"]["pending_jobs"]) self.assertEqual(createThresholds["testSite2"]["total_slots"], 100, "Error: Wrong number of total slots.") self.assertEqual(createThresholds["testSite2"]["pending_jobs"], 0, "Error: Wrong number of running jobs.") thresholds = myResourceControl.listThresholdsForSubmit() self.assertEqual( len(thresholds.keys()), 2, "Error: Wrong number of sites in Resource Control DB") self.assertTrue("testSite1" in thresholds.keys(), "Error: testSite1 missing from thresholds.") self.assertTrue("testSite2" in thresholds.keys(), "Error: testSite2 missing from thresholds.") site1Info = thresholds["testSite1"] site2Info = thresholds["testSite2"] site1Thresholds = site1Info["thresholds"] site2Thresholds = site2Info["thresholds"] procThreshold1 = None procThreshold2 = None mergeThreshold1 = None mergeThreshold2 = None for threshold in site1Thresholds: if threshold["task_type"] == "Merge": mergeThreshold1 = threshold elif threshold["task_type"] == "Processing": procThreshold1 = threshold for threshold in site2Thresholds: if threshold["task_type"] == "Merge": mergeThreshold2 = threshold elif threshold["task_type"] == "Processing": procThreshold2 = threshold self.assertEqual(len(site1Thresholds), 2, "Error: Wrong number of task types.") self.assertEqual(len(site2Thresholds), 2, "Error: Wrong number of task types.") self.assertNotEqual(procThreshold1, None) self.assertNotEqual(procThreshold2, None) self.assertNotEqual(mergeThreshold1, None) self.assertNotEqual(mergeThreshold2, None) self.assertEqual(site1Info["total_pending_slots"], 10, "Error: Site thresholds wrong") self.assertEqual(site1Info["total_running_slots"], 20, "Error: Site thresholds wrong") self.assertEqual(site1Info["total_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(site1Info["total_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["max_slots"], 20, "Error: Site thresholds wrong") self.assertEqual(procThreshold1["pending_slots"], 10, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["max_slots"], 250, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold1["pending_slots"], 150, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_pending_slots"], 100, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_running_slots"], 200, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(site2Info["total_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["max_slots"], 50, "Error: Site thresholds wrong") self.assertEqual(procThreshold2["pending_slots"], 30, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["task_running_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["task_pending_jobs"], 0, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["max_slots"], 135, "Error: Site thresholds wrong") self.assertEqual(mergeThreshold2["pending_slots"], 100, "Error: Site thresholds wrong")
def testList(self): """ _testList_ Test the functions that list thresholds for creating jobs and submitting jobs. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1", "T1_US_FNAL", "LsfPlugin") myResourceControl.insertSite("testSite2", 20, 40, "testSE2", "testCE2") myResourceControl.insertThreshold("testSite1", "Processing", 20, 10) myResourceControl.insertThreshold("testSite1", "Merge", 200, 100) myResourceControl.insertThreshold("testSite2", "Processing", 50, 25) myResourceControl.insertThreshold("testSite2", "Merge", 135, 65) testWorkflow = Workflow(spec=makeUUID(), owner="Steve", name=makeUUID(), task="Test") testWorkflow.create() testFilesetA = Fileset(name="TestFilesetA") testFilesetA.create() testFilesetB = Fileset(name="TestFilesetB") testFilesetB.create() testFilesetC = Fileset(name="TestFilesetC") testFilesetC.create() testFileA = File(lfn="testFileA", locations=set(["testSE1", "testSE2"])) testFileA.create() testFilesetA.addFile(testFileA) testFilesetA.commit() testFilesetB.addFile(testFileA) testFilesetB.commit() testFilesetC.addFile(testFileA) testFilesetC.commit() testSubscriptionA = Subscription(fileset=testFilesetA, workflow=testWorkflow, type="Processing") testSubscriptionA.create() testSubscriptionA.addWhiteBlackList([{ "site_name": "testSite1", "valid": True }]) testSubscriptionB = Subscription(fileset=testFilesetB, workflow=testWorkflow, type="Processing") testSubscriptionB.create() testSubscriptionB.addWhiteBlackList([{ "site_name": "testSite1", "valid": False }]) testSubscriptionC = Subscription(fileset=testFilesetC, workflow=testWorkflow, type="Merge") testSubscriptionC.create() testJobGroupA = JobGroup(subscription=testSubscriptionA) testJobGroupA.create() testJobGroupB = JobGroup(subscription=testSubscriptionB) testJobGroupB.create() testJobGroupC = JobGroup(subscription=testSubscriptionC) testJobGroupC.create() # Site1, Has been assigned a location and is complete. testJobA = Job(name="testJobA", files=[testFileA]) testJobA["couch_record"] = makeUUID() testJobA.create(group=testJobGroupA) testJobA["state"] = "success" # Site 1, Has been assigned a location and is incomplete. testJobB = Job(name="testJobB", files=[testFileA]) testJobB["couch_record"] = makeUUID() testJobB.create(group=testJobGroupA) testJobB["state"] = "executing" runJobB = RunJob() runJobB.buildFromJob(testJobB) runJobB["status"] = "PEND" # Does not have a location, white listed to site 1 testJobC = Job(name="testJobC", files=[testFileA]) testJobC["couch_record"] = makeUUID() testJobC.create(group=testJobGroupA) testJobC["state"] = "new" # Site 2, Has been assigned a location and is complete. testJobD = Job(name="testJobD", files=[testFileA]) testJobD["couch_record"] = makeUUID() testJobD.create(group=testJobGroupB) testJobD["state"] = "success" # Site 2, Has been assigned a location and is incomplete. testJobE = Job(name="testJobE", files=[testFileA]) testJobE["couch_record"] = makeUUID() testJobE.create(group=testJobGroupB) testJobE["state"] = "executing" runJobE = RunJob() runJobE.buildFromJob(testJobE) runJobE["status"] = "RUN" # Does not have a location, site 1 is blacklisted. testJobF = Job(name="testJobF", files=[testFileA]) testJobF["couch_record"] = makeUUID() testJobF.create(group=testJobGroupB) testJobF["state"] = "new" # Site 3, Has been assigned a location and is complete. testJobG = Job(name="testJobG", files=[testFileA]) testJobG["couch_record"] = makeUUID() testJobG.create(group=testJobGroupC) testJobG["state"] = "cleanout" # Site 3, Has been assigned a location and is incomplete. testJobH = Job(name="testJobH", files=[testFileA]) testJobH["couch_record"] = makeUUID() testJobH.create(group=testJobGroupC) testJobH["state"] = "new" # Site 3, Does not have a location. testJobI = Job(name="testJobI", files=[testFileA]) testJobI["couch_record"] = makeUUID() testJobI.create(group=testJobGroupC) testJobI["state"] = "new" # Site 3, Does not have a location and is in cleanout. testJobJ = Job(name="testJobJ", files=[testFileA]) testJobJ["couch_record"] = makeUUID() testJobJ.create(group=testJobGroupC) testJobJ["state"] = "cleanout" changeStateAction = self.daoFactory(classname="Jobs.ChangeState") changeStateAction.execute(jobs=[ testJobA, testJobB, testJobC, testJobD, testJobE, testJobF, testJobG, testJobH, testJobI, testJobJ ]) self.insertRunJob.execute([runJobB, runJobE]) setLocationAction = self.daoFactory(classname="Jobs.SetLocation") setLocationAction.execute(testJobA["id"], "testSite1") setLocationAction.execute(testJobB["id"], "testSite1") setLocationAction.execute(testJobD["id"], "testSite1") setLocationAction.execute(testJobE["id"], "testSite1") setLocationAction.execute(testJobG["id"], "testSite1") setLocationAction.execute(testJobH["id"], "testSite1") createThresholds = myResourceControl.listThresholdsForCreate() submitThresholds = myResourceControl.listThresholdsForSubmit() self.assertEqual(len(createThresholds.keys()), 2, "Error: Wrong number of sites in create thresholds") self.assertEqual(createThresholds["testSite1"]["total_slots"], 10, "Error: Wrong number of slots for site 1") self.assertEqual(createThresholds["testSite2"]["total_slots"], 20, "Error: Wrong number of slots for site 2") # We should have two running jobs with locations at site one, # two running jobs without locations at site two, and one running # job without a location at site one and two. self.assertEqual(createThresholds["testSite1"]["pending_jobs"], 4, "Error: Wrong number of pending jobs for site 1") # We should have one running job with a location at site 2 and # another running job without a location. self.assertEqual(createThresholds["testSite2"]["pending_jobs"], 2, "Error: Wrong number of pending jobs for site 2") # We should also have a phedex_name self.assertEqual(createThresholds["testSite1"]["cms_name"], "T1_US_FNAL") self.assertEqual(createThresholds["testSite2"]["cms_name"], None) mergeThreshold1 = None mergeThreshold2 = None procThreshold1 = None procThreshold2 = None self.assertEqual(submitThresholds["testSite1"]['cms_name'], 'T1_US_FNAL') for threshold in submitThresholds["testSite1"]["thresholds"]: if threshold['task_type'] == "Merge": mergeThreshold1 = threshold elif threshold['task_type'] == "Processing": procThreshold1 = threshold self.assertEqual(submitThresholds["testSite2"]['cms_name'], None) for threshold in submitThresholds["testSite2"]["thresholds"]: if threshold['task_type'] == "Merge": mergeThreshold2 = threshold elif threshold['task_type'] == "Processing": procThreshold2 = threshold self.assertEqual( submitThresholds["testSite1"]["total_running_jobs"], 1, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual( submitThresholds["testSite2"]["total_running_jobs"], 0, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual( submitThresholds["testSite1"]["total_pending_jobs"], 1, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual( submitThresholds["testSite2"]["total_pending_jobs"], 0, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual( mergeThreshold1["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( mergeThreshold1["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( procThreshold1["task_running_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( procThreshold1["task_pending_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( mergeThreshold2["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( mergeThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( procThreshold2["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual( procThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") return
#!/usr/bin/env python #pylint: disable-msg=C0103 """ resource-check Utility script for manipulating resource control. """ import os from pprint import pprint from WMCore.WMInit import connectToDB from WMCore.Configuration import loadConfigurationFile from WMCore.ResourceControl.ResourceControl import ResourceControl if 'WMAGENT_CONFIG' not in os.environ: os.environ[ 'WMAGENT_CONFIG'] = '/data/srv/wmagent/current/config/wmagent/config.py' connectToDB() wmConfig = loadConfigurationFile(os.environ['WMAGENT_CONFIG']) myResourceControl = ResourceControl(config=wmConfig) pprint(myResourceControl.listThresholdsForCreate()) pprint(myResourceControl.listThresholdsForSubmit())
#!/usr/bin/env python #pylint: disable-msg=C0103 """ resource-check Utility script for manipulating resource control. """ import os from pprint import pprint from WMCore.WMInit import connectToDB from WMCore.Configuration import loadConfigurationFile from WMCore.ResourceControl.ResourceControl import ResourceControl if 'WMAGENT_CONFIG' not in os.environ: os.environ['WMAGENT_CONFIG'] = '/data/srv/wmagent/current/config/wmagent/config.py' connectToDB() wmConfig = loadConfigurationFile(os.environ['WMAGENT_CONFIG']) myResourceControl = ResourceControl(config = wmConfig) pprint(myResourceControl.listThresholdsForCreate()) pprint(myResourceControl.listThresholdsForSubmit())
def testList(self): """ _testList_ Test the functions that list thresholds for creating jobs and submitting jobs. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1", "T1_US_FNAL", "LsfPlugin") myResourceControl.insertSite("testSite2", 20, 40, "testSE2", "testCE2", "T3_US_FNAL", "LsfPlugin") myResourceControl.insertThreshold("testSite1", "Processing", 20, 10) myResourceControl.insertThreshold("testSite1", "Merge", 200, 100) myResourceControl.insertThreshold("testSite2", "Processing", 50, 25) myResourceControl.insertThreshold("testSite2", "Merge", 135, 65) self.createJobs() createThresholds = myResourceControl.listThresholdsForCreate() submitThresholds = myResourceControl.listThresholdsForSubmit() self.assertEqual( len(createThresholds.keys()), 2, "Error: Wrong number of sites in create thresholds" ) self.assertEqual( createThresholds["testSite1"]["total_slots"], 10, "Error: Wrong number of slots for site 1" ) self.assertEqual( createThresholds["testSite2"]["total_slots"], 20, "Error: Wrong number of slots for site 2" ) # We should have two running jobs with locations at site one, # two running jobs without locations at site two, and one running # job without a location at site one and two. self.assertEqual( createThresholds["testSite1"]["pending_jobs"], {0 : 4}, "Error: Wrong number of pending jobs for site 1" ) # We should have one running job with a location at site 2 and # another running job without a location. self.assertEqual( createThresholds["testSite2"]["pending_jobs"], {0 : 2}, "Error: Wrong number of pending jobs for site 2" ) # We should also have a phedex_name self.assertEqual(createThresholds["testSite1"]["cms_name"], "T1_US_FNAL") self.assertEqual(createThresholds["testSite2"]["cms_name"], "T3_US_FNAL") mergeThreshold1 = None mergeThreshold2 = None procThreshold1 = None procThreshold2 = None self.assertEqual(set(submitThresholds.keys()), set(["testSite1", "testSite2"])) for taskType, threshold in submitThresholds["testSite1"]["thresholds"].items(): if taskType == "Merge": mergeThreshold1 = threshold elif taskType == "Processing": procThreshold1 = threshold for taskType, threshold in submitThresholds["testSite2"]["thresholds"].items(): if taskType == "Merge": mergeThreshold2 = threshold elif taskType == "Processing": procThreshold2 = threshold self.assertEqual(submitThresholds["testSite1"]["total_running_jobs"], 0, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite2"]["total_running_jobs"], 1, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite1"]["total_pending_jobs"], 1, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite2"]["total_pending_jobs"], 0, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual(mergeThreshold1["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold1["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold1["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold1["task_pending_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold2["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold2["task_running_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") return
def testList(self): """ _testList_ Test the functions that list thresholds for creating jobs and submitting jobs. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, 20, "testSE1", "testCE1", "T1_US_FNAL", "LsfPlugin") myResourceControl.insertSite("testSite2", 20, 40, "testSE2", "testCE2") myResourceControl.insertThreshold("testSite1", "Processing", 20, 10) myResourceControl.insertThreshold("testSite1", "Merge", 200, 100) myResourceControl.insertThreshold("testSite2", "Processing", 50, 25) myResourceControl.insertThreshold("testSite2", "Merge", 135, 65) testWorkflow = Workflow(spec = makeUUID(), owner = "Steve", name = makeUUID(), task = "Test") testWorkflow.create() testFilesetA = Fileset(name = "TestFilesetA") testFilesetA.create() testFilesetB = Fileset(name = "TestFilesetB") testFilesetB.create() testFilesetC = Fileset(name = "TestFilesetC") testFilesetC.create() testFileA = File(lfn = "testFileA", locations = set(["testSE1", "testSE2"])) testFileA.create() testFilesetA.addFile(testFileA) testFilesetA.commit() testFilesetB.addFile(testFileA) testFilesetB.commit() testFilesetC.addFile(testFileA) testFilesetC.commit() testSubscriptionA = Subscription(fileset = testFilesetA, workflow = testWorkflow, type = "Processing") testSubscriptionA.create() testSubscriptionA.addWhiteBlackList([{"site_name": "testSite1", "valid": True}]) testSubscriptionB = Subscription(fileset = testFilesetB, workflow = testWorkflow, type = "Processing") testSubscriptionB.create() testSubscriptionB.addWhiteBlackList([{"site_name": "testSite1", "valid": False}]) testSubscriptionC = Subscription(fileset = testFilesetC, workflow = testWorkflow, type = "Merge") testSubscriptionC.create() testJobGroupA = JobGroup(subscription = testSubscriptionA) testJobGroupA.create() testJobGroupB = JobGroup(subscription = testSubscriptionB) testJobGroupB.create() testJobGroupC = JobGroup(subscription = testSubscriptionC) testJobGroupC.create() # Site1, Has been assigned a location and is complete. testJobA = Job(name = "testJobA", files = [testFileA]) testJobA["couch_record"] = makeUUID() testJobA.create(group = testJobGroupA) testJobA["state"] = "success" # Site 1, Has been assigned a location and is incomplete. testJobB = Job(name = "testJobB", files = [testFileA]) testJobB["couch_record"] = makeUUID() testJobB.create(group = testJobGroupA) testJobB["state"] = "executing" runJobB = RunJob() runJobB.buildFromJob(testJobB) runJobB["status"] = "PEND" # Does not have a location, white listed to site 1 testJobC = Job(name = "testJobC", files = [testFileA]) testJobC["couch_record"] = makeUUID() testJobC.create(group = testJobGroupA) testJobC["state"] = "new" # Site 2, Has been assigned a location and is complete. testJobD = Job(name = "testJobD", files = [testFileA]) testJobD["couch_record"] = makeUUID() testJobD.create(group = testJobGroupB) testJobD["state"] = "success" # Site 2, Has been assigned a location and is incomplete. testJobE = Job(name = "testJobE", files = [testFileA]) testJobE["couch_record"] = makeUUID() testJobE.create(group = testJobGroupB) testJobE["state"] = "executing" runJobE = RunJob() runJobE.buildFromJob(testJobE) runJobE["status"] = "RUN" # Does not have a location, site 1 is blacklisted. testJobF = Job(name = "testJobF", files = [testFileA]) testJobF["couch_record"] = makeUUID() testJobF.create(group = testJobGroupB) testJobF["state"] = "new" # Site 3, Has been assigned a location and is complete. testJobG = Job(name = "testJobG", files = [testFileA]) testJobG["couch_record"] = makeUUID() testJobG.create(group = testJobGroupC) testJobG["state"] = "cleanout" # Site 3, Has been assigned a location and is incomplete. testJobH = Job(name = "testJobH", files = [testFileA]) testJobH["couch_record"] = makeUUID() testJobH.create(group = testJobGroupC) testJobH["state"] = "new" # Site 3, Does not have a location. testJobI = Job(name = "testJobI", files = [testFileA]) testJobI["couch_record"] = makeUUID() testJobI.create(group = testJobGroupC) testJobI["state"] = "new" # Site 3, Does not have a location and is in cleanout. testJobJ = Job(name = "testJobJ", files = [testFileA]) testJobJ["couch_record"] = makeUUID() testJobJ.create(group = testJobGroupC) testJobJ["state"] = "cleanout" changeStateAction = self.daoFactory(classname = "Jobs.ChangeState") changeStateAction.execute(jobs = [testJobA, testJobB, testJobC, testJobD, testJobE, testJobF, testJobG, testJobH, testJobI, testJobJ]) self.insertRunJob.execute([runJobB, runJobE]) setLocationAction = self.daoFactory(classname = "Jobs.SetLocation") setLocationAction.execute(testJobA["id"], "testSite1") setLocationAction.execute(testJobB["id"], "testSite1") setLocationAction.execute(testJobD["id"], "testSite1") setLocationAction.execute(testJobE["id"], "testSite1") setLocationAction.execute(testJobG["id"], "testSite1") setLocationAction.execute(testJobH["id"], "testSite1") createThresholds = myResourceControl.listThresholdsForCreate() submitThresholds = myResourceControl.listThresholdsForSubmit() self.assertEqual( len(createThresholds.keys()), 2, "Error: Wrong number of sites in create thresholds" ) self.assertEqual( createThresholds["testSite1"]["total_slots"], 10, "Error: Wrong number of slots for site 1" ) self.assertEqual( createThresholds["testSite2"]["total_slots"], 20, "Error: Wrong number of slots for site 2" ) # We should have two running jobs with locations at site one, # two running jobs without locations at site two, and one running # job without a location at site one and two. self.assertEqual( createThresholds["testSite1"]["pending_jobs"], 4, "Error: Wrong number of pending jobs for site 1" ) # We should have one running job with a location at site 2 and # another running job without a location. self.assertEqual( createThresholds["testSite2"]["pending_jobs"], 2, "Error: Wrong number of pending jobs for site 2" ) # We should also have a phedex_name self.assertEqual(createThresholds["testSite1"]["cms_name"], "T1_US_FNAL") self.assertEqual(createThresholds["testSite2"]["cms_name"], None) mergeThreshold1 = None mergeThreshold2 = None procThreshold1 = None procThreshold2 = None self.assertEqual(submitThresholds["testSite1"]['cms_name'], 'T1_US_FNAL') for threshold in submitThresholds["testSite1"]["thresholds"]: if threshold['task_type'] == "Merge": mergeThreshold1 = threshold elif threshold['task_type'] == "Processing": procThreshold1 = threshold self.assertEqual(submitThresholds["testSite2"]['cms_name'], None) for threshold in submitThresholds["testSite2"]["thresholds"]: if threshold['task_type'] == "Merge": mergeThreshold2 = threshold elif threshold['task_type'] == "Processing": procThreshold2 = threshold self.assertEqual(submitThresholds["testSite1"]["total_running_jobs"], 1, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite2"]["total_running_jobs"], 0, "Error: Wrong number of running jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite1"]["total_pending_jobs"], 1, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual(submitThresholds["testSite2"]["total_pending_jobs"], 0, "Error: Wrong number of pending jobs for submit thresholds.") self.assertEqual(mergeThreshold1["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold1["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold1["task_running_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold1["task_pending_jobs"], 1, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold2["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(mergeThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold2["task_running_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") self.assertEqual(procThreshold2["task_pending_jobs"], 0, "Error: Wrong number of task running jobs for submit thresholds.") return
def testInsert(self): """ _testInsert_ Verify that inserting sites and thresholds works correctly, even if the site or threshold already exists. """ myResourceControl = ResourceControl() myResourceControl.insertSite("testSite1", 10, "testSE1", "testCE1") myResourceControl.insertSite("testSite1", 10, "testSE1", "testCE1") myResourceControl.insertSite("testSite2", 100, "testSE2", "testCE2") myResourceControl.insertThreshold("testSite1", "Processing", 20) myResourceControl.insertThreshold("testSite1", "Merge", 200) myResourceControl.insertThreshold("testSite1", "Merge", 250) myResourceControl.insertThreshold("testSite2", "Processing", 50) myResourceControl.insertThreshold("testSite2", "Merge", 135) createThresholds = myResourceControl.listThresholdsForCreate() assert len(createThresholds.keys()) == 2, \ "Error: Wrong number of site in Resource Control DB" assert "testSite1" in createThresholds.keys(), \ "Error: Test Site 1 missing from thresholds." assert "testSite2" in createThresholds.keys(), \ "Error: Test Site 2 missing from thresholds." assert createThresholds["testSite1"]["total_slots"] == 10, \ "Error: Wrong number of total slots." assert createThresholds["testSite1"]["running_jobs"] == 0, \ "Error: Wrong number of running jobs: %s" % createThresholds["testSite1"]["running_jobs"] assert createThresholds["testSite2"]["total_slots"] == 100, \ "Error: Wrong number of total slots." assert createThresholds["testSite2"]["running_jobs"] == 0, \ "Error: Wrong number of running jobs." thresholds = myResourceControl.listThresholdsForSubmit() assert len(thresholds.keys()) == 2, \ "Error: Wrong number of sites in Resource Control DB" assert "testSite1" in thresholds.keys(), \ "Error: testSite1 missing from thresholds." assert "testSite2" in thresholds.keys(), \ "Error: testSite2 missing from thresholds." site1Thresholds = thresholds["testSite1"] site2Thresholds = thresholds["testSite2"] procThreshold1 = None procThreshold2 = None mergeThreshold1 = None mergeThreshold2 = None for threshold in site1Thresholds: if threshold["task_type"] == "Merge": mergeThreshold1 = threshold elif threshold["task_type"] == "Processing": procThreshold1 = threshold for threshold in site2Thresholds: if threshold["task_type"] == "Merge": mergeThreshold2 = threshold elif threshold["task_type"] == "Processing": procThreshold2 = threshold assert len(site1Thresholds) == 2, \ "Error: Wrong number of task types." assert len(site2Thresholds) == 2, \ "Error: Wrong number of task types." self.assertTrue(procThreshold1 != None) self.assertTrue(procThreshold2 != None) self.assertTrue(mergeThreshold1 != None) self.assertTrue(mergeThreshold2 != None) assert procThreshold1["total_slots"] == 10, \ "Error: Site thresholds wrong" assert procThreshold1["total_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert procThreshold1["task_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert procThreshold1["max_slots"] == 20, \ "Error: Site thresholds wrong" assert mergeThreshold1["total_slots"] == 10, \ "Error: Site thresholds wrong" assert mergeThreshold1["total_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert mergeThreshold1["task_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert mergeThreshold1["max_slots"] == 250, \ "Error: Site thresholds wrong" assert procThreshold2["total_slots"] == 100, \ "Error: Site thresholds wrong" assert procThreshold2["total_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert procThreshold2["task_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert procThreshold2["max_slots"] == 50, \ "Error: Site thresholds wrong" assert mergeThreshold2["total_slots"] == 100, \ "Error: Site thresholds wrong" assert mergeThreshold2["total_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert mergeThreshold2["task_running_jobs"] == 0, \ "Error: Site thresholds wrong" assert mergeThreshold2["max_slots"] == 135, \ "Error: Site thresholds wrong" return