Commit 05ee7f5e authored by Jim Fulton's avatar Jim Fulton

Switched to using the subprocess module so that the zeo server closes

all but the standard file descriptors.  This fixed a really hard to
debug test failure. (A server started after a client storage was
started had the client storage's cache loc file open, preventing the
client storage from being reopened.)

For starting servers, the storage config not defaults to a simple
file-storage configuration.

Use a simple log file configuration for the storage server rather than
trying to somehow copy the useless test log configuration. This makes
it far more likely that there will be a sever log available when
debugging test failures.
parent 4aa885a8
...@@ -19,6 +19,7 @@ import sys ...@@ -19,6 +19,7 @@ import sys
import time import time
import errno import errno
import socket import socket
import subprocess
import logging import logging
import StringIO import StringIO
import tempfile import tempfile
...@@ -60,39 +61,14 @@ class ZEOConfig: ...@@ -60,39 +61,14 @@ class ZEOConfig:
print >> f, "authentication-realm", self.authentication_realm print >> f, "authentication-realm", self.authentication_realm
print >> f, "</zeo>" print >> f, "</zeo>"
logger = logging.getLogger() print >> f, """
print >> f <eventlog>
print >> f, "<eventlog>" level INFO
print >> f, "level", logger.level <logfile>
for handler in logger.handlers: path server-%s.log
if isinstance(handler, logging.FileHandler): </logfile>
path = handler.baseFilename </eventlog>
elif isinstance(handler, logging.StreamHandler): """ % self.address[1]
stream = handler.stream
if stream.name == "<stdout>":
path = "STDOUT"
elif stream.name == "<stderr>":
path = "STDERR"
else:
# just drop it on the floor; unlikely an issue when testing
continue
else:
# just drop it on the floor; unlikely an issue when testing
continue
# This doesn't convert the level values to names, so the
# generated configuration isn't as nice as it could be,
# but it doesn't really need to be.
print >> f, "<logfile>"
print >> f, "level", handler.level
print >> f, "path ", path
if handler.formatter:
formatter = handler.formatter
if formatter._fmt:
print >> f, "format", encode_format(formatter._fmt)
if formatter.datefmt:
print >> f, "dateformat", encode_format(formatter.datefmt)
print >> f, "</logfile>"
print >> f, "</eventlog>"
def __str__(self): def __str__(self):
f = StringIO.StringIO() f = StringIO.StringIO()
...@@ -109,7 +85,8 @@ def encode_format(fmt): ...@@ -109,7 +85,8 @@ def encode_format(fmt):
return fmt return fmt
def start_zeo_server(storage_conf, zeo_conf=None, port=None, keep=False): def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
path='Data.fs'):
"""Start a ZEO server in a separate process. """Start a ZEO server in a separate process.
Takes two positional arguments a string containing the storage conf Takes two positional arguments a string containing the storage conf
...@@ -119,6 +96,9 @@ def start_zeo_server(storage_conf, zeo_conf=None, port=None, keep=False): ...@@ -119,6 +96,9 @@ def start_zeo_server(storage_conf, zeo_conf=None, port=None, keep=False):
to the config file. to the config file.
""" """
if not storage_conf:
storage_conf = '<filestorage>\npath %s\n</filestorage>' % path
if port is None: if port is None:
raise AssertionError("The port wasn't specified") raise AssertionError("The port wasn't specified")
...@@ -148,7 +128,9 @@ def start_zeo_server(storage_conf, zeo_conf=None, port=None, keep=False): ...@@ -148,7 +128,9 @@ def start_zeo_server(storage_conf, zeo_conf=None, port=None, keep=False):
args.append("-k") args.append("-k")
d = os.environ.copy() d = os.environ.copy()
d['PYTHONPATH'] = os.pathsep.join(sys.path) d['PYTHONPATH'] = os.pathsep.join(sys.path)
pid = os.spawnve(os.P_NOWAIT, sys.executable, tuple(args), d)
pid = subprocess.Popen(args, env=d, close_fds=True).pid
adminaddr = ('localhost', port + 1) adminaddr = ('localhost', port + 1)
# We need to wait until the server starts, but not forever. # We need to wait until the server starts, but not forever.
# 30 seconds is a somewhat arbitrary upper bound. A BDBStorage # 30 seconds is a somewhat arbitrary upper bound. A BDBStorage
...@@ -292,7 +274,7 @@ def setUp(test): ...@@ -292,7 +274,7 @@ def setUp(test):
servers = [] servers = []
def start_server(storage_conf, zeo_conf=None, port=None, keep=False, def start_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
addr=None): addr=None):
"""Start a ZEO server. """Start a ZEO server.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment