PEP8: fix E128: continuation line under-indented for visual indent
[metze/samba/wip.git] / source4 / dsdb / tests / python / ad_dc_multi_bind.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 import optparse
4 import sys
5 sys.path.insert(0, 'bin/python')
6
7 import os
8 import samba
9 import samba.getopt as options
10 import random
11 import tempfile
12 import shutil
13 import time
14
15 from samba.netcmd.main import cmd_sambatool
16
17 # We try to use the test infrastructure of Samba 4.3+, but if it
18 # doesn't work, we are probably in a back-ported patch and trying to
19 # run on 4.1 or something.
20 #
21 # Don't copy this horror into ordinary tests -- it is special for
22 # performance tests that want to apply to old versions.
23 try:
24     from samba.tests.subunitrun import SubunitOptions, TestProgram
25     ANCIENT_SAMBA = False
26 except ImportError:
27     ANCIENT_SAMBA = True
28     samba.ensure_external_module("testtools", "testtools")
29     samba.ensure_external_module("subunit", "subunit/python")
30     from subunit.run import SubunitTestRunner
31     import unittest
32
33 from samba.samdb import SamDB
34 from samba.auth import system_session
35 from ldb import Message, MessageElement, Dn, LdbError
36 from ldb import FLAG_MOD_ADD, FLAG_MOD_REPLACE, FLAG_MOD_DELETE
37 from ldb import SCOPE_BASE, SCOPE_SUBTREE, SCOPE_ONELEVEL
38
39 parser = optparse.OptionParser("ad_dc_mulit_bind.py [options] <host>")
40 sambaopts = options.SambaOptions(parser)
41 parser.add_option_group(sambaopts)
42 parser.add_option_group(options.VersionOptions(parser))
43
44 if not ANCIENT_SAMBA:
45     subunitopts = SubunitOptions(parser)
46     parser.add_option_group(subunitopts)
47
48 # use command line creds if available
49 credopts = options.CredentialsOptions(parser)
50 parser.add_option_group(credopts)
51 opts, args = parser.parse_args()
52
53
54 if len(args) < 1:
55     parser.print_usage()
56     sys.exit(1)
57
58 host = args[0]
59
60 lp = sambaopts.get_loadparm()
61 creds = credopts.get_credentials(lp)
62
63 class UserTests(samba.tests.TestCase):
64
65     def setUp(self):
66         super(UserTests, self).setUp()
67         self.lp = lp
68
69     def tearDown(self):
70         super(UserTests, self).tearDown()
71
72     def test_1000_binds(self):
73
74         for x in range(1, 1000):
75             samdb = SamDB(host, credentials=creds,
76                           session_info=system_session(self.lp), lp=self.lp)
77             samdb.search(base=samdb.domain_dn(),
78                          scope=SCOPE_BASE, attrs=["*"])
79
80
81 if "://" not in host:
82     if os.path.isfile(host):
83         host = "tdb://%s" % host
84     else:
85         host = "ldap://%s" % host
86
87
88 if ANCIENT_SAMBA:
89     runner = SubunitTestRunner()
90     if not runner.run(unittest.makeSuite(UserTests)).wasSuccessful():
91         sys.exit(1)
92     sys.exit(0)
93 else:
94     TestProgram(module=__name__, opts=subunitopts)