1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

selftest: updated docs.py script

The script now checks the parameter defaults against the documentation by using
the output of testparm and samba-tool testparm.

It now also uses the ElementTree xml library.

Change-Id: I2657c8c56a8c8383735e659dc9f636b4c5ab460b
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>

Autobuild-User(master): Michael Adam <obnox@samba.org>
Autobuild-Date(master): Fri Jan 31 23:22:09 CET 2014 on sn-devel-104
This commit is contained in:
Garming Sam 2013-12-24 15:33:42 +13:00 committed by Michael Adam
parent 2c86758b04
commit fca80dccf8

View File

@ -21,54 +21,42 @@
import samba import samba
import samba.tests import samba.tests
from samba.tests import TestSkipped from samba.tests import TestSkipped, TestCaseInTempDir
import errno import errno
import os import os
import re import re
import subprocess import subprocess
import xml.etree.ElementTree as ET
class TestCase(samba.tests.TestCaseInTempDir):
class TestCase(samba.tests.TestCase):
def _format_message(self, parameters, message): def _format_message(self, parameters, message):
parameters = list(parameters) parameters = list(parameters)
parameters.sort() parameters.sort()
return message + '\n\n %s' % ('\n '.join(parameters)) return message + '\n\n %s' % ('\n '.join(parameters))
class NoXsltProc(Exception):
def __init__(self):
Exception.__init__(self, "'xsltproc' is not installed")
def get_documented_parameters(sourcedir): def get_documented_parameters(sourcedir):
path = os.path.join(sourcedir, "bin", "default", "docs-xml", "smbdotconf") path = os.path.join(sourcedir, "bin", "default", "docs-xml", "smbdotconf")
if not os.path.exists(os.path.join(path, "parameters.all.xml")): if not os.path.exists(os.path.join(path, "parameters.all.xml")):
raise Exception("Unable to find parameters.all.xml") raise Exception("Unable to find parameters.all.xml")
try: try:
p = subprocess.Popen( p = open(os.path.join(path, "parameters.all.xml"), 'r')
["xsltproc", "--xinclude", "--param", "smb.context", "ALL", os.path.join(sourcedir, "docs-xml", "smbdotconf", "generate-context.xsl"), "parameters.all.xml"], except IOError, e:
stderr=subprocess.STDOUT, stdout=subprocess.PIPE, raise Exception("Error opening parameters file")
cwd=path) out = p.read()
except OSError, e:
if e.errno == errno.ENOENT: root = ET.fromstring(out)
raise NoXsltProc() for parameter in root:
raise name = parameter.attrib.get('name')
out, err = p.communicate() if parameter.attrib.get('removed') == "1":
assert p.returncode == 0, "returncode was %r" % p.returncode continue
for l in out.splitlines(): yield name
m = re.match('<samba:parameter .*?name="([^"]*?)"', l) syn = parameter.findall('synonym')
if "removed=\"1\"" in l: if syn is not None:
continue for sy in syn:
if m: yield sy.text
name = m.group(1) p.close()
yield name
m = re.match('.*<synonym>(.*)</synonym>.*', l)
if m:
name = m.group(1)
yield name
def get_implementation_parameters(sourcedir): def get_implementation_parameters(sourcedir):
@ -96,15 +84,69 @@ def get_implementation_parameters(sourcedir):
finally: finally:
f.close() f.close()
def get_default_triples(sourcedir):
path = os.path.join(sourcedir, "bin", "default", "docs-xml", "smbdotconf")
if not os.path.exists(os.path.join(path, "parameters.all.xml")):
raise Exception("Unable to find parameters.all.xml")
try:
p = open(os.path.join(path, "parameters.all.xml"), 'r')
except IOError, e:
raise Exception("Error opening parameters file")
out = p.read()
root = ET.fromstring(out)
for parameter in root:
name = parameter.attrib.get("name")
values = parameter.findall("value")
defaults = []
for value in values:
if value.attrib.get("type") == "default":
defaults.append(value)
if len(defaults) == 0:
continue
elif len(defaults) > 1:
raise Exception("More than one default found for parameter %s" % name)
default_text = defaults[0].text
if default_text is None:
default_text = ""
context = parameter.attrib.get("context")
yield name, default_text, context
p.close()
class SmbDotConfTests(TestCase): class SmbDotConfTests(TestCase):
# defines the cases where the defaults may differ from the documentation
special_cases = set(['log level', 'path', 'ldapsam:trusted', 'spoolss: architecture',
'share:fake_fscaps', 'ldapsam:editposix', 'rpc_daemon:DAEMON',
'rpc_server:SERVER', 'panic action', 'homedir map', 'NIS homedir',
'server string', 'netbios name', 'socket options', 'use mmap',
'ctdbd socket', 'printing', 'printcap name', 'queueresume command',
'queuepause command','lpresume command', 'lppause command',
'lprm command', 'lpq command', 'print command', 'template homedir'])
def setUp(self):
super(SmbDotConfTests, self).setUp()
# create a minimal smb.conf file for testparm
self.smbconf = os.path.join(self.tempdir, "paramtestsmb.conf")
f = open(self.smbconf, 'w')
try:
f.write("""
[test]
path = /
""")
finally:
f.close()
def tearDown(self):
super(SmbDotConfTests, self).tearDown()
os.unlink(self.smbconf)
def test_unknown(self): def test_unknown(self):
topdir = samba.source_tree_topdir() topdir = os.path.abspath(samba.source_tree_topdir())
try: try:
documented = set(get_documented_parameters(topdir)) documented = set(get_documented_parameters(topdir))
except NoXsltProc: except e:
raise TestSkipped("'xsltproc' is missing, unable to load parameters") self.fail("Unable to load parameters")
parameters = set(get_implementation_parameters(topdir)) parameters = set(get_implementation_parameters(topdir))
# Filter out parametric options, since we can't find them in the parm # Filter out parametric options, since we can't find them in the parm
# table # table
@ -115,13 +157,52 @@ class SmbDotConfTests(TestCase):
"Parameters that are documented but not in the implementation:")) "Parameters that are documented but not in the implementation:"))
def test_undocumented(self): def test_undocumented(self):
topdir = samba.source_tree_topdir() topdir = os.path.abspath(samba.source_tree_topdir())
try: try:
documented = set(get_documented_parameters(topdir)) documented = set(get_documented_parameters(topdir))
except NoXsltProc: except:
raise TestSkipped("'xsltproc' is missing, unable to load parameters") self.fail("Unable to load parameters")
parameters = set(get_implementation_parameters(topdir)) parameters = set(get_implementation_parameters(topdir))
undocumented = parameters.difference(documented) undocumented = parameters.difference(documented)
if len(undocumented) > 0: if len(undocumented) > 0:
self.fail(self._format_message(undocumented, self.fail(self._format_message(undocumented,
"Parameters that are in the implementation but undocumented:")) "Parameters that are in the implementation but undocumented:"))
def test_default_s3(self):
self._test_default(['bin/testparm'])
def test_default_s4(self):
self._test_default(['bin/samba-tool', 'testparm'])
def _test_default(self, program):
topdir = os.path.abspath(samba.source_tree_topdir())
try:
defaults = set(get_default_triples(topdir))
except:
self.fail("Unable to load parameters")
bindir = os.path.join(topdir, "bin")
failset = set()
count = 0
for triple in defaults:
param, default, context = triple
if param in self.special_cases:
continue
section = None
if context == "G":
section = "global"
elif context == "S":
section = "test"
else:
self.fail("%s has no valid context" % param)
p = subprocess.Popen(program + ["-s", self.smbconf,
"--section-name", section, "--parameter-name", param],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=topdir).communicate()
if p[0].upper().strip() != default.upper():
if not (p[0].upper().strip() == "" and default == '""'):
doc_triple = "%s\n Expected: %s" % (param, default)
failset.add("%s\n Got: %s" % (doc_triple, p[0].upper().strip()))
if len(failset) > 0:
self.fail(self._format_message(failset,
"Parameters that do not have matching defaults:"))