예제 #1
0
 def testMsgSubsts(self):
     "Test subst-created additional substitutions."
     hi = makehi(rip="127.100.1.2")
     aroot = actions.fromfile(StringIO(testSubstFile), "<t>")
     r = aroot.genaction(hi, genrules(("class1",)))
     self.assertEqual(r.logmsgs, ["1: foo-127.100.1.2-bar 2: HUP HIKE"])
     r = aroot.genaction(hi, genrules(("class2",)))
     self.assertEqual(r.arglist, ["id", "-x", "UNKNOWN"])
     # Now make sure that we haven't mutated the substitutions
     # for class1 somehow (perhaps replacing the pre-expansion
     # versions with the post-expansion ones).
     hi = makehi(rip="0.0.1.0")
     r = aroot.genaction(hi, genrules(("class1",)))
     self.assertEqual(r.logmsgs, ["1: foo-0.0.1.0-bar 2: HUP HIKE"])
예제 #2
0
 def testRunArgSplit(self):
     "Test that run and failrun properly split their arguments before string substitution."
     aroot = actions.fromfile(StringIO(splitTFile), "<t>")
     hi = makehi()
     for rn, rl, alst, astr in self.knownValues:
         r = aroot.genaction(hi, (FakeRule(rn, rl),))
         self.assertEqual(r.argstring, astr)
         self.assertEqual(r.arglist, alst)
예제 #3
0
 def testFunctionResults(self):
     "Test that actions evaluation is setting the right functions to run."
     arules = actions.fromfile(StringIO(actEvalfile), "t")
     hi = makehi(rip="127.0.0.1")
     for cls, fres, vres in self.knownFuncResults:
         rlist = genrules(cls)
         r = arules.genaction(hi, rlist)
         self.assertEqual(r.what, fres)
         self.assertEqual(r.argstring, vres)
예제 #4
0
 def testNoSubst(self):
     "Test that we can disable string substitutions."
     si = StringIO("a: ipmax 0 : faillog %(ip)s\n")
     aroot = actions.fromfile(si, "<t>")
     actions.dosubstitutions(0)
     r = aroot.genaction(makehi(), genrules(("a,")))
     self.assertEqual(r.logmsgs, ["%(ip)s"])
     # We'd BETTER restore that default!
     actions.dosubstitutions(1)
예제 #5
0
 def testBasicSees(self):
     "Test that basic 'see' operations work correctly."
     si = StringIO(testSeeF)
     hi = makehi(rip="0.0.0.1")
     aroot = actions.fromfile(si, "<t>")
     for cls, what, argstr, logmsgs in self.knownValues:
         r = aroot.genaction(hi, genrules((cls,)))
         self.assertEqual(r.what, what)
         self.assertEqual(r.argstring, argstr)
         self.assertEqual(r.logmsgs, logmsgs)
예제 #6
0
 def testDefaultsMatrix(self):
     "Test a matrix of known defaulting failmsg and faillog results."
     hi = makehi()
     for plusList, cls, argRes, logRes in self.knownValues:
         t = "\n".join(plusList)
         si = StringIO(failDefs + t)
         aroot = actions.fromfile(si, "<t>")
         r = aroot.genaction(hi, genrules((cls,)))
         self.assertEqual(r.argstring, argRes)
         self.assertEqual(r.logmsgs, logRes)
예제 #7
0
 def testLoggedResults(self):
     "Test what is logged on the generated action."
     actrules = actions.fromfile(StringIO(actEvalfile), "<t>")
     for cls, logres in self.knownLogresults:
         rlist = genrules(cls)
         hi = makehi(rip="127.0.0.1")
         r = actrules.genaction(hi, rlist)
         if not r:
             self.assertEqual(0, 1, "genaction was null")
         self.assertEqual(r.logmsgs, logres)
예제 #8
0
 def testNoRepLog(self):
     "Test that the norepeatlog directive works right"
     hi = makehi()
     for clslst, logres in self.knownValues:
         si = StringIO(testLogRepFile)
         # We generate the action root anew each time
         # to insure that we have a consistent start point.
         aroot = actions.fromfile(si, "<t>")
         for cls in clslst:
             r = aroot.genaction(hi, genrules((cls,)))
         self.assertEqual(r.logmsgs, logres)
예제 #9
0
 def testEnvResults(self):
     "Test that the environment is set properly."
     arules = actions.fromfile(StringIO(actEvalfile), "t")
     hi = makehi(rip="127.0.0.1")
     for clsname, envres in self.knownEnvResults:
         rlist = genrules((clsname,))
         r = arules.genaction(hi, rlist)
         l = r.env.keys()
         l.sort()
         rl = [(k, r.env[k]) for k in l]
         self.assertEqual(rl, envres)
예제 #10
0
 def testEnvShadowing(self):
     "Test that setenv environment variables properly get set up."
     si = StringIO(testSeeF)
     hi = makehi()
     aroot = actions.fromfile(si, "<t>")
     r = aroot.genaction(hi, genrules(("classA",)))
     re = r.env.items()
     re.sort()
     self.assertEqual(re, [("a", "1"), ("b", "10")])
     r = aroot.genaction(hi, genrules(("classB",)))
     re = r.env.items()
     re.sort()
     self.assertEqual(re, [("a", "2"), ("b", "10")])
예제 #11
0
 def testMaxLims(self):
     "Test that connmax and ipmax are correctly handled in see situations."
     rip = "0.0.0.1"
     hi = makehi(rip=rip)
     aroot = actions.fromfile(StringIO(testSeeF), "<t>")
     clsl = genrules(("class50",))
     for ipl, connl, lmsg in self.knownLimVals:
         conntrack._clearmaps()
         for i in range(0, ipl):
             conntrack.up(i, rip, [])
         for i in range(0, connl):
             conntrack.up(i + 100, "NOIP", ["class50"])
         r = aroot.genaction(hi, clsl)
         self.assertEqual(r.logmsgs, lmsg)
         # insure that this stays true if we up class51 too.
         conntrack.up(1000, "NOIP", ["class51"])
         conntrack.up(1001, "NOIP", ["class51"])
         conntrack.up(1002, "NOIP", ["class51"])
         r = aroot.genaction(hi, clsl)
         self.assertEqual(r.logmsgs, lmsg)
예제 #12
0
 def testActGenMsgFailure(self):
     "Test that we properly raise an error during action evaluation if we are formatting a bad string."
     si = StringIO("a: ipmax 0 : failmsg %(abcdef)s\n")
     aroot = actions.fromfile(si, "<t>")
     rlist = genrules(("a",))
     self.assertRaises(actions.BadAction, aroot.genaction, makehi(), rlist)
예제 #13
0
 def testLogLabelLine(self):
     "Test that a label is properly logged."
     actrules = actions.fromfile(StringIO("a: ipmax 0 : faillog %(label)s@%(lineno)s\n"), "<t>")
     hi = makehi()
     r = actrules.genaction(hi, (FakeRule("a", "foobar-label"),))
     self.assertEqual(r.logmsgs, ["foobar-label@-1"])
예제 #14
0
 def testActRDoesFail(self):
     "Test ActRule.doesfailall() with basic known values."
     for s, r in self.knownDoesfails:
         hi = makehi()
         ar = actions.parseline(s, 0)
         self.assertEqual(ar.doesfailall(hi), r)