def makePrioCorrectionsAds(): """ Optimize the PostJobPrio* entries for HTCondor matchmaking. This will sort jobs within the schedd along the following criteria (higher is better): 1) Workflow ID (lower is better). 2) Step in workflow (later is better) 3) # of sites in whitelist (lower is better). 4) Estimated job runtime (lower is better). 5) Estimated job disk requirements (lower is better). """ anAd = classad.ClassAd() anAd["GridResource"] = "condor localhost localhost" anAd["TargetUniverse"] = 5 anAd["Name"] = "Prio Corrections" anAd["Requirements"] = classad.ExprTree( "(target.HasPrioCorrection isnt true)") anAd["set_HasPrioCorrection"] = True anAd["set_HasBeenRouted"] = False # -1 * Number of sites in workflow. anAd["copy_PostJobPrio1"] = "WMAgent_PostJobPrio1" # -1 * Workflow ID (newer workflows have higher numbers) anAd["copy_PostJobPrio2"] = "WMAgent_PostJobPrio2" anAd["eval_set_JR_PostJobPrio1"] = classad.ExprTree( "WMAgent_PostJobPrio2*100*1000 + size(WMAgent_SubTaskName)*100 + WMAgent_PostJobPrio1" ) anAd["eval_set_JR_PostJobPrio2"] = classad.ExprTree( "-MaxWallTimeMins - RequestDisk/1000000") anAd["set_PostJobPrio1"] = classad.Attribute("JR_PostJobPrio1") anAd["set_PostJobPrio2"] = classad.Attribute("JR_PostJobPrio2") print anAd
def test_operator(self): expr = classad.Literal(1) + 2 self.assertTrue(isinstance(expr, classad.ExprTree)) self.assertTrue(expr) self.assertTrue(expr.sameAs(classad.ExprTree('1 + 2'))) expr = classad.Literal(1) & 2 self.assertTrue(isinstance(expr, classad.ExprTree)) self.assertEquals(expr.eval(), 0) self.assertTrue(expr.sameAs(classad.ExprTree('1 & 2'))) expr = classad.Attribute("foo").is_(classad.Value.Undefined) self.assertTrue(expr.eval()) ad = classad.ClassAd("[foo = 1]") expr = classad.Attribute("foo").isnt_(classad.Value.Undefined) self.assertTrue(expr.eval(ad)) expr = classad.Literal(1).and_(classad.Literal(2)) self.assertRaises(RuntimeError, bool, expr)
def test_flatten(self): expr = classad.Attribute("foo") == classad.Attribute("bar") ad = classad.ClassAd({"bar": 1}) self.assertTrue(ad.flatten(expr).sameAs(classad.ExprTree('foo == 1')))
def test_subscript(self): ad = classad.ClassAd({'foo': [0, 1, 2, 3]}) expr = classad.Attribute("foo")._get(2) self.assertTrue(isinstance(expr, classad.ExprTree)) self.assertEquals(expr.eval(), classad.Value.Undefined) self.assertEquals(expr.eval(ad), 2)
def test_flatten(ad): ad["bar"] = 1 expr = classad.Attribute("foo") == classad.Attribute("bar") assert ad.flatten(expr).sameAs(classad.ExprTree("foo == 1"))
def test_subscript(ad): ad["foo"] = [0, 1, 2, 3] expr = classad.Attribute("foo")._get(2) assert expr.eval(ad) == 2
assert expr.eval(ad) == classad.Value.Undefined @pytest.mark.parametrize( "expr, expected", [ (classad.Literal(1) + 2, 3), (classad.Literal(1) + classad.Literal(2), 3), (classad.Literal(1) - 2, -1), (classad.Literal(1) * 2, 2), (classad.Literal(2) / 2, 1), (classad.Literal(1) & 2, 0), (classad.Literal(1) | 2, 3), (classad.Literal(1).and_(2), True), (classad.Literal(1).and_(classad.Literal(2)), True), (classad.Attribute("foo").is_(classad.Value.Undefined), True), ], ) def test_operators_produce_exprtrees_and_eval_as_expected(expr, expected): assert isinstance(expr, classad.ExprTree) assert expr.eval() == expected def test_subscript(ad): ad["foo"] = [0, 1, 2, 3] expr = classad.Attribute("foo")._get(2) assert expr.eval(ad) == 2 def test_function():