s4-python: Start using standard python logging infrastructure rather
[samba.git] / source4 / scripting / python / samba / tests / samdb.py
1 #!/usr/bin/python
2
3 # Unix SMB/CIFS implementation. Tests for SamDB
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
5 #   
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #   
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #   
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 from samba.auth import system_session
20 import logging
21 import os
22 from samba.provision import setup_samdb, guess_names, make_smbconf, find_setup_dir
23 from samba.tests import TestCaseInTempDir
24 from samba.dcerpc import security
25 import uuid
26 from samba import param
27
28
29 class SamDBTestCase(TestCaseInTempDir):
30     """Base-class for tests with a Sam Database.
31     
32     This is used by the Samba SamDB-tests, but e.g. also by the OpenChange
33     provisioning tests (which need a Sam).
34     """
35
36     def setup_path(self, relpath):
37         return os.path.join(find_setup_dir(), relpath)
38
39     def setUp(self):
40         super(SamDBTestCase, self).setUp()
41         invocationid = str(uuid.uuid4())
42         domaindn = "DC=COM,DC=EXAMPLE"
43         self.domaindn = domaindn
44         configdn = "CN=Configuration," + domaindn
45         schemadn = "CN=Schema," + configdn
46         domainguid = str(uuid.uuid4())
47         policyguid = str(uuid.uuid4())
48         domainsid = security.random_sid()
49         path = os.path.join(self.tempdir, "samdb.ldb")
50         session_info = system_session()
51         
52         hostname="foo"
53         domain="EXAMPLE"
54         dnsdomain="example.com" 
55         serverrole="domain controller"
56
57         smbconf = os.path.join(self.tempdir, "smb.conf")
58         make_smbconf(smbconf, self.setup_path, hostname, domain, dnsdomain, 
59                      serverrole, self.tempdir)
60
61         self.lp = param.LoadParm()
62         self.lp.load(smbconf)
63
64         names = guess_names(lp=self.lp, hostname=hostname, 
65                             domain=domain, dnsdomain=dnsdomain, 
66                             serverrole=serverrole, 
67                             domaindn=self.domaindn, configdn=configdn, 
68                             schemadn=schemadn)
69
70         paths = provision_paths_from_lp(self.lp, names.dnsdomain)
71
72         provision_backend = ProvisionBackend("ldb", backend_type,
73                                              paths=paths, setup_path=self.setup_path,
74                                              lp=self.lp, credentials=None, 
75                                              names=names,
76                                              message=message, hostname=hostname,
77                                              root=root, schema=schema,
78                                              domainsid=domainsid)
79
80         self.samdb = setup_samdb(path, self.setup_path, session_info, provision_backend, 
81                                  self.lp, names, 
82                                  logging.getLogger("samdb"), domainsid, 
83                                  domainguid, 
84                                  policyguid, False, "secret", 
85                                  "secret", "secret", invocationid, 
86                                  "secret", "domain controller")
87
88     def tearDown(self):
89         for f in ['schema.ldb', 'configuration.ldb',
90                   'users.ldb', 'samdb.ldb', 'smb.conf']:
91             os.remove(os.path.join(self.tempdir, f))
92         super(SamDBTestCase, self).tearDown()
93
94
95 # disable this test till andrew works it out ...
96 class SamDBTests(SamDBTestCase):
97     """Tests for the SamDB implementation."""
98
99     print "samdb add_foreign disabled for now"
100 #    def test_add_foreign(self):