summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-25 16:36:44 -0600
committerStefan Metzmacher <metze@samba.org>2007-12-26 11:57:08 -0600
commit533cc583ed20efdfd6bee60f86d16fef3942898b (patch)
treeb89f9b0988d38e9995a71ff8d14ea023cc37783a /source4/scripting
parentcea31e32163fe639be72b3f4dfca1362c93b5576 (diff)
downloadsamba-533cc583ed20efdfd6bee60f86d16fef3942898b.tar.gz
samba-533cc583ed20efdfd6bee60f86d16fef3942898b.tar.bz2
samba-533cc583ed20efdfd6bee60f86d16fef3942898b.zip
r26596: Fixed upgrade.py.
Added blackbox tests for provision and upgrade Python scripts. Clean up temporary files created by the Python tests. (This used to be commit 2227fb6df62240cae64d27a1920d878316f819fc)
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/samba/__init__.py6
-rw-r--r--source4/scripting/python/samba/provision.py6
-rw-r--r--source4/scripting/python/samba/tests/__init__.py11
-rw-r--r--source4/scripting/python/samba/tests/provision.py10
-rw-r--r--source4/scripting/python/samba/upgrade.py26
5 files changed, 30 insertions, 29 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 5b34534133..359457d815 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -164,9 +164,9 @@ class Ldb(ldb.Ldb):
self.add(msg)
def modify_ldif(self, ldif):
- for (changetype, msg) in ldb.parse_ldif(data):
- assert changetype == CHANGETYPE_MODIFY
- ldb.modify(msg)
+ for (changetype, msg) in self.parse_ldif(ldif):
+ assert changetype == ldb.CHANGETYPE_MODIFY
+ self.modify(msg)
def substitute_var(text, values):
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index a4e6c6a214..c4a3bb7fd6 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -95,7 +95,7 @@ def setup_add_ldif(ldb, ldif_path, subst_vars=None):
assert "${" not in data
- ldb.load_ldif_add(data)
+ ldb.add_ldif(data)
def setup_modify_ldif(ldb, ldif_path, substvars=None):
@@ -140,7 +140,7 @@ def setup_file(template, fname, substvars):
open(f, 'w').write(data)
-def provision_default_paths(lp, dnsdomain):
+def provision_paths_from_lp(lp, dnsdomain):
"""Set the default paths for provisioning.
:param lp: Loadparm context.
@@ -605,7 +605,7 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
realm = lp.get("realm")
else:
if lp.get("realm").upper() != realm.upper():
- raise Error("realm '%s' in smb.conf must match chosen realm '%s'\n" %
+ raise Exception("realm '%s' in smb.conf must match chosen realm '%s'\n" %
(lp.get("realm"), realm))
assert realm is not None
diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py
index 5885a3b507..5e1ff87c2b 100644
--- a/source4/scripting/python/samba/tests/__init__.py
+++ b/source4/scripting/python/samba/tests/__init__.py
@@ -67,7 +67,12 @@ class SubstituteVarTestCase(unittest.TestCase):
class LdbExtensionTests(TestCaseInTempDir):
def test_searchone(self):
- l = samba.Ldb(self.tempdir + "/searchone.ldb")
- l.add({"dn": "foo=dc", "bar": "bla"})
- self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
+ path = self.tempdir + "/searchone.ldb"
+ l = samba.Ldb(path)
+ try:
+ l.add({"dn": "foo=dc", "bar": "bla"})
+ self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
+ finally:
+ del l
+ os.unlink(path)
diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py
index bf7182dbd3..f5a0339c1f 100644
--- a/source4/scripting/python/samba/tests/provision.py
+++ b/source4/scripting/python/samba/tests/provision.py
@@ -29,10 +29,14 @@ def setup_path(file):
class ProvisionTestCase(samba.tests.TestCaseInTempDir):
def test_setup_secretsdb(self):
- ldb = setup_secretsdb(os.path.join(self.tempdir, "secrets.ldb"),
- setup_path, None, None, None)
- self.assertEquals("LSA Secrets",
+ path = os.path.join(self.tempdir, "secrets.ldb")
+ ldb = setup_secretsdb(path, setup_path, None, None, None)
+ try:
+ self.assertEquals("LSA Secrets",
ldb.searchone(Dn(ldb, "CN=LSA Secrets"), "CN"))
+ finally:
+ del ldb
+ os.unlink(path)
class Disabled:
diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py
index c13351bc63..05a63d9326 100644
--- a/source4/scripting/python/samba/upgrade.py
+++ b/source4/scripting/python/samba/upgrade.py
@@ -8,7 +8,6 @@
"""Support code for upgrading from Samba 3 to Samba 4."""
from provision import findnss, provision
-import provision
import grp
import pwd
import uuid
@@ -255,7 +254,7 @@ maxVersion: %llu
return ldif
-def upgrade_provision(samba3, setup_dir, message, credentials, session_info, paths):
+def upgrade_provision(samba3, setup_dir, message, credentials, session_info, lp, paths):
oldconf = samba3.get_conf()
if oldconf.get("domain logons") == "True":
@@ -266,7 +265,11 @@ def upgrade_provision(samba3, setup_dir, message, credentials, session_info, pat
else:
serverrole = "member server"
+ lp.set("server role", serverrole)
domainname = oldconf.get("workgroup")
+ if domainname:
+ domainname = str(domainname)
+ lp.set("workgroup", domainname)
realm = oldconf.get("realm")
netbiosname = oldconf.get("netbios name")
@@ -279,18 +282,19 @@ def upgrade_provision(samba3, setup_dir, message, credentials, session_info, pat
if realm is None:
realm = domainname.lower()
message("No realm specified in smb.conf file, assuming '%s'\n" % realm)
+ lp.set("realm", realm)
domainguid = secrets_db.get_domain_guid(domainname)
- domainsid = secrets_db.get_sid(domainsid)
+ domainsid = secrets_db.get_sid(domainname)
if domainsid is None:
message("Can't find domain secrets for '%s'; using random SID\n" % domainname)
if netbiosname is not None:
machinepass = secrets_db.get_machine_password(netbiosname)
else:
- netbiosname = None
+ machinepass = None
- provision(lp, setup_dir, message, blank=True, paths=path, session_info=session_info,
+ provision(lp=lp, setup_dir=setup_dir, message=message, blank=True, ldapbackend=None, paths=paths, session_info=session_info,
credentials=credentials, realm=realm, domain=domainname,
domainsid=domainsid, domainguid=domainguid, machinepass=machinepass, serverrole=serverrole)
@@ -500,18 +504,6 @@ data: %d
return ret
-def upgrade_verify(subobj, samba3, paths, message):
- message("Verifying account policies")
-
- samldb = Ldb(paths.samdb)
-
- for account in samba3.samaccounts:
- msg = samldb.search("(&(sAMAccountName=" + account.nt_username + ")(objectclass=user))")
- assert(len(msg) >= 1)
-
- # FIXME
-
-
def enable_samba3sam(samdb):
samdb.modify("""