[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Tweaks gearing up for 0.0.6rc1.
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv23428/lib/mixminion
Modified Files:
Common.py test.py
Log Message:
Tweaks gearing up for 0.0.6rc1.
Common:
- Document log configuration code; make it easier to force server logs
onto/off of the console
test:
- Add tests for ServerInfo.displayServer.
- Refactor kegen tests to account for new hostname/IP consistency checking.
EventStats:
- Add boilerplate at the head of new stats files.
ServerConfig:
- Document new file configuration functions
ServerKeys:
- Warn if we're configured with a hostname that we can't resolve, or
that doesn't resolve to our IP.
ServerMain:
- Document new directory layout correctly.
- Refactor --echo handling so that it actually works.
Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- Common.py 28 Nov 2003 04:14:04 -0000 1.120
+++ Common.py 3 Dec 2003 23:18:52 -0000 1.121
@@ -864,27 +864,39 @@
"""
self.handlers = []
if config == None or not config.has_section("Server"):
+ # We're configuring a client.
self.setMinSeverity("WARN")
self.addHandler(_ConsoleLogHandler(sys.stderr))
- else:
- #DOCDOC
- self.setMinSeverity(config['Server'].get('LogLevel', "WARN"))
- logfile = config.getLogFile()
- self.addHandler(_ConsoleLogHandler(sys.stderr))
- if logfile:
- try:
- self.addHandler(_FileLogHandler(logfile))
- except MixError, e:
- self.error(str(e))
- if keepStderr or config['Server'].get('EchoMessages',0)==2:
- return
- if (config['Server'].get('Daemon',0) or
- not config['Server'].get('EchoMessages',0)):
- if not self.silenceNoted:
- print "Silencing the console log; look in %s instead"%(
- logfile)
- self.silenceNoted = 1
- del self.handlers[0]
+ return
+
+ # We're configuring the log on a server. Stuff will get complicated
+ # now. First, we set the severity as specified in the configuration...
+ self.setMinSeverity(config['Server'].get('LogLevel', "WARN"))
+ # ...find out what logfile we're supposed to use ...
+ logfile = config.getLogFile()
+ # ...and add a handler to log any messages to stderr.
+ self.addHandler(_ConsoleLogHandler(sys.stderr))
+ if logfile:
+ # First, try to create a file log handler.
+ try:
+ self.addHandler(_FileLogHandler(logfile))
+ except MixError, e:
+ self.error(str(e))
+ return
+ # If we're successful, and we're absolutely supposed to echo
+ # messages (or keepStderr is set), we don't even consider
+ # dumping the console log handler.
+ if keepStderr or config['Server'].get('EchoMessages',0)==2:
+ return
+ # If we're running in daemon mode, or we're not supposed to echo
+ # messages, we remove the console log handler.
+ if (config['Server'].get('Daemon',0) or
+ not config['Server'].get('EchoMessages',0)):
+ if not self.silenceNoted:
+ print "Silencing the console log; look in %s instead"%(
+ logfile)
+ self.silenceNoted = 1
+ del self.handlers[0]
def setMinSeverity(self, minSeverity):
"""Sets the minimum severity of messages to be logged.
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- test.py 28 Nov 2003 04:14:04 -0000 1.169
+++ test.py 3 Dec 2003 23:18:52 -0000 1.170
@@ -4410,6 +4410,40 @@
"""
class ServerInfoTests(TestCase):
+ def test_displayServer(self):
+ ds = mixminion.ServerInfo.displayServer
+ eq = self.assertEquals
+ eq(ds(None), "unknown server")
+ eq(ds("Fred"), "Fred")
+
+ # Test without keyid resolver
+ eq(ds(IPV4Info("1.2.3.4", 48099, "x"*20)),
+ "server at 1.2.3.4:48099")
+
+ eq(ds(MMTPHostInfo("a.b.com", 48099, "x"*20)),
+ "server at a.b.com:48099")
+
+ # Test with keyid resolver
+ def resolver(keyid):
+ if keyid[0] == 'a': return "Kenichi"
+ elif keyid[1] == 'b': return "Tima"
+ else: return None
+ try:
+ mixminion.ServerInfo._keyIDToNicknameFn = resolver
+ eq(ds(IPV4Info("1.2.3.4", 48099, "b"*20)),
+ "'Tima' at 1.2.3.4:48099")
+ eq(ds(IPV4Info("1.2.3.4", 48099, "x"*20)),
+ "server at 1.2.3.4:48099")
+ eq(ds(MMTPHostInfo("ken.com", 48099, "a"*20)),
+ "'Kenichi' at ken.com:48099")
+ finally:
+ mixminion.ServerInfo._keyIDToNicknameFn = None
+
+ # Test serverinfos
+ examples = getExampleServerDescriptors()
+ eq(ds(mixminion.ServerInfo.ServerInfo(string=examples["Fred"][0])),
+ "'Fred' at Fred:48099")
+
def test_ServerInfo(self):
# Try generating a serverinfo and see if its values are as expected.
identity = getRSAKey(1, 2048)
@@ -4422,11 +4456,15 @@
if not os.path.exists(d):
os.mkdir(d, 0700)
- inf = generateServerDescriptorAndKeys(conf,
- identity,
- d,
- "key1",
- d)
+ try:
+ overrideDNS({"Theserver": "192.168.0.1"})
+ inf = generateServerDescriptorAndKeys(conf,
+ identity,
+ d,
+ "key1",
+ d)
+ finally:
+ undoReplacedAttributes()
info = mixminion.ServerInfo.ServerInfo(string=inf)
eq = self.assertEquals
eq(info['Server']['Descriptor-Version'], "0.2")
@@ -4472,11 +4510,15 @@
if not os.path.exists(d):
os.mkdir(d, 0700)
- inf = generateServerDescriptorAndKeys(conf,
- identity,
- d,
- "key2",
- d)
+ try:
+ overrideDNS({"Theserver" : "192.168.0.1"})
+ inf = generateServerDescriptorAndKeys(conf,
+ identity,
+ d,
+ "key2",
+ d)
+ finally:
+ undoReplacedAttributes()
info = mixminion.ServerInfo.ServerInfo(string=inf)
eq(info['Delivery/MBOX'].get('Version'), '0.1')
eq(info['Delivery/Fragmented'].get('Version'), '0.1')
@@ -4598,9 +4640,9 @@
eq(info.getMMTPHostInfo(), info.getRoutingInfo())
self.assert_(info.canStartAt())
- #XXXX006 this is a workaround to deal with the fact that we've
- #XXXX006 opened a fragment DB just to configure the server. Not
- #XXXX006 cool.
+ #XXXX this is a workaround to deal with the fact that we've
+ #XXXX opened a fragment DB just to configure the server. Not
+ #XXXX cool. Startup should get refactored.
conf.getModuleManager().close()
# Now with a shorter configuration
@@ -4614,11 +4656,15 @@
""")
finally:
resumeLog()
- generateServerDescriptorAndKeys(conf,
- identity,
- d,
- "key2",
- d)
+ try:
+ overrideDNS({"Theserver2" : "192.168.0.99"})
+ generateServerDescriptorAndKeys(conf,
+ identity,
+ d,
+ "key2",
+ d)
+ finally:
+ undoReplacedAttributes()
# Now with a bad signature
sig2 = Crypto.pk_sign(sha1("Hello"), identity)
sig2 = base64.encodestring(sig2).replace("\n", "")
@@ -4684,12 +4730,21 @@
finally:
resumeLog()
- _ = generateServerDescriptorAndKeys(conf,
- identity,
- d,
- "key2",
- d,
- useServerKeys=1)
+ try:
+ suspendLog()
+ overrideDNS({"Theserver3" : "1.2.3.4"})
+ _ = generateServerDescriptorAndKeys(conf,
+ identity,
+ d,
+ "key2",
+ d,
+ useServerKeys=1)
+ finally:
+ s = resumeLog()
+ undoReplacedAttributes()
+
+ self.assertEndsWith(s, "Configured hostname 'Theserver3' resolves to"
+ " 1.2.3.4, but we're publishing the IP 192.168.100.3\n")
key3 = mixminion.server.ServerKeys.ServerKeyset(d, "key2", d)
key3.load()
@@ -4709,15 +4764,16 @@
self.assert_(not info3.canRelayTo(info)) # info3 has no outgoing/mmtp
self.assertEquals(info.getRoutingFor(info3)[1],
info3.getRoutingInfo().pack())
- #XXXX006 Test negative (IPv4) cases, somehow.
- key3.regenerateServerDescriptor(conf2, identity)
+ try:
+ overrideDNS({"Theserver4": "192.168.100.4"})
+ key3.regenerateServerDescriptor(conf2, identity)
+ finally:
+ undoReplacedAttributes()
info3 = key3.getServerDescriptor()
eq(info3['Incoming/MMTP']['Hostname'], "Theserver4")
eq(info3['Incoming/MMTP']['IP'], "192.168.100.4")
-
-
def test_directory(self):
eq = self.assertEquals
examples = getExampleServerDescriptors()
@@ -4969,7 +5025,8 @@
# Test rotate
ES.log.rotate(now=tm+3600*24)
s2 = readFile(os.path.join(homedir, "stats"))
- eq(s2.split("\n")[1:], sOrig.split("\n")[1:])
+ eq([ l for l in s2.split("\n") if l == '' or l[0] not in "#="],
+ sOrig.split("\n")[1:])
eq(ES.log.count['UnretriableDelivery'], {})
eq(ES.log.lastSave, tm+3600*24)
eq(ES.log.accumulatedTime, 0)
@@ -5154,11 +5211,13 @@
# Check serverinfo generation.
try:
suspendLog()
+ overrideDNS({"TheServer5" : '1.0.0.1'})
info = generateServerDescriptorAndKeys(
conf, getRSAKey(0,2048), home_dir, "key11", home_dir)
self.failUnless(stringContains(info,"\n[Example]\nFoo: 99\n"))
finally:
resumeLog()
+ undoReplacedAttributes()
manager.close()
# Try again, this time with the test module disabled.
@@ -5852,15 +5911,19 @@
# Now create a keyset
now = time.time()
- keyring.createKeys(1, now)
- # check internal state
- ivals = keyring.keySets
- start = mixminion.Common.previousMidnight(now)
- finish = mixminion.Common.previousMidnight(start+(10*24*60*60)+30)
- self.assertEquals(1, len(ivals))
- self.assertEquals((start,finish), ivals[0][0:2])
+ try:
+ overrideDNS({"Theserver5" : '10.0.0.1'})
+ keyring.createKeys(1, now)
+ # check internal state
+ ivals = keyring.keySets
+ start = mixminion.Common.previousMidnight(now)
+ finish = mixminion.Common.previousMidnight(start+(10*24*60*60)+30)
+ self.assertEquals(1, len(ivals))
+ self.assertEquals((start,finish), ivals[0][0:2])
- keyring.createKeys(2)
+ keyring.createKeys(2)
+ finally:
+ undoReplacedAttributes()
# Check the first key we created
va, vu, _ = keyring._getLiveKeys()[0]
@@ -6153,9 +6216,13 @@
continue
k = "tst%d"%n
validAt = previousMidnight(now + 24*60*60*starting[n])
- gen(config=conf, identityKey=identity, keyname=k,
- keydir=tmpkeydir, hashdir=tmpkeydir, validAt=validAt,
- now=publishing)
+ try:
+ overrideDNS({nickname: ip})
+ gen(config=conf, identityKey=identity, keyname=k,
+ keydir=tmpkeydir, hashdir=tmpkeydir, validAt=validAt,
+ now=publishing)
+ finally:
+ undoReplacedAttributes()
sd = os.path.join(tmpkeydir,"key_"+k,"ServerDesc")
_EXAMPLE_DESCRIPTORS[nickname].append(readFile(sd))
@@ -7411,7 +7478,7 @@
tc = loader.loadTestsFromTestCase
if 0:
- suite.addTest(tc(DNSFarmTests))
+ suite.addTest(tc(ServerInfoTests))
return suite
testClasses = [MiscTests,
MinionlibCryptoTests,