Rev 2: Define a basic environment. in file:///v/home/vila/.bazaar/plugins/local_test_server/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri May 23 18:10:36 BST 2008


At file:///v/home/vila/.bazaar/plugins/local_test_server/

------------------------------------------------------------
revno: 2
revision-id: v.ladeuil+lp at free.fr-20080523171036-0oimydn77kxknddm
parent: v.ladeuil+lp at free.fr-20080521133855-nnfdmllwsyvohof9
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Fri 2008-05-23 19:10:36 +0200
message:
  Define a basic environment.
  
  * tests/test_config.py: 
  Test basics.
  
  * configs/apache2.conf: 
  First try at simplified apache2 config.
  
  * configs/__init__.py: 
  (Config): New class.
  
  * __init__.py: 
  Add doc. Start defining environment.
added:
  configs/                       configs-20080522095844-nk9u479vv3pp7uj4-1
  configs/__init__.py            __init__.py-20080523170713-0c8mnxio9r41iyhk-1
  configs/apache2.conf           apache2.conf-20080522095851-6eixwo2qv9brec67-1
  etc/                           etc-20080523170706-tosxlttyvwvutu4s-1
  tests/                         tests-20080522095846-k9yakpq7h7rumi69-1
  tests/__init__.py              __init__.py-20080522095852-86lozt5jrpmajiqg-1
  tests/test_config.py           test_config.py-20080523170715-clr6vz0qdzefftob-1
  var/                           var-20080523170708-nkpjg07oorui519n-1
  var/lock/                      lock-20080523170716-vl523z7to322eg8a-1
  var/run/                       run-20080523170717-jvc42ynv6ghppmnk-1
modified:
  __init__.py                    __init__.py-20080521133755-h9wimitytocyyxyv-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-05-21 13:38:55 +0000
+++ b/__init__.py	2008-05-23 17:10:36 +0000
@@ -14,7 +14,89 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-"""Plugin description."""
+"""Manage a local test server and provide it to bzr selftest.
+
+Thsi plugin provides commands to start/stop local test servers which can then
+be used in bzr selftest.
+
+This is not intended to test remote servers for bzr compliance nor should it be
+used as example source on how to configure web servers (many configurations
+settings are tuned to provide low overhead test servers, not something you want
+for real life use).
+
+Instead, this is used locally to test real servers under bzr control.
+
+The bzr test suite has many tests exercising various protocols from the client
+point of view by setting up servers and using them. Yet, most of the time,
+either during setup or verification test phases, files are accessed via the
+file system served, bypassing the server (thta's the main reason why the test
+suite itself can't be used against remote test servers).
+
+The intent of this plugin is to simplify the use of local real servers by the
+test suite.
+
+This will hopefully help in the folowing areas:
+
+- checking bzr support for a given server,
+- allowing client tests writing without the need for a specific test server,
+- validating bzr test servers.
+
+The strategy is to avoid starting and stopping the servers when running the
+test suite, we don't want to test hte servers themselves but the behaviour of
+bzr against them. Also, we don't want to spend time starting and stopping these
+servers when all we are interested in is using them under the same
+configuration from run to run.
+
+Two main points are important for that:
+
+- the IP address MUST be localhost and the port should be provided to bzr
+  (since this is a local server, *you* should decide which port is appropriate
+  (a sane default is used),
+
+- the directory served, containing the tests files, will change from run to
+  run, this addressed by doing XXX.
+
+Finally this plugin is:
+
+- a work in progress, report bugs to bazaar at list.canonical.com
+
+- is not intended to be installed system-wide, it's a developper tool and there
+  is little point in polishing it for a wider audience. If anything doesn't
+  suit your needs, use the source. Patches welcome.
+"""
+
+from bzrlib import (
+    osutils,
+    )
+
+# Directory containing all server configuration files
+base_dir = osutils.dirname(osutils.realpath(__file__))
+
+def get_lts_path(name, subdirs=None, mod=None):
+    """Build and return a path in the local_test_server hierarchy."""
+    if mod is None:
+        mod = osutils.dirname(osutils.realpath(__file__))
+    if subdirs is not None:
+        mod = osutils.pathjoin(mod, *subdirs)
+    return osutils.pathjoin(mod, name)
+
+
+etc_dir = get_lts_path('etc')
+
+# Run-time directories
+var_dir = get_lts_path('var')
+var_run_dir = get_lts_path('run', ['var'])
+var_lock_dir = get_lts_path('lock', ['var'])
 
 def load_tests(basic_tests, module, loader):
