[SCM] Samba Shared Repository - branch master updated

Jelmer Vernooij jelmer at samba.org
Sun Mar 4 21:43:03 MST 2012


The branch, master has been updated
       via  53a147d selftest.run: Factor out read_testlist_file and open_file_or_pipe.
       via  f26b40a selftest.run: Factor out exported_envvars_str.
       via  a6a8456 selfclient.client: Factor out write_clientconf.
       via  f3f6b8e selftest.run: Factor out expand_command_run.
       via  d6924f8 selftest.run: Factor out expand_command_list.
       via  1741e64 selftest: Factor out expand_environment_strings.
      from  5c5111c s3-ctdb: Enable CTDB readonly support only if CTDB supports it

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 53a147d1c0c54fe94ac21f25088fd874d1300102
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 5 04:05:35 2012 +0100

    selftest.run: Factor out read_testlist_file and open_file_or_pipe.
    
    Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
    Autobuild-Date: Mon Mar  5 05:42:19 CET 2012 on sn-devel-104

commit f26b40a92553863bc0da39918ff19bf21199c608
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 5 03:49:50 2012 +0100

    selftest.run: Factor out exported_envvars_str.

commit a6a84566466a59fc954268ebd616ef1af4b347b1
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 5 03:45:57 2012 +0100

    selfclient.client: Factor out write_clientconf.

commit f3f6b8eafa07b8d9e815e023adb8825ce89ef8da
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 5 03:39:57 2012 +0100

    selftest.run: Factor out expand_command_run.

commit d6924f803904d25a7f9cac2ec69f421d7a5bdeab
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 5 03:27:40 2012 +0100

    selftest.run: Factor out expand_command_list.

commit 1741e6486dbae821aaac8bc4bd52938e4034f870
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 5 03:20:13 2012 +0100

    selftest: Factor out expand_environment_strings.

-----------------------------------------------------------------------

Summary of changes:
 selftest/client.py              |   80 ++++++++++++++++++++++
 selftest/run.py                 |   79 ++++++++++++++++++++++
 selftest/selftest.py            |  142 +++++++--------------------------------
 selftest/testlist.py            |   33 +++++++++
 selftest/tests/__init__.py      |    2 +-
 selftest/tests/test_run.py      |   94 ++++++++++++++++++++++++++
 selftest/tests/test_testlist.py |   46 +++++++++++++
 7 files changed, 357 insertions(+), 119 deletions(-)
 create mode 100644 selftest/client.py
 create mode 100644 selftest/run.py
 create mode 100644 selftest/tests/test_run.py


Changeset truncated at 500 lines:

