summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-19 23:27:31 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:51:56 +0100
commit86f91db7d5c84526b3fbd4369d7a56dc0f057b4c (patch)
tree276fae99b2d92b8fb0f688ac8f04da3d216804fb /source4/scripting/python
parent595ec370da471116b35464dc65d2962f28380d74 (diff)
downloadsamba-86f91db7d5c84526b3fbd4369d7a56dc0f057b4c.tar.gz
samba-86f91db7d5c84526b3fbd4369d7a56dc0f057b4c.tar.bz2
samba-86f91db7d5c84526b3fbd4369d7a56dc0f057b4c.zip
r26536: More tests for provisioning code.
(This used to be commit 43c8bfeedf06ce806c524a28fa72c643f6db60f4)
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/samba/__init__.py4
-rw-r--r--source4/scripting/python/samba/provision.py6
-rw-r--r--source4/scripting/python/samba/tests/__init__.py18
-rw-r--r--source4/scripting/python/samba/tests/provision.py17
-rw-r--r--source4/scripting/python/samba/upgrade.py18
5 files changed, 39 insertions, 24 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 9ac283e660..d185464a58 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -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."""
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index c9cb457b4a..f3fc138e6b 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -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)
diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py
index 0808469907..45588ecb5a 100644
--- a/source4/scripting/python/samba/tests/__init__.py
+++ b/source4/scripting/python/samba/tests/__init__.py
@@ -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"))
+
diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py
index 5edfe79084..c8bd99283b 100644
--- a/source4/scripting/python/samba/tests/provision.py
+++ b/source4/scripting/python/samba/tests/provision.py
@@ -17,13 +17,22 @@
# 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)
diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py
index 783cc008d5..4521d4604d 100644
--- a/source4/scripting/python/samba/upgrade.py
+++ b/source4/scripting/python/samba/upgrade.py
@@ -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)