r26536: More tests for provisioning code.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 19 Dec 2007 22:27:31 +0000 (23:27 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:51:56 +0000 (05:51 +0100)
source/scripting/python/samba/__init__.py
source/scripting/python/samba/provision.py
source/scripting/python/samba/tests/__init__.py
source/scripting/python/samba/tests/provision.py
source/scripting/python/samba/upgrade.py
source/selftest/samba4_tests.sh

index 9ac283e660788c0cd91f377b9d5b89786a0a7deb..d185464a58998f65de302acbeca7ec9c803b1a12 100644 (file)
@@ -92,7 +92,9 @@ class Ldb(ldb.Ldb):
         res = self.search(basedn, scope, expression, [attribute])
         if len(res) != 1 or res[0][attribute] is None:
             return None
-        return res[0][attribute]
+        values = set(res[0][attribute])
+        assert len(values) == 1
+        return values.pop()
 
     def erase(self):
         """Erase an ldb, removing all records."""
index c9cb457b4a5e1c57285e49bdb1e08eb9faec1ca1..f3fc138e6bb3df7fb200daedb2d8d46dfa7d4fbd 100644 (file)
@@ -73,11 +73,6 @@ def findnss(nssfn, *names):
     raise Exception("Unable to find user/group for %s" % arguments[1])
 
 
-def hostname():
-    """return first part of hostname."""
-    return gethostname().split(".")[0]
-
-
 def open_ldb(session_info, credentials, lp, dbname):
     assert session_info is not None
     try:
@@ -742,7 +737,6 @@ def provision_dns(setup_dir, paths, session_info,
         })
 
 
-
 def provision_ldapbase(setup_dir, message, paths):
     """Write out a DNS zone file, from the info in the current database."""
     message("Setting up LDAP base entry: %s" % domaindn)
index 080846990728db268cdc9092a2a880b1d0412a0a..45588ecb5a4872055f3e26e13fc457ab7e794d4c 100644 (file)
@@ -20,6 +20,7 @@
 import os
 import ldb
 import samba
+import tempfile
 import unittest
 
 class LdbTestCase(unittest.TestCase):
@@ -35,6 +36,15 @@ class LdbTestCase(unittest.TestCase):
         self.ldb = samba.Ldb(self.filename)
 
 
+class TestCaseInTempDir(unittest.TestCase):
+    def setUp(self):
+        super(TestCaseInTempDir, self).setUp()
+        self.tempdir = tempfile.mkdtemp()
+
+    def tearDown(self):
+        super(TestCaseInTempDir, self).tearDown()
+
+
 class SubstituteVarTestCase(unittest.TestCase):
     def test_empty(self):
         self.assertEquals("", samba.substitute_var("", {}))
@@ -52,3 +62,11 @@ class SubstituteVarTestCase(unittest.TestCase):
     def test_unknown_var(self):
         self.assertEquals("foo ${bla} gsff", 
                 samba.substitute_var("foo ${bla} gsff", {"bar": "bla"}))
+
+
+class LdbExtensionTests(TestCaseInTempDir):
+    def test_searchone(self):
+        l = samba.Ldb(self.tempdir + "/searchone.ldb")
+        l.add({"dn": ldb.Dn(l, "foo=dc"), "bar": "bla"})
+        self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
+
index 5edfe79084a0c25351983e9c459d9d1b72b85388..c8bd99283b781d2494ac9e21dd79c60fe57d5291 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import unittest
-import samba.provision
+import os
+from samba.provision import setup_secretsdb
+import samba.tests
+from ldb import Dn
 
-class ProvisionTestCase(unittest.TestCase):
+setup_dir = "setup"
+
+class ProvisionTestCase(samba.tests.TestCaseInTempDir):
     def test_setup_secretsdb(self):
-        raise NotImplementedError(self.test_setup_secretsdb)
+        ldb = setup_secretsdb(os.path.join(self.tempdir, "secrets.ldb"), 
+                              setup_dir, None, None, None)
+        self.assertEquals("LSA Secrets",
+                 ldb.searchone(Dn(ldb, "CN=LSA Secrets"), "CN"))
+
 
+class Disabled:
     def test_setup_templatesdb(self):
         raise NotImplementedError(self.test_setup_templatesdb)
 
index 783cc008d5bc8479e78c64c6638645c56d80320e..4521d4604d6dd9ba51f645511d2a81d08ff7d217 100644 (file)
@@ -14,7 +14,10 @@ import pwd
 import uuid
 
 def regkey_to_dn(name):
-    """Convert a registry key to a DN."""
+    """Convert a registry key to a DN.
+    
+    :name: The registry key name.
+    :return: A matching DN."""
     dn = "hive=NONE"
 
     if name == "":
@@ -253,8 +256,6 @@ maxVersion: %llu
     return ldif
 
 def upgrade_provision(lp, samba3):
-    subobj = Object()
-
     domainname = samba3.configuration.get("workgroup")
     
     if domainname is None:
@@ -272,13 +273,7 @@ def upgrade_provision(lp, samba3):
 
     subobj.realm        = realm
     subobj.domain       = domainname
-    subobj.hostname     = hostname()
 
-    assert subobj.realm is not None
-    assert subobj.domain is not None
-    assert subobj.hostname is not None
-
-    subobj.HOSTIP       = hostip()
     if domsec is not None:
         subobj.DOMAINGUID   = domsec.guid
         subobj.DOMAINSID    = domsec.sid
@@ -288,10 +283,7 @@ def upgrade_provision(lp, samba3):
         subobj.DOMAINSID = randsid()
     
     if hostsec:
-        subobj.HOSTGUID     = hostsec.guid
-    else:
-        subobj.HOSTGUID = uuid.random()
-    subobj.invocationid = uuid.random()
+        hostguid = hostsec.guid
     subobj.krbtgtpass   = randpass(12)
     subobj.machinepass  = randpass(12)
     subobj.adminpass    = randpass(12)
index 268a3246e5a660b48cafbdf1c1a95062a689abfe..95baff2be7ac471c3dde23d6b4b205f3fe33a1db 100755 (executable)
@@ -296,4 +296,5 @@ then
        plantest "param.python" none PYTHONPATH=bin/python:scripting/python:param/tests scripting/bin/subunitrun bindings
        plantest "upgrade.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests.upgrade
        plantest "samba.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests
+       plantest "provision.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests.provision
 fi