[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Win32 fixes: Unit tests pass again, and py2exe and bdis...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv6637/lib/mixminion

Modified Files:
	Common.py Crypto.py Filestore.py NetUtils.py test.py 
Log Message:
Win32 fixes: Unit tests pass again, and py2exe and bdist_wininst both
seem to work. The client looks happy: I have not a clue about the server.



Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- Common.py	3 Dec 2003 23:18:52 -0000	1.121
+++ Common.py	4 Dec 2003 05:02:50 -0000	1.122
@@ -1383,9 +1383,7 @@
 
 def installSIGCHLDHandler():
     '''Register sigchld handler for this process.'''
-    #WWWWW
     if sys.platform == 'win32':
-        LOG.warn("Skipping installSIGCHLDHandler")
         return
     signal.signal(signal.SIGCHLD, _sigChldHandler)
 
@@ -1468,7 +1466,8 @@
             self._lock(self.fd, blocking)
             self.count += 1
             os.write(self.fd, contents)
-            os.fsync(self.fd)
+            if hasattr(os, "fsync"):
+                os.fsync(self.fd)
         except:
             os.close(self.fd)
             self.fd = None
@@ -1477,12 +1476,16 @@
     def replaceContents(self, contents):
         """Replace the current contents of the lockfile with 'contents',
            without releasing the lock.  Invokers must hold the lock."""
+        # XXXX Actually, on Win32, this actually replaces the first 
+        # XXXX len(contents) characters of the lockfile.  This is a bug.
         assert self.count > 0 and self.fd is not None
         SEEK_SET = 0
         os.lseek(self.fd, 0, SEEK_SET)
-        os.ftruncate(self.fd, 0)
+        if hasattr(os, 'ftruncate'): # Doesn't exist on windows.
+            os.ftruncate(self.fd, 0)
         os.write(self.fd, contents)
-        os.fsync(self.fd)
+        if hasattr(os, 'fsync'):
+            os.fsync(self.fd)
 
     def release(self):
         """Release the lock."""

Index: Crypto.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Crypto.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- Crypto.py	28 Nov 2003 04:14:04 -0000	1.57
+++ Crypto.py	4 Dec 2003 05:02:50 -0000	1.58
@@ -722,7 +722,7 @@
         verbose = (file == requestedFile)
         if not os.path.exists(file):
             if verbose:
-                LOG.error("No such file as %s", file)
+                LOG.warn("No such file as %s", file)
         else:
             st = os.stat(file)
             if not (st[stat.ST_MODE] & stat.S_IFCHR):
@@ -734,6 +734,7 @@
                 break
 
     if randFile is None and _TRNG_FILENAME is None:
+        #XXXX006 on win32, we should do this first.
         if sys.platform == 'win32':
             # We have two entropy sources on windows: openssl's built-in
             # entropy generator that takes data from the screen, and

Index: Filestore.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Filestore.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Filestore.py	28 Nov 2003 04:14:04 -0000	1.14
+++ Filestore.py	4 Dec 2003 05:02:50 -0000	1.15
@@ -20,12 +20,13 @@
 import errno
 import os
 import stat
+import sys
 import threading
 import time
 import whichdb
 
 from mixminion.Common import MixError, MixFatalError, secureDelete, LOG, \
-     createPrivateDir, readFile, tryUnlink
+     createPrivateDir, readFile, replaceFile, tryUnlink
 from mixminion.Crypto import getCommonPRNG
 
 __all__ = [ "StringStore", "StringMetadataStore",
@@ -274,10 +275,9 @@
         try:
             self._lock.acquire()
             try:
-                os.rename(os.path.join(self.dir, s1+"_"+handle),
-                          os.path.join(self.dir, s2+"_"+handle))
+                replaceFile(os.path.join(self.dir, s1+"_"+handle),
+                            os.path.join(self.dir, s2+"_"+handle))
             except OSError, e:
-                # WWWW On windows, replacing metdata can create an error!
                 contents = os.listdir(self.dir)
                 LOG.error("Error while trying to change %s from %s to %s: %s",
                           handle, s1, s2, e)

Index: NetUtils.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/NetUtils.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- NetUtils.py	28 Nov 2003 04:14:04 -0000	1.5
+++ NetUtils.py	4 Dec 2003 05:02:50 -0000	1.6
@@ -193,7 +193,7 @@
     res = [0,0]
     for pos, familyname, loopback in ((0, "AF_INET", "127.0.0.1"),
                                       (1, "AF_INET6", "::1")):
-        family = getattr(socket, familyname)
+        family = getattr(socket, familyname, None)
         if family is None: continue
         s = None
         try:

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- test.py	3 Dec 2003 23:18:52 -0000	1.170
+++ test.py	4 Dec 2003 05:02:50 -0000	1.171
@@ -554,32 +554,44 @@
         self.assertEquals(fn, dX+".2")
 
     def test_lockfile(self):
+        #XXXX The 'locked' cases need to get tested on windows.  Right now
+        #XXXX that's hard, because they don't seem to block one another unless
+        #XXXX you try them from separate processes.
+
         fn = mix_mktemp()
         LF1 = Lockfile(fn)
         LF2 = Lockfile(fn)
         LF1.acquire("LF1")
         if not ON_WINDOWS:
             self.assertEquals("LF1", readFile(fn))
+        if not ON_WIN32:
+            self.assertRaises(LockfileLocked, LF2.acquire, blocking=0)
         LF1.replaceContents("new longer contents")
         if not ON_WINDOWS:
             self.assertEquals("new longer contents", readFile(fn))
         LF1.replaceContents("shorter")
         if not ON_WINDOWS:
             self.assertEquals("shorter", readFile(fn))
-
-        self.assertRaises(LockfileLocked, LF2.acquire, blocking=0)
+        if not ON_WIN32:
+            self.assertRaises(LockfileLocked, LF2.acquire, blocking=0)
         LF1.release()
         LF2.acquire("LF2",1)
-        if not ON_WINDOWS:
+        if not ON_WIN32:
             self.assertEquals("LF2", readFile(fn))
-        self.assertRaises(LockfileLocked, LF1.acquire, blocking=0)
+            self.assertRaises(LockfileLocked, LF1.acquire, blocking=0)
 
         # Now try recursivity.
         LF2.acquire()
-        self.assertRaises(LockfileLocked, LF1.acquire, blocking=0)
+        if not ON_WIN32:
+            self.assertRaises(LockfileLocked, LF1.acquire, blocking=0)
         LF2.release()
-        self.assertRaises(LockfileLocked, LF1.acquire, blocking=0)
+        if not ON_WIN32:
+            self.assertRaises(LockfileLocked, LF1.acquire, blocking=0)
         LF2.release()
+
+        if ON_WIN32:
+            return
+
         LF1.acquire(blocking=1)
 
         # Now try a blocking lock.  We need to block in another process
@@ -7478,7 +7490,7 @@
     tc = loader.loadTestsFromTestCase
 
     if 0:
-        suite.addTest(tc(ServerInfoTests))
+        suite.addTest(tc(MiscTests))
         return suite
     testClasses = [MiscTests,
                    MinionlibCryptoTests,