+    # This module shouldn't define any tests but I don't know how to report
+    # that. I prefer to update basic_tests with the other tests to detect
+    # unwanted tests and I think that's sufficient.
+
+    testmod_names = [
+        'tests',
+        ]
+    basic_tests.addTest(loader.loadTestsFromModuleNames(
+            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
     return basic_tests
+

=== added directory 'configs'
=== added file 'configs/__init__.py'
--- a/configs/__init__.py	1970-01-01 00:00:00 +0000
+++ b/configs/__init__.py	2008-05-23 17:10:36 +0000
@@ -0,0 +1,48 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""configs -- provides access to server configurations."""
+
+from bzrlib import (
+    osutils,
+    )
+
+
+import bzrlib.plugins.local_test_server as lts
+
+
+# Directory containing all server configuration files
+base_dir = lts.get_lts_path('configs')
+
+
+class Config(object):
+
+    def __init__(self, name):
+        self.name = name
+        self.values = dict(server_name=name,
+                           etc_dir=lts.etc_dir,
+                           var_dir=lts.var_dir,
+                           var_run_dir=lts.var_run_dir,
+                           var_lock_dir=lts.var_lock_dir)
+
+    def expand(self, infile, outfile):
+        """Expand all the config keywords.
+
+        :param infile: A file containing the kwywords to be expanded
+        :param outfile: A opened file where the expansion result is written
+        """
+        for line in infile.readlines():
+            outfile.write(line % self.values)

=== added file 'configs/apache2.conf'
--- a/configs/apache2.conf	1970-01-01 00:00:00 +0000
+++ b/configs/apache2.conf	2008-05-23 17:10:36 +0000
@@ -0,0 +1,45 @@
+#
+# Based on apache2.conf in ubuntu Gusty
+#
+
+# This file will be processed with python '%' operator see plugin
+# source for details.
+
+# Note that most of the directories below are usually owned by
+# root. We want directories writable by the user running the
+# tests.
+
+ServerRoot "%(server_root_dir)s"
+
+LockFile "%(var_lock_dir)s/accept.lock
+
+#
+# PidFile: The file in which the server should record its process
+# identification number when it starts.
+#
+PidFile %(var_run_dir)s/%(server_name)s.pid
+
+#
+# Timeout: The number of seconds before receives and sends time out.
+#
+Timeout 10
+
+#
+# KeepAlive: Whether or not to allow persistent connections (more than
+# one request per connection). Set to "Off" to deactivate.
+#
+KeepAlive On
+
+#
+# MaxKeepAliveRequests: The maximum number of requests to allow
+# during a persistent connection. Set to 0 to allow an unlimited amount.
+# We recommend you leave this number high, for maximum performance.
+#
+MaxKeepAliveRequests 20
+
+#
+# KeepAliveTimeout: Number of seconds to wait for the next request from the
+# same client on the same connection.
+#
+KeepAliveTimeout 5
+

=== added directory 'etc'
=== added directory 'tests'
=== added file 'tests/__init__.py'
--- a/tests/__init__.py	1970-01-01 00:00:00 +0000
+++ b/tests/__init__.py	2008-05-23 17:10:36 +0000
@@ -0,0 +1,23 @@
+# Copyright (C) 2008 by Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+def load_tests(basic_tests, module, loader):
+    testmod_names = [
+        'test_config',
+        ]
+    basic_tests.addTest(loader.loadTestsFromModuleNames(
+            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
+    return basic_tests

=== added file 'tests/test_config.py'
--- a/tests/test_config.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_config.py	2008-05-23 17:10:36 +0000
@@ -0,0 +1,92 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Test the config files and their usage."""
+
+from cStringIO import StringIO
+
+from bzrlib import (
+    tests,
+    )
+
+
+import bzrlib.plugins.local_test_server as lts
+from bzrlib.plugins.local_test_server import (
+    configs
+    )
+
+
+class TestConfigEnv(tests.TestCase):
+
+    def test_etc_exists(self):
+        self.failUnlessExists(lts.etc_dir)
+
+    def test_var_exists(self):
+        self.failUnlessExists(lts.var_dir)
+
+    def test_var_exists_run(self):
+        self.failUnlessExists(lts.var_run_dir)
+
+    def test_var_exists_lock(self):
+        self.failUnlessExists(lts.var_lock_dir)
+
+
+class TestConfig(tests.TestCase):
+
+    def test_build_path(self):
+        path = lts.get_lts_path('foo', ['configs'])
+        self.assertTrue(path.endswith('local_test_server/configs/foo'))
+        path = lts.get_lts_path('foo', ['var', 'run'])
+        self.assertTrue(path.endswith('local_test_server/var/run/foo'))
+
+
+    def test_config_defines_keywords(self):
+        conf = configs.Config('foo')
+        self.assertEquals('foo', conf.values.get('server_name'))
+        self.assertEquals(lts.etc_dir, conf.values.get('etc_dir'))
+        self.assertEquals(lts.var_dir, conf.values.get('var_dir'))
+        self.assertEquals(lts.var_run_dir, conf.values.get('var_run_dir'))
+        self.assertEquals(lts.var_lock_dir, conf.values.get('var_lock_dir'))
+
+    def test_expand_no_keywords(self):
+        conf = configs.Config('foo')
+        content = 'nearly_empty'
+        inf = StringIO(content)
+        outf = StringIO()
+        conf.expand(inf, outf)
+        self.assertEqual(content, outf.getvalue())
+
+    def test_expand_keywords(self):
+        conf = configs.Config('foo')
+        content = '''
+my name is %(server_name)s
+my config is generated under %(etc_dir)s
+my pid is somewhere below %(var_run_dir)s
+I use some lock mechanism which needs something under %(var_lock_dir)s
+'''
+        inf = StringIO(content)
+        outf = StringIO()
+        conf.expand(inf, outf)
+        expanded = outf.getvalue()
+        self.assertContainsRe(expanded, 'my name is foo\n')
+        self.assertContainsRe(
+            expanded, 'my config is generated under .*/etc\n')
+        self.assertContainsRe(
+            expanded, 'my pid is somewhere below .*/var/run\n')
+        self.assertContainsRe(
+            expanded, 'I use some lock mechanism which needs something under'
+            ' .*var/lock\n')
+

=== added directory 'var'
=== added directory 'var/lock'
=== added directory 'var/run'


More information about the bazaar-commits mailing list