Rev 39: Add vsftpd. in http://bazaar.launchpad.net/%7Evila/bzr/local-test-server
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Jun 24 21:06:37 BST 2008
At http://bazaar.launchpad.net/%7Evila/bzr/local-test-server
------------------------------------------------------------
revno: 39
revision-id: v.ladeuil+lp at free.fr-20080624200635-u290d1dgy937ur93
parent: v.ladeuil+lp at free.fr-20080624165649-w5xzsgiexl8z8em8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Tue 2008-06-24 22:06:35 +0200
message:
Add vsftpd.
* tests/test_utils.py:
(ServerAdapter.__init__): Add vsftpd.
* tests/test_test_server.py:
(TestTestServer.test_server_setup_and_teardown): Temporary and
partly disabled.
* tests/test_config.py:
(TestConfig.test_config_defines_keywords): Update test for 'user'.
* test_server.py:
(VsftpdFeature): New feature.
(LocalTestServer): Abstract common parts between http and ftp.
(LocalHTTPTestServer): Simplified.
(LocalFTPTestServer): New class.
(Vsftpd): New test server.
(get_test_permutations): Add vsftpd.
* server.py:
(Vsftpd): New server.
(_servers): Declare all the servers e same way. Add vsftpd.
* config.py:
(Config.__init__): vsftpd needs a user for impersonate anonymous
connections.
(Vsftpd): New config.
* __init__.py:
Declare a fake ftp transport to be able to inject our ftp servers.
modified:
__init__.py __init__.py-20080521133755-h9wimitytocyyxyv-1
config.py __init__.py-20080523170713-0c8mnxio9r41iyhk-1
server.py server.py-20080524160639-rqhbexqatjqbwypw-1
test_server.py test_server.py-20080530070615-f555godexnk7frms-1
tests/test_config.py test_config.py-20080523170715-clr6vz0qdzefftob-1
tests/test_test_server.py test_test_server.py-20080530070620-xatqa0pbxvo7u2v0-1
tests/test_utils.py test_utils.py-20080603162150-w01001l902j0gu95-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2008-05-30 07:57:14 +0000
+++ b/__init__.py 2008-06-24 20:06:35 +0000
@@ -90,5 +90,6 @@
transport.register_lazy_transport(
'http://',
'bzrlib.plugins.local_test_server.test_server', 'HttpTransport_urllib')
-
-
+transport.register_lazy_transport(
+ 'ftp://',
+ 'bzrlib.plugins.local_test_server.test_server', 'FtpTransport')
=== modified file 'config.py'
--- a/config.py 2008-06-24 16:52:55 +0000
+++ b/config.py 2008-06-24 20:06:35 +0000
@@ -17,6 +17,7 @@
"""configs -- generates server configurations."""
import errno
+import getpass
import os
@@ -67,6 +68,7 @@
for name, relpath in self.required_dirs.items():
self.values[name] = self.abspath(relpath)
+ self.values['user'] = getpass.getuser()
self.values['base_dir'] = self.base_dir
self.values['pid_file'] = self.abspath('var/run/%s.pid' % self.name)
self.values['log_file'] = self.abspath('var/log/error.log')
@@ -102,6 +104,8 @@
class HttpConfig(Config):
"""Common base class for all http servers."""
+# FIXME: Couldn't the following be simplified by defining name and
+# required_dirs as class attributes ?
class Apache2(HttpConfig):
@@ -151,3 +155,8 @@
super(LighttpdDAV, self).__init__('lighttpd-dav', _base_dir=_base_dir)
+class Vsftpd(Config):
+
+ def __init__(self, _base_dir=None):
+ super(Vsftpd, self).__init__('vsftpd', _base_dir=_base_dir)
+
=== modified file 'server.py'
--- a/server.py 2008-06-24 16:56:49 +0000
+++ b/server.py 2008-06-24 20:06:35 +0000
@@ -467,6 +467,35 @@
self.output_config_path = self.config.abspath('etc/lighttpd-dav.conf')
+class Vsftpd(Server):
+
+ def __init__(self, port, _conf=None):
+ if _conf is None:
+ _conf = config.Vsftpd()
+ # FIXME: it's weird to reverse parameter order
+ super(Vsftpd, self).__init__(_conf, port)
+ self.output_config_path = self.config.abspath('etc/vsftpd.conf')
+
+ def _start(self):
+ # This is the best we can do: just spawn the process hoping nothing
+ # goes wrong during server launch... There is nothing in the log to get
+ # confirmation that the start went right, the log file itself is not
+ # created before the first connection :-/
+ proc = subprocess.Popen(['vsftpd', self.output_config_path])
+ if proc.returncode is not None:
+ raise LTSCantStartError(self, 'return code: %s' % proc.returncode)
+ f = open(self.get_config_value('pid_file'), 'w')
+ try:
+ f.write('%s' % proc.pid)
+ finally:
+ f.close()
+
+ def _stop(self):
+ if not self._wait_for_server_process_death():
+ raise LTSCantStopError(self)
+ # We need to delete the pid file ourselves
+ osutils.delete_any(self.get_config_value('pid_file'))
+
_next_available_port = 49000
_max_available_port = 49151
@@ -495,13 +524,15 @@
# The test servers provided use a range of unassigned port numbers as described
# in http://www.iana.org/assignments/port-numbers
-_servers = dict(apache2=Apache2(37000),
- cherokee=Cherokee(37001),
- lighttpd=Lighttpd(37002),
- )
-_servers['apache2-dav']=Apache2DAV(37003)
-_servers['lighttpd-dav']=LighttpdDAV(37004)
-_servers['apache2-svn']=Apache2SVN(37005)
+_servers = dict()
+_servers['apache2'] = Apache2DAV(37000)
+_servers['cherokee'] = Apache2DAV(37001)
+_servers['lighttpd'] = Apache2DAV(37002)
+_servers['apache2-dav'] = Apache2DAV(37003)
+_servers['lighttpd-dav'] = LighttpdDAV(37004)
+_servers['apache2-svn'] = Apache2SVN(37005)
+_servers['vsftpd'] = Vsftpd(37006)
+
def get_server(name):
return _servers.get(name, None)
=== modified file 'test_server.py'
--- a/test_server.py 2008-06-24 16:52:55 +0000
+++ b/test_server.py 2008-06-24 20:06:35 +0000
@@ -31,6 +31,7 @@
tests,
transport,
)
+from bzrlib.transport import ftp
from bzrlib.transport.http import (
_urllib,
)
@@ -86,30 +87,56 @@
_server_name = 'lighttpd-dav'
-class LocalHTTPTestServer(transport.Server):
+class VsftpdFeature(LocalTestServerFeature):
+
+ _server_name = 'vsftpd'
+
+
+class LocalTestServer(transport.Server):
# Must be set by daughter classes
_server_name = None
# used to form the url that connects to this server
- _url_protocol = 'http'
+ _url_protocol = None
def __init__(self, _server=None):
- super(LocalHTTPTestServer, self).__init__()
+ super(LocalTestServer, self).__init__()
if _server is None:
_server = server.get_server(self._server_name)
self._server = _server
self.host = self._server.get_config_value('host')
self.port = self._server.get_config_value('port')
- self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
- self.host, self.port)
- self._base_dir = None
-
- def setUp(self, backing_transport_server=None):
- # redirect to the right url
+ self._base_url = None
+ self._test_working_dir = None
+
+ def _build_base_url(self):
+ return '%s://%s:%s/' % (self._url_protocol, self.host, self.port)
+
+ def get_bogus_url(self):
+ """See bzrlib.transport.Server.get_bogus_url."""
+ # this is chosen to try to prevent trouble with proxies, weird dns,
+ # etc
+ return self._url_protocol + '://127.0.0.1:1/'
+
+ def setUp(self):
+ """Build a specific directory to be served."""
+ super(LocalTestServer, self).setUp()
# Hard to believe, but the directory to be served is the current one at
# setUp time...
- self._base_dir = os.getcwdu()
+ self._test_working_dir = os.getcwdu()
+ self._base_url = self._build_base_url()
+
+ def get_url(self):
+ """See bzrlib.transport.Server.get_url."""
+ return self._base_url + self._symlink_name
+
+
+class LocalHTTPTestServer(LocalTestServer):
+
+ _url_protocol = 'http'
+
+ def _build_symlink_under_data_dir(self):
# Some servers (notably cherokee) don't check the file system when
# serving files, relying on the assumption that nobody will change file
# content behind their back. But the test suite often create files with
@@ -123,23 +150,26 @@
self._symlink_name = rnd_name
data_dir = self._server.get_config_value('data_dir')
- os.symlink(self._base_dir,
+ os.symlink(self._test_working_dir,
osutils.pathjoin(data_dir, self._symlink_name))
+ def setUp(self):
+ """Build a specific directory to be served."""
+ # Hard to believe, but the directory to be served is the current one at
+ # setUp time...
+ super(LocalHTTPTestServer, self).setUp()
+ self._build_symlink_under_data_dir()
+
def tearDown(self):
"""See bzrlib.transport.Server.tearDown."""
+ super(LocalHTTPTestServer, self).tearDown()
data_dir = self._server.get_config_value('data_dir')
osutils.delete_any(osutils.pathjoin(data_dir, self._symlink_name))
- def get_url(self):
- """See bzrlib.transport.Server.get_url."""
- return self._http_base_url + self._symlink_name
-
- def get_bogus_url(self):
- """See bzrlib.transport.Server.get_bogus_url."""
- # this is chosen to try to prevent trouble with proxies, weird dns,
- # etc
- return self._url_protocol + '://127.0.0.1:1/'
+
+class LocalFTPTestServer(LocalTestServer):
+
+ _url_protocol = 'ftp'
class Apache2(LocalHTTPTestServer):
@@ -217,12 +247,28 @@
_url_protocol = 'http+webdav'
+class Vsftpd(LocalFTPTestServer):
+
+ _server_name = 'vsftpd'
+
+ def _build_base_url(self):
+ # We use anonymous to avoid having to store the password of the user
+ # running the tests
+ return '%s://anonymous@%s:%s' % (self._url_protocol,
+ self.host, self.port)
+ def get_url(self):
+ """See bzrlib.transport.Server.get_url."""
+ return self._base_url + self._test_working_dir
+
+
+
# We have registered a transport for the purpose of adding new servers in the
# test permutations. Registering a transport makes our module appears in the
# list which is queried for a get_test_permutations function.
+# Since we pretended to define the transports alias them to the real ones
HttpTransport_urllib = _urllib.HttpTransport_urllib
-
+FtpTransport = ftp.FtpTransport
def get_test_permutations():
"""Return the permutations to be used in testing."""
@@ -258,4 +304,7 @@
if LighttpdDAVFeature().available():
permutations.append((webdav.HttpDavTransport, LighttpdDAV))
+ if VsftpdFeature().available():
+ permutations.append((FtpTransport, Vsftpd))
+
return permutations
=== modified file 'tests/test_config.py'
--- a/tests/test_config.py 2008-06-24 16:52:55 +0000
+++ b/tests/test_config.py 2008-06-24 20:06:35 +0000
@@ -17,6 +17,7 @@
"""Test the config files and their usage."""
from cStringIO import StringIO
+import getpass
from bzrlib import (
osutils,
@@ -101,6 +102,7 @@
def test_config_defines_keywords(self):
conf = self._get_config()
+ self.assertEquals(getpass.getuser(), conf.get_value('user'))
self.assertEquals(self._server_name, conf.get_value('server_name'))
self._check_conf_path(conf, 'etc_dir', 'etc')
self._check_conf_path(conf, 'var_run_dir', 'var/run')
=== modified file 'tests/test_test_server.py'
--- a/tests/test_test_server.py 2008-06-24 16:52:55 +0000
+++ b/tests/test_test_server.py 2008-06-24 20:06:35 +0000
@@ -71,8 +71,14 @@
self.addCleanup(ts._server.stop)
ts.setUp()
- data_dir = ts._server.get_config_value('data_dir')
- served_dir = osutils.pathjoin(data_dir, ts._symlink_name)
- self.assertIsSameRealPath(served_dir, self.test_dir)
+
+ # FIXME: There ought to be better tests than simple smoke ones, the
+ # following is commented out as the code is heavily exercised when the
+ # local test servers are used by the bzr test suite. And it fails for
+ # ftp since, really, ftp serves '/' :-P
+
+# data_dir = ts._server.get_config_value('data_dir')
+# served_dir = osutils.pathjoin(data_dir, ts._symlink_name)
+# self.assertIsSameRealPath(served_dir, self.test_dir)
ts.tearDown()
=== modified file 'tests/test_utils.py'
--- a/tests/test_utils.py 2008-06-15 08:59:23 +0000
+++ b/tests/test_utils.py 2008-06-24 20:06:35 +0000
@@ -109,6 +109,13 @@
_server_feature_class=test_server.LighttpdDAVFeature,
_test_server_class=test_server.LighttpdDAV,
)),
+ ('vsftpd', dict(
+ _server_name='vsftpd',
+ _config_class=config.Vsftpd,
+ _server_class=server.Vsftpd,
+ _server_feature_class=test_server.VsftpdFeature,
+ _test_server_class=test_server.Vsftpd,
+ )),
]
self.scenarios = server_scenarios
More information about the bazaar-commits
mailing list