source: vendor/current/source4/scripting/devel/speedtest.py

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 8.0 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Unix SMB/CIFS implementation.
5# This speed test aims to show difference in execution time for bulk
6# creation of user objects. This will help us compare
7# Samba4 vs MS Active Directory performance.
8
9# Copyright (C) Zahari Zahariev <zahari.zahariev@postpath.com> 2010
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 3 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program. If not, see <http://www.gnu.org/licenses/>.
23#
24
25import optparse
26import sys
27import time
28import base64
29from decimal import Decimal
30
31sys.path.insert(0, "bin/python")
32import samba
33from samba.tests.subunitrun import TestProgram, SubunitOptions
34
35import samba.getopt as options
36
37from ldb import SCOPE_BASE, SCOPE_SUBTREE
38from samba.ndr import ndr_unpack
39from samba.dcerpc import security
40
41from samba.auth import system_session
42from samba import gensec, sd_utils
43from samba.samdb import SamDB
44from samba.credentials import Credentials
45import samba.tests
46from samba.tests import delete_force
47
48parser = optparse.OptionParser("speedtest.py [options] <host>")
49sambaopts = options.SambaOptions(parser)
50parser.add_option_group(sambaopts)
51parser.add_option_group(options.VersionOptions(parser))
52
53# use command line creds if available
54credopts = options.CredentialsOptions(parser)
55parser.add_option_group(credopts)
56subunitopts = SubunitOptions(parser)
57parser.add_option_group(subunitopts)
58opts, args = parser.parse_args()
59
60if len(args) < 1:
61 parser.print_usage()
62 sys.exit(1)
63
64host = args[0]
65
66lp = sambaopts.get_loadparm()
67creds = credopts.get_credentials(lp)
68creds.set_gensec_features(creds.get_gensec_features() | gensec.FEATURE_SEAL)
69
70#
71# Tests start here
72#
73
74class SpeedTest(samba.tests.TestCase):
75
76 def find_domain_sid(self, ldb):
77 res = ldb.search(base=self.base_dn, expression="(objectClass=*)", scope=SCOPE_BASE)
78 return ndr_unpack(security.dom_sid,res[0]["objectSid"][0])
79
80 def setUp(self):
81 super(SpeedTest, self).setUp()
82 self.ldb_admin = ldb
83 self.base_dn = ldb.domain_dn()
84 self.domain_sid = security.dom_sid(ldb.get_domain_sid())
85 self.user_pass = "samba123@"
86 print "baseDN: %s" % self.base_dn
87
88 def create_user(self, user_dn):
89 ldif = """
90dn: """ + user_dn + """
91sAMAccountName: """ + user_dn.split(",")[0][3:] + """
92objectClass: user
93unicodePwd:: """ + base64.b64encode(("\"%s\"" % self.user_pass).encode('utf-16-le')) + """
94url: www.example.com
95"""
96 self.ldb_admin.add_ldif(ldif)
97
98 def create_group(self, group_dn, desc=None):
99 ldif = """
100dn: """ + group_dn + """
101objectClass: group
102sAMAccountName: """ + group_dn.split(",")[0][3:] + """
103groupType: 4
104url: www.example.com
105"""
106 self.ldb_admin.add_ldif(ldif)
107
108 def create_bundle(self, count):
109 for i in range(count):
110 self.create_user("cn=speedtestuser%d,cn=Users,%s" % (i+1, self.base_dn))
111
112 def remove_bundle(self, count):
113 for i in range(count):
114 delete_force(self.ldb_admin, "cn=speedtestuser%d,cn=Users,%s" % (i+1, self.base_dn))
115
116 def remove_test_users(self):
117 res = ldb.search(base="cn=Users,%s" % self.base_dn, expression="(objectClass=user)", scope=SCOPE_SUBTREE)
118 dn_list = [item.dn for item in res if "speedtestuser" in str(item.dn)]
119 for dn in dn_list:
120 delete_force(self.ldb_admin, dn)
121
122class SpeedTestAddDel(SpeedTest):
123
124 def setUp(self):
125 super(SpeedTestAddDel, self).setUp()
126
127 def run_bundle(self, num):
128 print "\n=== Test ADD/DEL %s user objects ===\n" % num
129 avg_add = Decimal("0.0")
130 avg_del = Decimal("0.0")
131 for x in [1, 2, 3]:
132 start = time.time()
133 self.create_bundle(num)
134 res_add = Decimal( str(time.time() - start) )
135 avg_add += res_add
136 print " Attempt %s ADD: %.3fs" % ( x, float(res_add) )
137 #
138 start = time.time()
139 self.remove_bundle(num)
140 res_del = Decimal( str(time.time() - start) )
141 avg_del += res_del
142 print " Attempt %s DEL: %.3fs" % ( x, float(res_del) )
143 print "Average ADD: %.3fs" % float( Decimal(avg_add) / Decimal("3.0") )
144 print "Average DEL: %.3fs" % float( Decimal(avg_del) / Decimal("3.0") )
145 print ""
146
147 def test_00000(self):
148 """ Remove possibly undeleted test users from previous test
149 """
150 self.remove_test_users()
151
152 def test_00010(self):
153 self.run_bundle(10)
154
155 def test_00100(self):
156 self.run_bundle(100)
157
158 def test_01000(self):
159 self.run_bundle(1000)
160
161 def _test_10000(self):
162 """ This test should be enabled preferably against MS Active Directory.
163 It takes quite the time against Samba4 (1-2 days).
164 """
165 self.run_bundle(10000)
166
167class AclSearchSpeedTest(SpeedTest):
168
169 def setUp(self):
170 super(AclSearchSpeedTest, self).setUp()
171 self.ldb_admin.newuser("acltestuser", "samba123@")
172 self.sd_utils = sd_utils.SDUtils(self.ldb_admin)
173 self.ldb_user = self.get_ldb_connection("acltestuser", "samba123@")
174 self.user_sid = self.sd_utils.get_object_sid(self.get_user_dn("acltestuser"))
175
176 def tearDown(self):
177 super(AclSearchSpeedTest, self).tearDown()
178 delete_force(self.ldb_admin, self.get_user_dn("acltestuser"))
179
180 def run_search_bundle(self, num, _ldb):
181 print "\n=== Creating %s user objects ===\n" % num
182 self.create_bundle(num)
183 mod = "(A;;LC;;;%s)(D;;RP;;;%s)" % (str(self.user_sid), str(self.user_sid))
184 for i in range(num):
185 self.sd_utils.dacl_add_ace("cn=speedtestuser%d,cn=Users,%s" %
186 (i+1, self.base_dn), mod)
187 print "\n=== %s user objects created ===\n" % num
188 print "\n=== Test search on %s user objects ===\n" % num
189 avg_search = Decimal("0.0")
190 for x in [1, 2, 3]:
191 start = time.time()
192 res = _ldb.search(base=self.base_dn, expression="(objectClass=*)", scope=SCOPE_SUBTREE)
193 res_search = Decimal( str(time.time() - start) )
194 avg_search += res_search
195 print " Attempt %s SEARCH: %.3fs" % ( x, float(res_search) )
196 print "Average Search: %.3fs" % float( Decimal(avg_search) / Decimal("3.0") )
197 self.remove_bundle(num)
198
199 def get_user_dn(self, name):
200 return "CN=%s,CN=Users,%s" % (name, self.base_dn)
201
202 def get_ldb_connection(self, target_username, target_password):
203 creds_tmp = Credentials()
204 creds_tmp.set_username(target_username)
205 creds_tmp.set_password(target_password)
206 creds_tmp.set_domain(creds.get_domain())
207 creds_tmp.set_realm(creds.get_realm())
208 creds_tmp.set_workstation(creds.get_workstation())
209 creds_tmp.set_gensec_features(creds_tmp.get_gensec_features()
210 | gensec.FEATURE_SEAL)
211 ldb_target = SamDB(url=host, credentials=creds_tmp, lp=lp)
212 return ldb_target
213
214 def test_search_01000(self):
215 self.run_search_bundle(1000, self.ldb_admin)
216
217 def test_search2_01000(self):
218 # allow the user to see objects but not attributes, all attributes will be filtered out
219 mod = "(A;;LC;;;%s)(D;;RP;;;%s)" % (str(self.user_sid), str(self.user_sid))
220 self.sd_utils.dacl_add_ace("CN=Users,%s" % self.base_dn, mod)
221 self.run_search_bundle(1000, self.ldb_user)
222
223# Important unit running information
224
225if not "://" in host:
226 host = "ldap://%s" % host
227
228ldb_options = ["modules:paged_searches"]
229ldb = SamDB(host, credentials=creds, session_info=system_session(), lp=lp, options=ldb_options)
230
231TestProgram(module=__name__, opts=subunitopts)
Note: See TracBrowser for help on using the repository browser.