diff --git a/selftest/client.py b/selftest/client.py
new file mode 100644
index 0000000..81a9889
--- /dev/null
+++ b/selftest/client.py
@@ -0,0 +1,80 @@
+#!/usr/bin/python -u
+# Bootstrap Samba and run a number of tests against it.
+# Copyright (C) 2012 Jelmer Vernooij <jelmer at samba.org>
+
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import os
+import shutil
+
+def write_clientconf(conffile, clientdir, vars):
+    if not os.path.isdir(clientdir):
+        os.mkdir(clientdir, 0777)
+
+    for n in ["private", "lockdir", "statedir", "cachedir"]:
+        p = os.path.join(clientdir, n)
+        if os.path.isdir(p):
+            shutil.rmtree(p)
+        os.mkdir(p, 0777)
+
+    # this is ugly, but the ncalrpcdir needs exactly 0755
+    # otherwise tests fail.
+    mask = os.umask(0022)
+
+    for n in ["ncalrpcdir", "ncalrpcdir/np"]:
+        p = os.path.join(clientdir, n)
+        if os.path.isdir(p):
+            shutil.rmtree(p)
+        os.mkdir(p, 0777)
+    os.umask(mask)
+
+    settings = {
+        "netbios name": "client",
+        "private dir": os.path.join(clientdir, "private"),
+        "lock dir": os.path.join(clientdir, "lockdir"),
+        "state directory": os.path.join(clientdir, "statedir"),
+        "cache directory": os.path.join(clientdir, "cachedir"),
+        "ncalrpc dir": os.path.join(clientdir, "ncalrpcdir"),
+        "name resolve order": "file bcast",
+        "panic action": os.path.join(os.path.dirname(__file__), "gdb_backtrace \%d"),
+        "max xmit": "32K",
+        "notify:inotify": "false",
+        "ldb:nosync": "true",
+        "system:anonymous": "true",
+        "client lanman auth": "Yes",
+        "log level": "1",
+        "torture:basedir": clientdir,
+        # We don't want to pass our self-tests if the PAC code is wrong
+        "gensec:require_pac": "true",
+        "resolv:host file": os.path.join(prefix_abs, "dns_host_file"),
+        # We don't want to run 'speed' tests for very long
+        "torture:timelimit": "1",
+        }
+
+    if "DOMAIN" in vars:
+        settings["workgroup"] = vars["DOMAIN"]
+    if "REALM" in vars:
+        settings["realm"] = vars["REALM"]
+    if opts.socket_wrapper:
+        settings["interfaces"] = interfaces
+
+    f = open(conffile, 'w')
+    try:
+        f.write("[global]\n")
+        for item in settings.iteritems():
+            f.write("\t%s = %s\n" % item)
+    finally:
+        f.close()
+
+
diff --git a/selftest/run.py b/selftest/run.py
new file mode 100644
index 0000000..20ede65
--- /dev/null
+++ b/selftest/run.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python -u
+# Bootstrap Samba and run a number of tests against it.
+# Copyright (C) 2012 Jelmer Vernooij <jelmer at samba.org>
+
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import os
+import tempfile
+import warnings
+
+# expand strings from %ENV
+def expand_environment_strings(s, vars):
+    # we use a reverse sort so we do the longer ones first
+    for k in sorted(vars.keys(), reverse=True):
+        v = vars[k]
+        s = s.replace("$%s" % k, v)
+    return s
+
+
+def expand_command_list(cmd):
+    if not "$LISTOPT" in cmd:
+        return None
+    return cmd.replace("$LISTOPT", "--list")
+
+
+def expand_command_run(cmd, supports_loadfile, supports_idlist, subtests=None):
+    """Expand a test command.
+
+    :param cmd: Command to expand
+    :param supports_loadfile: Whether command supports loadfile
+    :param supports_idlist: Whether the command supports running specific
+        subtests
+    :param subtests: List of subtests to run - None for all subtests
+    :return: Tuple with command to run and temporary file to remove after
+        running (or None)
+    """
+    # Generate a file with the individual tests to run, if the
+    # test runner for this test suite supports it.
+    if subtests is None:
+        return (cmd.replace("$LOADLIST", ""), None)
+    if supports_loadfile:
+        (fd, listid_file) = tempfile.mkstemp()
+        f = os.fdopen(fd, 'w')
+        try:
+            for test in subtests:
+                f.write(test+"\n")
+        finally:
+            f.close()
+        return (
+            cmd.replace("$LOADLIST", "--load-list=%s" % listid_file),
+            listid_file)
+    elif supports_idlist:
+        cmd += " " + " ".join(subtests)
+        return (cmd, None)
+    else:
+        warnings.warn(
+            "Running subtests requested, but command does not support "
+            "this.")
+        return (cmd, None)
+
+
+def exported_envvars_str(vars, names):
+    out = ""
+    for n in names:
+        if not n in vars:
+            continue
+        out += "%s=%s\n" % (n, vars[n])
+    return out
diff --git a/selftest/selftest.py b/selftest/selftest.py
index e619515..26c409a 100755
--- a/selftest/selftest.py
+++ b/selftest/selftest.py
@@ -23,10 +23,8 @@ import iso8601
 import os
 import sys
 import signal
-import shutil
 import subprocess
 import subunit
-import tempfile
 import traceback
 import warnings
 
@@ -39,6 +37,13 @@ from selftest import (
     subunithelper,
     testlist,
     )
