Debian Codegraph @

dirsrvtests/tests/stress/reliabilty/reliab_7_5_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2016 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8
9 import sys
10 import time
11 import ldap
12 import logging
13 import pytest
14 import threading
15 import random
16 from lib389 import DirSrv, Entry
17 from lib389._constants import *
18 from lib389.properties import *
19 from lib389.tasks import *
20 from lib389.utils import *
21
22 from lib389.idm.directorymanager import DirectoryManager
23
24 pytestmark = pytest.mark.tier3
25
26 logging.getLogger(__name__).setLevel(logging.DEBUG)
27 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s' +
28 ' - %(message)s')
29 handler = logging.StreamHandler()
30 handler.setFormatter(formatter)
31 log = logging.getLogger(__name__)
32 log.addHandler(handler)
33
34 installation1_prefix = None
35 NUM_USERS = 5000
36 MAX_PASSES = 1000
37 CHECK_CONVERGENCE = True
38 ENABLE_VALGRIND = False
39 RUNNING = True
40
41 DEBUGGING = os.getenv('DEBUGGING', default=False)
42
43 class TopologyReplication(object):
44 def __init__(self, supplier1, supplier2):
45 supplier1.open()
46 self.supplier1 = supplier1
47 supplier2.open()
48 self.supplier2 = supplier2
49
50
51 @pytest.fixture(scope="module")
52 def topology(request):
53 global installation1_prefix
54 if installation1_prefix:
55 args_instance[SER_DEPLOYED_DIR] = installation1_prefix
56
57 # Creating supplier 1...
58 supplier1 = DirSrv(verbose=DEBUGGING)
59 args_instance[SER_HOST] = HOST_SUPPLIER_1
60 args_instance[SER_PORT] = PORT_SUPPLIER_1
61 args_instance[SER_SECURE_PORT] = SECUREPORT_SUPPLIER_1
62 args_instance[SER_SERVERID_PROP] = SERVERID_SUPPLIER_1
63 args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
64 args_supplier = args_instance.copy()
65 supplier1.allocate(args_supplier)
66 instance_supplier1 = supplier1.exists()
67 if instance_supplier1:
68 supplier1.delete()
69 supplier1.create()
70 supplier1.open()
71 supplier1.replica.enableReplication(suffix=SUFFIX, role=ReplicaRole.SUPPLIER,
72 replicaId=REPLICAID_SUPPLIER_1)
73
74 # Creating supplier 2...
75 supplier2 = DirSrv(verbose=DEBUGGING)
76 args_instance[SER_HOST] = HOST_SUPPLIER_2
77 args_instance[SER_PORT] = PORT_SUPPLIER_2
78 args_instance[SER_SECURE_PORT] = SECUREPORT_SUPPLIER_2
79 args_instance[SER_SERVERID_PROP] = SERVERID_SUPPLIER_2
80 args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
81 args_supplier = args_instance.copy()
82 supplier2.allocate(args_supplier)
83 instance_supplier2 = supplier2.exists()
84 if instance_supplier2:
85 supplier2.delete()
86 supplier2.create()
87 supplier2.open()
88 supplier2.replica.enableReplication(suffix=SUFFIX, role=ReplicaRole.SUPPLIER,
89 replicaId=REPLICAID_SUPPLIER_2)
90
91 #
92 # Create all the agreements
93 #
94 # Creating agreement from supplier 1 to supplier 2
95 properties = {RA_NAME: r'meTo_$host:$port',
96 RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
97 RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
98 RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
99 RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
100 m1_m2_agmt = supplier1.agreement.create(suffix=SUFFIX, host=supplier2.host,
101 port=supplier2.port,
102 properties=properties)
103 if not m1_m2_agmt:
104 log.fatal("Fail to create a supplier -> supplier replica agreement")
105 sys.exit(1)
106 log.debug("%s created" % m1_m2_agmt)
107
108 # Creating agreement from supplier 2 to supplier 1
109 properties = {RA_NAME: r'meTo_$host:$port',
110 RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
111 RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
112 RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
113 RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
114 m2_m1_agmt = supplier2.agreement.create(suffix=SUFFIX, host=supplier1.host,
115 port=supplier1.port,
116 properties=properties)
117 if not m2_m1_agmt:
118 log.fatal("Fail to create a supplier -> supplier replica agreement")
119 sys.exit(1)
120 log.debug("%s created" % m2_m1_agmt)
121
122 # Allow the replicas to get situated with the new agreements...
123 time.sleep(5)
124
125 #
126 # Import tests entries into supplier1 before we initialize supplier2
127 #
128 ldif_dir = supplier1.get_ldif_dir()
129
130 import_ldif = ldif_dir + '/rel7.5-entries.ldif'
131
132 # First generate an ldif
133 try:
134 ldif = open(import_ldif, 'w')
135 except IOError as e:
136 log.fatal('Failed to create test ldif, error: %s - %s' %
137 (e.errno, e.strerror))
138 assert False
139
140 # Create the root node
141 ldif.write('dn: ' + DEFAULT_SUFFIX + '\n')
142 ldif.write('objectclass: top\n')
143 ldif.write('objectclass: domain\n')
144 ldif.write('dc: example\n')
145 ldif.write('\n')
146
147 # Create the entries
148 idx = 0
149 while idx < NUM_USERS:
150 count = str(idx)
151 ldif.write('dn: uid=supplier1_entry' + count + ',' +
152 DEFAULT_SUFFIX + '\n')
153 ldif.write('objectclass: top\n')
154 ldif.write('objectclass: person\n')
155 ldif.write('objectclass: inetorgperson\n')
156 ldif.write('objectclass: organizationalperson\n')
157 ldif.write('uid: supplier1_entry' + count + '\n')
158 ldif.write('cn: supplier1 entry' + count + '\n')
159 ldif.write('givenname: supplier1 ' + count + '\n')
160 ldif.write('sn: entry ' + count + '\n')
161 ldif.write('userpassword: supplier1_entry' + count + '\n')
162 ldif.write('description: ' + 'a' * random.randint(1, 1000) + '\n')
163 ldif.write('\n')
164
165 ldif.write('dn: uid=supplier2_entry' + count + ',' +
166 DEFAULT_SUFFIX + '\n')
167 ldif.write('objectclass: top\n')
168 ldif.write('objectclass: person\n')
169 ldif.write('objectclass: inetorgperson\n')
170 ldif.write('objectclass: organizationalperson\n')
171 ldif.write('uid: supplier2_entry' + count + '\n')
172 ldif.write('cn: supplier2 entry' + count + '\n')
173 ldif.write('givenname: supplier2 ' + count + '\n')
174 ldif.write('sn: entry ' + count + '\n')
175 ldif.write('userpassword: supplier2_entry' + count + '\n')
176 ldif.write('description: ' + 'a' * random.randint(1, 1000) + '\n')
177 ldif.write('\n')
178 idx += 1
179
180 ldif.close()
181
182 # Now import it
183 try:
184 supplier1.tasks.importLDIF(suffix=DEFAULT_SUFFIX, input_file=import_ldif,
185 args={TASK_WAIT: True})
186 except ValueError:
187 log.fatal('test_reliab_7.5: Online import failed')
188 assert False
189
190 #
191 # Initialize all the agreements
192 #
193 supplier1.agreement.init(SUFFIX, HOST_SUPPLIER_2, PORT_SUPPLIER_2)
194 supplier1.waitForReplInit(m1_m2_agmt)
195
196 # Check replication is working...
197 if supplier1.testReplication(DEFAULT_SUFFIX, supplier2):
198 log.info('Replication is working.')
199 else:
200 log.fatal('Replication is not working.')
201 assert False
202
203 # Clear out the tmp dir
204 supplier1.clearTmpDir(__file__)
205
206 # Delete each instance in the end
207 def fin():
208 supplier1.delete()
209 supplier2.delete()
210 if ENABLE_VALGRIND:
211 sbin_dir = get_sbin_dir(prefix=supplier1.prefix)
212 valgrind_disable(sbin_dir)
213 request.addfinalizer(fin)
214
215 return TopologyReplication(supplier1, supplier2)
216
217
218 class AddDelUsers(threading.Thread):
219 def __init__(self, inst, supplierid):
220 threading.Thread.__init__(self)
221 self.daemon = True
222 self.inst = inst
223 self.id = supplierid
224
225 def run(self):
226 # Add 5000 entries
227 idx = 0
228 RDN = 'uid=add_del_supplier_' + self.id + '-'
229
230 conn = DirectoryManager(self.inst).bind()
231
232 while idx < NUM_USERS:
233 USER_DN = RDN + str(idx) + ',' + DEFAULT_SUFFIX
234 try:
235 conn.add_s(Entry((USER_DN, {'objectclass':
236 'top extensibleObject'.split(),
237 'uid': 'user' + str(idx),
238 'cn': 'g' * random.randint(1, 500)
239 })))
240 except ldap.LDAPError as e:
241 log.fatal('Add users to supplier ' + self.id + ' failed (' +
242 USER_DN + ') error: ' + e.message['desc'])
243 idx += 1
244 conn.close()
245
246 # Delete 5000 entries
247 conn = DirectoryManager(self.inst).bind()
248 idx = 0
249 while idx < NUM_USERS:
250 USER_DN = RDN + str(idx) + ',' + DEFAULT_SUFFIX
251 try:
252 conn.delete_s(USER_DN)
253 except ldap.LDAPError as e:
254 log.fatal('Failed to delete (' + USER_DN + ') on supplier ' +
255 self.id + ': error ' + e.message['desc'])
256 idx += 1
257 conn.close()
258
259
260 class ModUsers(threading.Thread):
261 # Do mods and modrdns
262 def __init__(self, inst, supplierid):
263 threading.Thread.__init__(self)
264 self.daemon = True
265 self.inst = inst
266 self.id = supplierid
267
268 def run(self):
269 # Mod existing entries
270 conn = DirectoryManager(self.inst).bind()
271 idx = 0
272 while idx < NUM_USERS:
273 USER_DN = ('uid=supplier' + self.id + '_entry' + str(idx) + ',' +
274 DEFAULT_SUFFIX)
275 try:
276 conn.modify(USER_DN, [(ldap.MOD_REPLACE,
277 'givenname',
278 'new givenname supplier1-' + str(idx))])
279 except ldap.LDAPError as e:
280 log.fatal('Failed to modify (' + USER_DN + ') on supplier ' +
281 self.id + ': error ' + e.message['desc'])
282 idx += 1
283 conn.close()
284
285 # Modrdn existing entries
286 conn = DirectoryManager(self.inst).bind()
287 idx = 0
288 while idx < NUM_USERS:
289 USER_DN = ('uid=supplier' + self.id + '_entry' + str(idx) + ',' +
290 DEFAULT_SUFFIX)
291 NEW_RDN = 'cn=supplier' + self.id + '_entry' + str(idx)
292 try:
293 conn.rename_s(USER_DN, NEW_RDN, delold=1)
294 except ldap.LDAPError as e:
295 log.error('Failed to modrdn (' + USER_DN + ') on supplier ' +
296 self.id + ': error ' + e.message['desc'])
297 idx += 1
298 conn.close()
299
300 # Undo modrdn to we can rerun this test
301 conn = DirectoryManager(self.inst).bind()
302 idx = 0
303 while idx < NUM_USERS:
304 USER_DN = ('cn=supplier' + self.id + '_entry' + str(idx) + ',' +
305 DEFAULT_SUFFIX)
306 NEW_RDN = 'uid=supplier' + self.id + '_entry' + str(idx)
307 try:
308 conn.rename_s(USER_DN, NEW_RDN, delold=1)
309 except ldap.LDAPError as e:
310 log.error('Failed to modrdn (' + USER_DN + ') on supplier ' +
311 self.id + ': error ' + e.message['desc'])
312 idx += 1
313 conn.close()
314
315
316 class DoSearches(threading.Thread):
317 # Search a supplier
318 def __init__(self, inst, supplierid):
319 threading.Thread.__init__(self)
320 self.daemon = True
321 self.inst = inst
322 self.id = supplierid
323
324 def run(self):
325 # Equality
326 conn = DirectoryManager(self.inst).bind()
327 idx = 0
328 while idx < NUM_USERS:
329 search_filter = ('(|(uid=supplier' + self.id + '_entry' + str(idx) +
330 ')(cn=supplier' + self.id + '_entry' + str(idx) +
331 '))')
332 try:
333 conn.search(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, search_filter)
334 except ldap.LDAPError as e:
335 log.fatal('Search Users: Search failed (%s): %s' %
336 (search_filter, e.message['desc']))
337 conn.close()
338 return
339
340 idx += 1
341 conn.close()
342
343 # Substring
344 conn = DirectoryManager(self.inst).bind()
345 idx = 0
346 while idx < NUM_USERS:
347 search_filter = ('(|(uid=supplier' + self.id + '_entry' + str(idx) +
348 '*)(cn=supplier' + self.id + '_entry' + str(idx) +
349 '*))')
350 try:
351 conn.search(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, search_filter)
352 except ldap.LDAPError as e:
353 log.fatal('Search Users: Search failed (%s): %s' %
354 (search_filter, e.message['desc']))
355 conn.close()
356 return
357
358 idx += 1
359 conn.close()
360
361
362 class DoFullSearches(threading.Thread):
363 # Search a supplier
364 def __init__(self, inst):
365 threading.Thread.__init__(self)
366 self.daemon = True
367 self.inst = inst
368
369 def run(self):
370 global RUNNING
371 conn = DirectoryManager(self.inst).bind()
372 while RUNNING:
373 time.sleep(2)
374 try:
375 conn.search_s(DEFAULT_SUFFIX,
376 ldap.SCOPE_SUBTREE,
377 'objectclass=top')
378 except ldap.LDAPError as e:
379 log.fatal('Full Search Users: Search failed (%s): %s' %
380 ('objectclass=*', e.message['desc']))
381 conn.close()
382 assert False
383
384 conn.close()
385
386
387 def test_reliab7_5_init(topology):
388 '''
389 Reduce entry cache - to increase the cache churn
390
391 Then process "reliability 15" type tests
392 '''
393
394 BACKEND_DN = 'cn=userroot,cn=ldbm database,cn=plugins,cn=config'
395
396 # Update supplier 1
397 try:
398 topology.supplier1.modify_s(BACKEND_DN, [(ldap.MOD_REPLACE,
399 'nsslapd-cachememsize',
400 '512000'),
401 (ldap.MOD_REPLACE,
402 'nsslapd-cachesize',
403 '500')])
404 except ldap.LDAPError as e:
405 log.fatal('Failed to set cache settings: error ' + e.message['desc'])
406 assert False
407
408 # Update supplier 2
409 try:
410 topology.supplier2.modify_s(BACKEND_DN, [(ldap.MOD_REPLACE,
411 'nsslapd-cachememsize',
412 '512000'),
413 (ldap.MOD_REPLACE,
414 'nsslapd-cachesize',
415 '500')])
416 except ldap.LDAPError as e:
417 log.fatal('Failed to set cache settings: error ' + e.message['desc'])
418 assert False
419
420 # Restart the suppliers to pick up the new cache settings
421 topology.supplier1.stop(timeout=10)
422 topology.supplier2.stop(timeout=10)
423
424 # This is the time to enable valgrind (if enabled)
425 if ENABLE_VALGRIND:
426 sbin_dir = get_sbin_dir(prefix=topology.supplier1.prefix)
427 valgrind_enable(sbin_dir)
428
429 topology.supplier1.start(timeout=30)
430 topology.supplier2.start(timeout=30)
431
432
433 def test_reliab7_5_run(topology):
434 '''
435 Starting issuing adds, deletes, mods, modrdns, and searches
436 '''
437 global RUNNING
438 count = 1
439 RUNNING = True
440
441 # Start some searches to run through the entire stress test
442 fullSearch1 = DoFullSearches(topology.supplier1)
443 fullSearch1.start()
444 fullSearch2 = DoFullSearches(topology.supplier2)
445 fullSearch2.start()
446
447 while count <= MAX_PASSES:
448 log.info('################## Reliabilty 7.5 Pass: %d' % count)
449
450 # Supplier 1
451 add_del_users1 = AddDelUsers(topology.supplier1, '1')
452 add_del_users1.start()
453 mod_users1 = ModUsers(topology.supplier1, '1')
454 mod_users1.start()
455 search1 = DoSearches(topology.supplier1, '1')
456 search1.start()
457
458 # Supplier 2
459 add_del_users2 = AddDelUsers(topology.supplier2, '2')
460 add_del_users2.start()
461 mod_users2 = ModUsers(topology.supplier2, '2')
462 mod_users2.start()
463 search2 = DoSearches(topology.supplier2, '2')
464 search2.start()
465
466 # Search the suppliers
467 search3 = DoSearches(topology.supplier1, '1')
468 search3.start()
469 search4 = DoSearches(topology.supplier2, '2')
470 search4.start()
471
472 # Wait for threads to finish
473 log.info('################## Waiting for threads to finish...')
474 add_del_users1.join()
475 mod_users1.join()
476 add_del_users2.join()
477 mod_users2.join()
478 log.info('################## Update threads finished.')
479 search1.join()
480 search2.join()
481 search3.join()
482 search4.join()
483 log.info('################## All threads finished.')
484
485 # Allow some time for replication to catch up before firing
486 # off the next round of updates
487 time.sleep(5)
488 count += 1
489
490 #
491 # Wait for replication to converge
492 #
493 if CHECK_CONVERGENCE:
494 # Add an entry to each supplier, and wait for it to replicate
495 SUPPLIER1_DN = 'uid=rel7.5-supplier1,' + DEFAULT_SUFFIX
496 SUPPLIER2_DN = 'uid=rel7.5-supplier2,' + DEFAULT_SUFFIX
497
498 # Supplier 1
499 try:
500 topology.supplier1.add_s(Entry((SUPPLIER1_DN, {'objectclass':
501 ['top',
502 'extensibleObject'],
503 'sn': '1',
504 'cn': 'user 1',
505 'uid': 'rel7.5-supplier1',
506 'userpassword':
507 PASSWORD})))
508 except ldap.LDAPError as e:
509 log.fatal('Failed to add replication test entry ' + SUPPLIER1_DN +
510 ': error ' + e.message['desc'])
511 assert False
512
513 log.info('################## Waiting for supplier 2 to converge...')
514
515 while True:
516 entry = None
517 try:
518 entry = topology.supplier2.search_s(SUPPLIER1_DN,
519 ldap.SCOPE_BASE,
520 'objectclass=*')
521 except ldap.NO_SUCH_OBJECT:
522 pass
523 except ldap.LDAPError as e:
524 log.fatal('Search Users: Search failed (%s): %s' %
525 (SUPPLIER1_DN, e.message['desc']))
526 assert False
527 if entry:
528 break
529 time.sleep(5)
530
531 log.info('################## Supplier 2 converged.')
532
533 # Supplier 2
534 try:
535 topology.supplier2.add_s(
536 Entry((SUPPLIER2_DN, {'objectclass': ['top',
537 'extensibleObject'],
538 'sn': '1',
539 'cn': 'user 1',
540 'uid': 'rel7.5-supplier2',
541 'userpassword': PASSWORD})))
542 except ldap.LDAPError as e:
543 log.fatal('Failed to add replication test entry ' + SUPPLIER1_DN +
544 ': error ' + e.message['desc'])
545 assert False
546
547 log.info('################## Waiting for supplier 1 to converge...')
548 while True:
549 entry = None
550 try:
551 entry = topology.supplier1.search_s(SUPPLIER2_DN,
552 ldap.SCOPE_BASE,
553 'objectclass=*')
554 except ldap.NO_SUCH_OBJECT:
555 pass
556 except ldap.LDAPError as e:
557 log.fatal('Search Users: Search failed (%s): %s' %
558 (SUPPLIER2_DN, e.message['desc']))
559 assert False
560 if entry:
561 break
562 time.sleep(5)
563
564 log.info('################## Supplier 1 converged.')
565
566 # Stop the full searches
567 RUNNING = False
568 fullSearch1.join()
569 fullSearch2.join()
570
571
572 if __name__ == '__main__':
573 # Run isolated
574 # -s for DEBUG mode
575 CURRENT_FILE = os.path.realpath(__file__)
576 pytest.main("-s %s" % CURRENT_FILE)