mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
r26527: Start on tests for provision.
(This used to be commit 84ac6c6bbf
)
This commit is contained in:
committed by
Stefan Metzmacher
parent
80529722e3
commit
4e6ab64762
@ -129,8 +129,6 @@ def substitute_var(text, values):
|
|||||||
assert isinstance(value, str), "Value %r for %s is not a string" % (value, name)
|
assert isinstance(value, str), "Value %r for %s is not a string" % (value, name)
|
||||||
text = text.replace("${%s}" % name, value)
|
text = text.replace("${%s}" % name, value)
|
||||||
|
|
||||||
assert "${" not in text, text
|
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,18 +135,6 @@ def hostname():
|
|||||||
return gethostname().split(".")[0]
|
return gethostname().split(".")[0]
|
||||||
|
|
||||||
|
|
||||||
def ldb_delete(ldb):
|
|
||||||
"""Delete a LDB file.
|
|
||||||
|
|
||||||
This may be necessary if the ldb is in bad shape, possibly due to being
|
|
||||||
built from an incompatible previous version of the code, so delete it
|
|
||||||
completely.
|
|
||||||
"""
|
|
||||||
print "Deleting %s\n" % ldb.filename
|
|
||||||
os.unlink(ldb.filename)
|
|
||||||
ldb.connect(ldb.filename)
|
|
||||||
|
|
||||||
|
|
||||||
def open_ldb(session_info, credentials, lp, dbname):
|
def open_ldb(session_info, credentials, lp, dbname):
|
||||||
assert session_info is not None
|
assert session_info is not None
|
||||||
try:
|
try:
|
||||||
@ -176,6 +164,13 @@ def setup_add_ldif(ldb, setup_dir, ldif, subst_vars=None):
|
|||||||
|
|
||||||
|
|
||||||
def setup_modify_ldif(ldb, setup_dir, ldif, substvars=None):
|
def setup_modify_ldif(ldb, setup_dir, ldif, substvars=None):
|
||||||
|
"""Modify a ldb in the private dir.
|
||||||
|
|
||||||
|
:param ldb: LDB object.
|
||||||
|
:param setup_dir: Setup directory.
|
||||||
|
:param ldif: LDIF file path.
|
||||||
|
:param substvars: Optional dictionary with substitution variables.
|
||||||
|
"""
|
||||||
src = os.path.join(setup_dir, ldif)
|
src = os.path.join(setup_dir, ldif)
|
||||||
|
|
||||||
data = open(src, 'r').read()
|
data = open(src, 'r').read()
|
||||||
@ -199,19 +194,6 @@ def setup_ldb(ldb, setup_dir, ldif, subst_vars=None):
|
|||||||
ldb.transaction_commit()
|
ldb.transaction_commit()
|
||||||
|
|
||||||
|
|
||||||
def setup_ldb_modify(ldb, setup_dir, ldif, substvars=None):
|
|
||||||
"""Modify a ldb in the private dir."""
|
|
||||||
src = os.path.join(setup_dir, ldif)
|
|
||||||
|
|
||||||
data = open(src, 'r').read()
|
|
||||||
if substvars is not None:
|
|
||||||
data = substitute_var(data, substvars)
|
|
||||||
assert not "${" in data
|
|
||||||
|
|
||||||
for (changetype, msg) in ldb.parse_ldif(data):
|
|
||||||
ldb.modify(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_file(setup_dir, template, fname, substvars):
|
def setup_file(setup_dir, template, fname, substvars):
|
||||||
"""Setup a file in the private dir."""
|
"""Setup a file in the private dir."""
|
||||||
f = fname
|
f = fname
|
||||||
@ -328,7 +310,7 @@ def provision_become_dc(setup_dir, subobj, message, paths, lp, session_info,
|
|||||||
setup_samdb_rootdse(samdb, setup_dir, subobj)
|
setup_samdb_rootdse(samdb, setup_dir, subobj)
|
||||||
|
|
||||||
message("Erasing data from partitions")
|
message("Erasing data from partitions")
|
||||||
ldb_erase_partitions(subobj, message, samdb, None)
|
ldb_erase_partitions(subobj.domaindn, message, samdb, None)
|
||||||
|
|
||||||
message("Setting up %s indexes" % paths.samdb)
|
message("Setting up %s indexes" % paths.samdb)
|
||||||
setup_add_ldif(samdb, setup_dir, "provision_index.ldif")
|
setup_add_ldif(samdb, setup_dir, "provision_index.ldif")
|
||||||
@ -453,8 +435,7 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
smbconfsuffix = "member"
|
smbconfsuffix = "member"
|
||||||
else:
|
else:
|
||||||
assert "Invalid server role setting: %s" % lp.get("server role")
|
assert "Invalid server role setting: %s" % lp.get("server role")
|
||||||
setup_file(setup_dir, "provision.smb.conf.%s" % smbconfsuffix, paths.smbconf,
|
setup_file(setup_dir, "provision.smb.conf.%s" % smbconfsuffix, paths.smbconf)
|
||||||
None)
|
|
||||||
lp.reload()
|
lp.reload()
|
||||||
|
|
||||||
# only install a new shares config db if there is none
|
# only install a new shares config db if there is none
|
||||||
@ -462,7 +443,7 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
message("Setting up share.ldb")
|
message("Setting up share.ldb")
|
||||||
share_ldb = Ldb(paths.shareconf, session_info=session_info,
|
share_ldb = Ldb(paths.shareconf, session_info=session_info,
|
||||||
credentials=credentials, lp=lp)
|
credentials=credentials, lp=lp)
|
||||||
setup_ldb(share_ldb, setup_dir, "share.ldif", None)
|
setup_ldb(share_ldb, setup_dir, "share.ldif")
|
||||||
|
|
||||||
message("Setting up %s" % paths.secrets)
|
message("Setting up %s" % paths.secrets)
|
||||||
secrets_ldb = setup_secretsdb(paths.secrets, setup_dir, session_info=session_info,
|
secrets_ldb = setup_secretsdb(paths.secrets, setup_dir, session_info=session_info,
|
||||||
@ -497,7 +478,7 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
setup_samdb_rootdse(samdb, setup_dir, subobj)
|
setup_samdb_rootdse(samdb, setup_dir, subobj)
|
||||||
|
|
||||||
message("Erasing data from partitions")
|
message("Erasing data from partitions")
|
||||||
ldb_erase_partitions(subobj, message, samdb, ldapbackend)
|
ldb_erase_partitions(subobj.domaindn, message, samdb, ldapbackend)
|
||||||
except:
|
except:
|
||||||
samdb.transaction_cancel()
|
samdb.transaction_cancel()
|
||||||
raise
|
raise
|
||||||
@ -527,7 +508,7 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
else:
|
else:
|
||||||
domainguid_mod = ""
|
domainguid_mod = ""
|
||||||
|
|
||||||
setup_ldb_modify(samdb, setup_dir, "provision_basedn_modify.ldif", {
|
setup_modify_ldif(samdb, setup_dir, "provision_basedn_modify.ldif", {
|
||||||
"RDN_DC": subobj.rdn_dc,
|
"RDN_DC": subobj.rdn_dc,
|
||||||
"LDAPTIME": timestring(int(time.time())),
|
"LDAPTIME": timestring(int(time.time())),
|
||||||
"DOMAINSID": str(subobj.domainsid),
|
"DOMAINSID": str(subobj.domainsid),
|
||||||
@ -547,7 +528,7 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
"EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb",
|
"EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb",
|
||||||
})
|
})
|
||||||
message("Modifying configuration container")
|
message("Modifying configuration container")
|
||||||
setup_ldb_modify(samdb, setup_dir, "provision_configuration_basedn_modify.ldif", {
|
setup_modify_ldif(samdb, setup_dir, "provision_configuration_basedn_modify.ldif", {
|
||||||
"CONFIGDN": subobj.configdn,
|
"CONFIGDN": subobj.configdn,
|
||||||
"SCHEMADN": subobj.schemadn,
|
"SCHEMADN": subobj.schemadn,
|
||||||
})
|
})
|
||||||
@ -559,7 +540,7 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
"EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb"
|
"EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb"
|
||||||
})
|
})
|
||||||
message("Modifying schema container")
|
message("Modifying schema container")
|
||||||
setup_ldb_modify(samdb, setup_dir, "provision_schema_basedn_modify.ldif", {
|
setup_modify_ldif(samdb, setup_dir, "provision_schema_basedn_modify.ldif", {
|
||||||
"SCHEMADN": subobj.schemadn,
|
"SCHEMADN": subobj.schemadn,
|
||||||
"NETBIOSNAME": subobj.netbiosname,
|
"NETBIOSNAME": subobj.netbiosname,
|
||||||
"DEFAULTSITE": subobj.defaultsite,
|
"DEFAULTSITE": subobj.defaultsite,
|
||||||
@ -593,13 +574,13 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
|
|||||||
setup_add_ldif(samdb, setup_dir, "provision_users_add.ldif", {
|
setup_add_ldif(samdb, setup_dir, "provision_users_add.ldif", {
|
||||||
"DOMAINDN": subobj.domaindn})
|
"DOMAINDN": subobj.domaindn})
|
||||||
message("Modifying users container")
|
message("Modifying users container")
|
||||||
setup_ldb_modify(samdb, setup_dir, "provision_users_modify.ldif", {
|
setup_modify_ldif(samdb, setup_dir, "provision_users_modify.ldif", {
|
||||||
"DOMAINDN": subobj.domaindn})
|
"DOMAINDN": subobj.domaindn})
|
||||||
message("Adding computers container (permitted to fail)")
|
message("Adding computers container (permitted to fail)")
|
||||||
setup_add_ldif(samdb, setup_dir, "provision_computers_add.ldif", {
|
setup_add_ldif(samdb, setup_dir, "provision_computers_add.ldif", {
|
||||||
"DOMAINDN": subobj.domaindn})
|
"DOMAINDN": subobj.domaindn})
|
||||||
message("Modifying computers container")
|
message("Modifying computers container")
|
||||||
setup_ldb_modify(samdb, setup_dir, "provision_computers_modify.ldif", {
|
setup_modify_ldif(samdb, setup_dir, "provision_computers_modify.ldif", {
|
||||||
"DOMAINDN": subobj.domaindn})
|
"DOMAINDN": subobj.domaindn})
|
||||||
message("Setting up sam.ldb data")
|
message("Setting up sam.ldb data")
|
||||||
setup_add_ldif(samdb, setup_dir, "provision.ldif", {
|
setup_add_ldif(samdb, setup_dir, "provision.ldif", {
|
||||||
@ -807,7 +788,7 @@ def load_schema(setup_dir, samdb, subobj):
|
|||||||
samdb.attach_schema_from_ldif(head_data, schema_data)
|
samdb.attach_schema_from_ldif(head_data, schema_data)
|
||||||
|
|
||||||
|
|
||||||
def join_domain(domain, netbios_name, join_type, creds, message):
|
def join_domain(domain, netbios_name, join_type, creds):
|
||||||
ctx = NetContext(creds)
|
ctx = NetContext(creds)
|
||||||
joindom = object()
|
joindom = object()
|
||||||
joindom.domain = domain
|
joindom.domain = domain
|
||||||
@ -824,8 +805,7 @@ def vampire(domain, session_info, credentials, message):
|
|||||||
access to our local database (might be remote ldap)
|
access to our local database (might be remote ldap)
|
||||||
"""
|
"""
|
||||||
ctx = NetContext(credentials)
|
ctx = NetContext(credentials)
|
||||||
vampire_ctx = object()
|
machine_creds = Credentials()
|
||||||
machine_creds = credentials_init()
|
|
||||||
machine_creds.set_domain(form.domain)
|
machine_creds.set_domain(form.domain)
|
||||||
if not machine_creds.set_machine_account():
|
if not machine_creds.set_machine_account():
|
||||||
raise Exception("Failed to access domain join information!")
|
raise Exception("Failed to access domain join information!")
|
||||||
@ -835,7 +815,7 @@ def vampire(domain, session_info, credentials, message):
|
|||||||
raise Exception("Migration of remote domain to Samba failed: %s " % vampire_ctx.error_string)
|
raise Exception("Migration of remote domain to Samba failed: %s " % vampire_ctx.error_string)
|
||||||
|
|
||||||
|
|
||||||
def ldb_erase_partitions(subobj, message, ldb, ldapbackend):
|
def ldb_erase_partitions(domaindn, message, ldb, ldapbackend):
|
||||||
"""Erase an ldb, removing all records."""
|
"""Erase an ldb, removing all records."""
|
||||||
assert ldb is not None
|
assert ldb is not None
|
||||||
res = ldb.search(Dn(ldb, ""), SCOPE_BASE, "(objectClass=*)",
|
res = ldb.search(Dn(ldb, ""), SCOPE_BASE, "(objectClass=*)",
|
||||||
@ -848,7 +828,7 @@ def ldb_erase_partitions(subobj, message, ldb, ldapbackend):
|
|||||||
previous_remaining = 1
|
previous_remaining = 1
|
||||||
current_remaining = 0
|
current_remaining = 0
|
||||||
|
|
||||||
if ldapbackend and (basedn == subobj.domaindn):
|
if ldapbackend and (basedn == domaindn):
|
||||||
# Only delete objects that were created by provision
|
# Only delete objects that were created by provision
|
||||||
anything = "(objectcategory=*)"
|
anything = "(objectcategory=*)"
|
||||||
|
|
||||||
|
@ -35,3 +35,20 @@ class LdbTestCase(unittest.TestCase):
|
|||||||
self.ldb = samba.Ldb(self.filename)
|
self.ldb = samba.Ldb(self.filename)
|
||||||
|
|
||||||
|
|
||||||
|
class SubstituteVarTestCase(unittest.TestCase):
|
||||||
|
def test_empty(self):
|
||||||
|
self.assertEquals("", samba.substitute_var("", {}))
|
||||||
|
|
||||||
|
def test_nothing(self):
|
||||||
|
self.assertEquals("foo bar", samba.substitute_var("foo bar", {"bar": "bla"}))
|
||||||
|
|
||||||
|
def test_replace(self):
|
||||||
|
self.assertEquals("foo bla", samba.substitute_var("foo ${bar}", {"bar": "bla"}))
|
||||||
|
|
||||||
|
def test_broken(self):
|
||||||
|
self.assertEquals("foo ${bdkjfhsdkfh sdkfh ",
|
||||||
|
samba.substitute_var("foo ${bdkjfhsdkfh sdkfh ", {"bar": "bla"}))
|
||||||
|
|
||||||
|
def test_unknown_var(self):
|
||||||
|
self.assertEquals("foo ${bla} gsff",
|
||||||
|
samba.substitute_var("foo ${bla} gsff", {"bar": "bla"}))
|
||||||
|
59
source4/scripting/python/samba/tests/provision.py
Normal file
59
source4/scripting/python/samba/tests/provision.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Unix SMB/CIFS implementation.
|
||||||
|
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
|
||||||
|
#
|
||||||
|
# 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 unittest
|
||||||
|
import samba.provision
|
||||||
|
|
||||||
|
class ProvisionTestCase(unittest.TestCase):
|
||||||
|
def test_setup_secretsdb(self):
|
||||||
|
raise NotImplementedError(self.test_setup_secretsdb)
|
||||||
|
|
||||||
|
def test_setup_templatesdb(self):
|
||||||
|
raise NotImplementedError(self.test_setup_templatesdb)
|
||||||
|
|
||||||
|
def test_setup_registry(self):
|
||||||
|
raise NotImplementedError(self.test_setup_registry)
|
||||||
|
|
||||||
|
def test_setup_samdb_rootdse(self):
|
||||||
|
raise NotImplementedError(self.test_setup_samdb_rootdse)
|
||||||
|
|
||||||
|
def test_setup_samdb_partitions(self):
|
||||||
|
raise NotImplementedError(self.test_setup_samdb_partitions)
|
||||||
|
|
||||||
|
def test_create_phpldapadmin_config(self):
|
||||||
|
raise NotImplementedError(self.test_create_phpldapadmin_config)
|
||||||
|
|
||||||
|
def test_provision_dns(self):
|
||||||
|
raise NotImplementedError(self.test_provision_dns)
|
||||||
|
|
||||||
|
def test_provision_ldapbase(self):
|
||||||
|
raise NotImplementedError(self.test_provision_ldapbase)
|
||||||
|
|
||||||
|
def test_provision_guess(self):
|
||||||
|
raise NotImplementedError(self.test_provision_guess)
|
||||||
|
|
||||||
|
def test_join_domain(self):
|
||||||
|
raise NotImplementedError(self.test_join_domain)
|
||||||
|
|
||||||
|
def test_vampire(self):
|
||||||
|
raise NotImplementedError(self.test_vampire)
|
||||||
|
|
||||||
|
def test_erase_partitions(self):
|
||||||
|
raise NotImplementedError(self.test_erase_partitions)
|
||||||
|
|
@ -295,4 +295,5 @@ then
|
|||||||
plantest "security.python" none PYTHONPATH=bin/python:scripting/python:libcli/security/tests/ scripting/bin/subunitrun bindings
|
plantest "security.python" none PYTHONPATH=bin/python:scripting/python:libcli/security/tests/ scripting/bin/subunitrun bindings
|
||||||
plantest "param.python" none PYTHONPATH=bin/python:scripting/python:param/tests scripting/bin/subunitrun bindings
|
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 "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
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user