+from selftest.client import write_clientconf
+from selftest.run import (
+    expand_environment_strings,
+    expand_command_list,
+    expand_command_run,
+    exported_envvars_str,
+    )
 from selftest.target import (
     EnvironmentManager,
     NoneTarget,
@@ -118,15 +123,6 @@ def cleanup_pcap(pcap_file, exit_code):
     os.unlink(pcap_file)
 
 
-# expand strings from %ENV
-def expand_environment_strings(s):
-    # we use a reverse sort so we do the longer ones first
-    for k in sorted(os.environ.keys(), reverse=True):
-        v = os.environ[k]
-        s = s.replace("$%s" % k, v)
-    return s
-
-
 def run_testsuite(envname, name, cmd):
     """Run a single testsuite.
 
@@ -156,7 +152,7 @@ def run_testsuite(envname, name, cmd):
         sys.stdout.write("envlog: %s\n" % envlog)
 
     sys.stdout.write("command: %s\n" % cmd)
-    sys.stdout.write("expanded command: %s\n" % expand_environment_strings(cmd))
+    sys.stdout.write("expanded command: %s\n" % expand_environment_strings(cmd, os.environ))
 
     if exitcode == 0:
         subunit_ops.end_testsuite(name, "success")
@@ -328,65 +324,6 @@ clientdir = os.path.join(prefix_abs, "client")
 conffile = os.path.join(clientdir, "client.conf")
 os.environ["SMB_CONF_PATH"] = conffile
 
-def write_clientconf(conffile, clientdir, vars):
-    if not os.path.isdir(clientdir):
-        os.mkdir(clientdir, 0777)
-
-    for n in ["private", "lockdir", "statedir", "cachedir"]:
-        p = os.path.join(clientdir, n)
-        if os.path.isdir(p):
-            shutil.rmtree(p)
-        os.mkdir(p, 0777)
-
-    # this is ugly, but the ncalrpcdir needs exactly 0755
-    # otherwise tests fail.
-    mask = os.umask(0022)
-
-    for n in ["ncalrpcdir", "ncalrpcdir/np"]:
-        p = os.path.join(clientdir, n)
-        if os.path.isdir(p):
-            shutil.rmtree(p)
-        os.mkdir(p, 0777)
-    os.umask(mask)
-
-    settings = {
-        "netbios name": "client",
-        "private dir": os.path.join(clientdir, "private"),
-        "lock dir": os.path.join(clientdir, "lockdir"),
-        "state directory": os.path.join(clientdir, "statedir"),
-        "cache directory": os.path.join(clientdir, "cachedir"),
-        "ncalrpc dir": os.path.join(clientdir, "ncalrpcdir"),
-        "name resolve order": "file bcast",
-        "panic action": os.path.join(os.path.dirname(__file__), "gdb_backtrace \%d"),
-        "max xmit": "32K",
-        "notify:inotify": "false",
-        "ldb:nosync": "true",
-        "system:anonymous": "true",
-        "client lanman auth": "Yes",
-        "log level": "1",
-        "torture:basedir": clientdir,
-        # We don't want to pass our self-tests if the PAC code is wrong
-        "gensec:require_pac": "true",
-        "resolv:host file": os.path.join(prefix_abs, "dns_host_file"),
-        # We don't want to run 'speed' tests for very long
-        "torture:timelimit": "1",
-        }
-
-    if "DOMAIN" in vars:
-        settings["workgroup"] = vars["DOMAIN"]
-    if "REALM" in vars:
-        settings["realm"] = vars["REALM"]
-    if opts.socket_wrapper:
-        settings["interfaces"] = interfaces
-
-    f = open(conffile, 'w')
-    try:
-        f.write("[global]\n")
-        for item in settings.iteritems():
-            f.write("\t%s = %s\n" % item)
-    finally:
-        f.close()
-
 todo = []
 
 if not opts.testlist:
@@ -407,31 +344,22 @@ else:
 os.environ["SELFTEST_MAXTIME"] = str(torture_maxtime)
 
 
-def open_file_or_pipe(path, mode):
-    if path.endswith("|"):
-        return os.popen(path[:-1], mode)
-    return open(path, mode)
-
 available = []
 for fn in opts.testlist:
-    inf = open_file_or_pipe(fn, 'r')
-    try:
-        for testsuite in testlist.read_testlist(inf, sys.stdout):
-            if not testlist.should_run_test(tests, testsuite):
-                continue
-            name = testsuite[0]
-            if includes is not None and testlist.find_in_list(includes, name) is not None:
-                continue
-            available.append(testsuite)
-    finally:
-        inf.close()
+    for testsuite in testlist.read_testlist_file(fn):
+        if not testlist.should_run_test(tests, testsuite):
+            continue
+        name = testsuite[0]
+        if (includes is not None and
+            testlist.find_in_list(includes, name) is not None):
+            continue
+        available.append(testsuite)
 
 if opts.load_list:
     restricted_mgr = testlist.RestrictedTestManager.from_path(opts.load_list)
 else:
     restricted_mgr = None
 
-
 for testsuite in available:
     name = testsuite[0]
     skipreason = skip(name)
@@ -510,17 +438,6 @@ exported_envvars = [
     "LOCAL_PATH"
 ]
 
-def exported_envvars_str(testenv_vars):
-    out = ""
-
-    for n in exported_envvars:
-        if not n in testenv_vars:
-            continue
-        out += "%s=%s\n" % (n, testenv_vars[n])
-
-    return out
-
-
 def switch_env(name, prefix):
     if ":" in name:
         (envname, option) = name.split(":", 1)
@@ -564,7 +481,7 @@ if opts.testenv:
     os.environ["PIDDIR"] = testenv_vars["PIDDIR"]
     os.environ["ENVNAME"] = testenv_name
 
-    envvarstr = exported_envvars_str(testenv_vars)
+    envvarstr = exported_envvars_str(testenv_vars, exported_envvars)
 
     term = os.environ.get("TERMINAL", "xterm -e")
     cmd = """'echo -e "
@@ -585,12 +502,11 @@ $envvarstr
     env_manager.teardown_env(testenv_name)
 elif opts.list:
     for (name, envname, cmd, supports_loadfile, supports_idlist, subtests) in todo:
-        if not "$LISTOPT" in cmd:
+        cmd = expand_command_list(cmd)
+        if cmd is None:
             warnings.warn("Unable to list tests in %s" % name)
             continue
 
-        cmd = cmd.replace("$LISTOPT", "--list")
-
         exitcode = subprocess.call(cmd, shell=True)
 
         if exitcode != 0:
@@ -612,24 +528,14 @@ else:
                 "unable to set up environment %s: %s" % (envname, e))
             continue
 
-        # Generate a file with the individual tests to run, if the
-        # test runner for this test suite supports it.
-        if subtests is not None:
-            if supports_loadfile:
-                (fd, listid_file) = tempfile.mkstemp()
-                # FIXME: Remove tempfile afterwards
-                f = os.fdopen(fd)
-                try:
-                    for test in subtests:
-                        f.write(test+"\n")
-                finally:
-                    f.close()
-                cmd = cmd.replace("$LOADLIST", "--load-list=%s" % listid_file)
-            elif supports_idlist:
-                cmd += " ".join(subtests)
+        cmd, tmpf = expand_command_run(cmd, supports_loadfile, supports_idlist,
+            subtests)
 
         run_testsuite(envname, name, cmd)
 
+        if tmpf is not None:
+            os.remove(tmpf)
+
         if opts.resetup_environment:
             env_manager.teardown_env(envname)
 
diff --git a/selftest/testlist.py b/selftest/testlist.py
index 441dda7..5102f42 100644
--- a/selftest/testlist.py
+++ b/selftest/testlist.py
@@ -21,7 +21,9 @@
 
 __all__ = ['find_in_list', 'read_test_regexes', 'read_testlist']
 
+import os
 import re
+import sys
 
 def find_in_list(list, fullname):
     """Find test in list.
@@ -133,3 +135,34 @@ class RestrictedTestManager(object):
         :return: Iterator over test list entries that were not used.
         """
         return iter(self.unused)
+
+
+def open_file_or_pipe(path, mode):
+    """Open a file or pipe.
+
+    :param path: Path to open; if it ends with | it is assumed to be a
+        command to run
+    :param mode: Mode with which to open it
+    :return: File-like object
+    """
+    if path.endswith("|"):
+        return os.popen(path[:-1], mode)
+    return open(path, mode)
+
+
+def read_testlist_file(fn, outf=None):
+    """Read testlist file.
+
+    :param fn: Path to read (assumed to be a command to run if it ends with |)
+    :param outf: File-like object to pass non-test data through to
+        (defaults to stdout)
+    :return: Iterator over test suites (see read_testlist)
+    """
+    if outf is None:
+        outf = sys.stdout
+    inf = open_file_or_pipe(fn, 'r')
+    try:
+        for testsuite in read_testlist(inf, outf):
+            yield testsuite
+    finally:
+        inf.close()
diff --git a/selftest/tests/__init__.py b/selftest/tests/__init__.py
index 3de290c..5ff1f6b 100644
--- a/selftest/tests/__init__.py
+++ b/selftest/tests/__init__.py
@@ -25,7 +25,7 @@ import unittest
 
 def test_suite():
     result = unittest.TestSuite()
-    names = ['socket_wrapper', 'target', 'testlist']
+    names = ['socket_wrapper', 'target', 'testlist', 'run']
     module_names = ['selftest.tests.test_' + name for name in names]
     loader = unittest.TestLoader()
     result.addTests(loader.loadTestsFromNames(module_names))
diff --git a/selftest/tests/test_run.py b/selftest/tests/test_run.py
new file mode 100644
index 0000000..894ceaa
--- /dev/null
+++ b/selftest/tests/test_run.py
@@ -0,0 +1,94 @@
+# test_run.py -- Tests for selftest.run
+# Copyright (C) 2012 Jelmer Vernooij <jelmer at samba.org>
+#
+# 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; version 3
+# of the License or (at your option) any later version of
+# the License.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+
+"""Tests for selftest.run."""
+
+import os
+
+from selftest.run import (
+    expand_command_list,
+    expand_environment_strings,
+    expand_command_run,
+    exported_envvars_str,
+    )


-- 
Samba Shared Repository


More information about the samba-cvs mailing list