Debian Codegraph @

dirsrvtests/tests/suites/replication/acceptance_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2025 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 pytest
10 import logging
11 import time
12 from lib389.backend import Backend
13 from lib389.replica import Replicas
14 from lib389.tasks import *
15 from lib389.utils import *
16 from test389.topologies import topology_m4 as topo_m4
17 from test389.topologies import topology_m2 as topo_m2
18 from . import get_repl_entries
19 from lib389.idm.user import UserAccount
20 from lib389.replica import ReplicationManager, Changelog
21 from lib389._constants import *
22
23 pytestmark = pytest.mark.tier0
24
25 TEST_ENTRY_NAME = 'mmrepl_test'
26 TEST_ENTRY_DN = 'uid={},{}'.format(TEST_ENTRY_NAME, DEFAULT_SUFFIX)
27 NEW_SUFFIX_NAME = 'test_repl'
28 NEW_SUFFIX = 'o={}'.format(NEW_SUFFIX_NAME)
29 NEW_BACKEND = 'repl_base'
30
31 DEBUGGING = os.getenv("DEBUGGING", default=False)
32 if DEBUGGING:
33 logging.getLogger(__name__).setLevel(logging.DEBUG)
34 else:
35 logging.getLogger(__name__).setLevel(logging.INFO)
36 log = logging.getLogger(__name__)
37
38
39 @pytest.fixture(scope="function")
40 def create_entry(topo_m4, request):
41 """Add test entry to supplier1"""
42
43 log.info('Adding entry {}'.format(TEST_ENTRY_DN))
44
45 test_user = UserAccount(topo_m4.ms["supplier1"], TEST_ENTRY_DN)
46 if test_user.exists():
47 log.info('Deleting entry {}'.format(TEST_ENTRY_DN))
48 test_user.delete()
49 test_user.create(properties={
50 'uid': TEST_ENTRY_NAME,
51 'cn': TEST_ENTRY_NAME,
52 'sn': TEST_ENTRY_NAME,
53 'userPassword': TEST_ENTRY_NAME,
54 'uidNumber' : '1000',
55 'gidNumber' : '2000',
56 'homeDirectory' : '/home/mmrepl_test',
57 })
58
59 @pytest.fixture(scope="function")
60 def new_suffix(topo_m4, request):
61 """Add a new suffix and enable a replication on it"""
62
63 for num in range(1, 5):
64 log.info('Adding suffix:{} and backend: {} to supplier{}'.format(NEW_SUFFIX, NEW_BACKEND, num))
65 topo_m4.ms["supplier{}".format(num)].backend.create(NEW_SUFFIX, {BACKEND_NAME: NEW_BACKEND})
66 topo_m4.ms["supplier{}".format(num)].mappingtree.create(NEW_SUFFIX, NEW_BACKEND)
67
68 try:
69 topo_m4.ms["supplier{}".format(num)].add_s(Entry((NEW_SUFFIX, {
70 'objectclass': 'top',
71 'objectclass': 'organization',
72 'o': NEW_SUFFIX_NAME,
73 'description': NEW_SUFFIX_NAME
74 })))
75 except ldap.LDAPError as e:
76 log.error('Failed to add suffix ({}): error ({})'.format(NEW_SUFFIX, e.message['desc']))
77 raise
78
79 def fin():
80 for num in range(1, 5):
81 log.info('Deleting suffix:{} and backend: {} from supplier{}'.format(NEW_SUFFIX, NEW_BACKEND, num))
82 topo_m4.ms["supplier{}".format(num)].mappingtree.delete(NEW_SUFFIX)
83 topo_m4.ms["supplier{}".format(num)].backend.delete(NEW_SUFFIX)
84
85 request.addfinalizer(fin)
86
87
88 def test_add_entry(topo_m4, create_entry):
89 """Check that entries are replicated after add operation
90
91 :id: 024250f1-5f7e-4f3b-a9f5-27741e6fd405
92 :setup: Four suppliers replication setup, an entry
93 :steps:
94 1. Check entry on all other suppliers
95 :expectedresults:
96 1. The entry should be replicated to all suppliers
97 """
98
99 entries = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["uid"])
100 assert all(entries), "Entry {} wasn't replicated successfully".format(TEST_ENTRY_DN)
101
102
103 def test_modify_entry(topo_m4, create_entry):
104 """Check that entries are replicated after modify operation
105
106 :id: 36764053-622c-43c2-a132-d7a3ab7d9aaa
107 :setup: Four suppliers replication setup, an entry
108 :steps:
109 1. Modify the entry on supplier1 - add attribute
110 2. Wait for replication to happen
111 3. Check entry on all other suppliers
112 4. Modify the entry on supplier1 - replace attribute
113 5. Wait for replication to happen
114 6. Check entry on all other suppliers
115 7. Modify the entry on supplier1 - delete attribute
116 8. Wait for replication to happen
117 9. Check entry on all other suppliers
118 :expectedresults:
119 1. Attribute should be successfully added
120 2. Some time should pass
121 3. The change should be present on all suppliers
122 4. Attribute should be successfully replaced
123 5. Some time should pass
124 6. The change should be present on all suppliers
125 7. Attribute should be successfully deleted
126 8. Some time should pass
127 9. The change should be present on all suppliers
128 """
129 if DEBUGGING:
130 sleep_time = 8
131 else:
132 sleep_time = 2
133
134 log.info('Modifying entry {} - add operation'.format(TEST_ENTRY_DN))
135
136 m1 = topo_m4.ms["supplier1"]
137 m2 = topo_m4.ms["supplier2"]
138 m3 = topo_m4.ms["supplier3"]
139 m4 = topo_m4.ms["supplier4"]
140 repl = ReplicationManager(DEFAULT_SUFFIX)
141
142 test_user = UserAccount(topo_m4.ms["supplier1"], TEST_ENTRY_DN)
143 test_user.add('mail', '{}@redhat.com'.format(TEST_ENTRY_NAME))
144 repl.wait_for_replication(m1, m2)
145 repl.wait_for_replication(m1, m3)
146 repl.wait_for_replication(m1, m4)
147
148 all_user = topo_m4.all_get_dsldapobject(TEST_ENTRY_DN, UserAccount)
149 for u in all_user:
150 assert "{}@redhat.com".format(TEST_ENTRY_NAME) in u.get_attr_vals_utf8('mail')
151
152 log.info('Modifying entry {} - replace operation'.format(TEST_ENTRY_DN))
153 test_user.replace('mail', '{}@greenhat.com'.format(TEST_ENTRY_NAME))
154 repl.wait_for_replication(m1, m2)
155 repl.wait_for_replication(m1, m3)
156 repl.wait_for_replication(m1, m4)
157
158 all_user = topo_m4.all_get_dsldapobject(TEST_ENTRY_DN, UserAccount)
159 for u in all_user:
160 assert "{}@greenhat.com".format(TEST_ENTRY_NAME) in u.get_attr_vals_utf8('mail')
161
162 log.info('Modifying entry {} - delete operation'.format(TEST_ENTRY_DN))
163 test_user.remove('mail', '{}@greenhat.com'.format(TEST_ENTRY_NAME))
164 repl.wait_for_replication(m1, m2)
165 repl.wait_for_replication(m1, m3)
166 repl.wait_for_replication(m1, m4)
167
168 all_user = topo_m4.all_get_dsldapobject(TEST_ENTRY_DN, UserAccount)
169 for u in all_user:
170 assert "{}@greenhat.com".format(TEST_ENTRY_NAME) not in u.get_attr_vals_utf8('mail')
171
172
173 def test_delete_entry(topo_m4, create_entry):
174 """Check that entry deletion is replicated after delete operation
175
176 :id: 18437262-9d6a-4b98-a47a-6182501ab9bc
177 :setup: Four suppliers replication setup, an entry
178 :steps:
179 1. Delete the entry from supplier1
180 2. Check entry on all other suppliers
181 :expectedresults:
182 1. The entry should be deleted
183 2. The change should be present on all suppliers
184 """
185
186 log.info('Deleting entry {} during the test'.format(TEST_ENTRY_DN))
187 topo_m4.ms["supplier1"].delete_s(TEST_ENTRY_DN)
188 if DEBUGGING:
189 time.sleep(8)
190 else:
191 time.sleep(1)
192 entries = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["uid"])
193 assert not entries, "Entry deletion {} wasn't replicated successfully".format(TEST_ENTRY_DN)
194
195
196 @pytest.mark.parametrize("delold", [0, 1])
197 def test_modrdn_entry(topo_m4, create_entry, delold):
198 """Check that entries are replicated after modrdn operation
199
200 :id: 02558e6d-a745-45ae-8d88-34fe9b16adc9
201 :parametrized: yes
202 :setup: Four suppliers replication setup, an entry
203 :steps:
204 1. Make modrdn operation on entry on supplier1 with both delold 1 and 0
205 2. Check entry on all other suppliers
206 :expectedresults:
207 1. Modrdn operation should be successful
208 2. The change should be present on all suppliers
209 """
210
211 newrdn_name = 'newrdn'
212 newrdn_dn = 'uid={},{}'.format(newrdn_name, DEFAULT_SUFFIX)
213 log.info('Modify entry RDN {}'.format(TEST_ENTRY_DN))
214 try:
215 topo_m4.ms["supplier1"].modrdn_s(TEST_ENTRY_DN, 'uid={}'.format(newrdn_name), delold)
216 except ldap.LDAPError as e:
217 log.error('Failed to modrdn entry (%s): error (%s)' % (TEST_ENTRY_DN,
218 e.message['desc']))
219 raise e
220
221 try:
222 entries_new = get_repl_entries(topo_m4, newrdn_name, ["uid"])
223 assert all(entries_new), "Entry {} wasn't replicated successfully".format(newrdn_name)
224 if delold == 0:
225 entries_old = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["uid"])
226 assert all(entries_old), "Entry with old rdn {} wasn't replicated successfully".format(TEST_ENTRY_DN)
227 else:
228 entries_old = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["uid"])
229 assert not entries_old, "Entry with old rdn {} wasn't removed in replicas successfully".format(
230 TEST_ENTRY_DN)
231 finally:
232 log.info('Remove entry with new RDN {}'.format(newrdn_dn))
233 topo_m4.ms["supplier1"].delete_s(newrdn_dn)
234
235
236 def test_modrdn_after_pause(topo_m4):
237 """Check that changes are properly replicated after replica pause
238
239 :id: 6271dc9c-a993-4a9e-9c6d-05650cdab282
240 :setup: Four suppliers replication setup, an entry
241 :steps:
242 1. Pause all replicas
243 2. Make modrdn operation on entry on supplier1
244 3. Resume all replicas
245 4. Wait for replication to happen
246 5. Check entry on all other suppliers
247 :expectedresults:
248 1. Replicas should be paused
249 2. Modrdn operation should be successful
250 3. Replicas should be resumed
251 4. Some time should pass
252 5. The change should be present on all suppliers
253 """
254
255 if DEBUGGING:
256 sleep_time = 8
257 else:
258 sleep_time = 3
259
260 newrdn_name = 'newrdn'
261 newrdn_dn = 'uid={},{}'.format(newrdn_name, DEFAULT_SUFFIX)
262
263 log.info('Adding entry {}'.format(TEST_ENTRY_DN))
264 try:
265 topo_m4.ms["supplier1"].add_s(Entry((TEST_ENTRY_DN, {
266 'objectclass': 'top person'.split(),
267 'objectclass': 'organizationalPerson',
268 'objectclass': 'inetorgperson',
269 'cn': TEST_ENTRY_NAME,
270 'sn': TEST_ENTRY_NAME,
271 'uid': TEST_ENTRY_NAME
272 })))
273 except ldap.LDAPError as e:
274 log.error('Failed to add entry (%s): error (%s)' % (TEST_ENTRY_DN,
275 e.message['desc']))
276 raise e
277
278 log.info('Pause all replicas')
279 topo_m4.pause_all_replicas()
280
281 log.info('Modify entry RDN {}'.format(TEST_ENTRY_DN))
282 try:
283 topo_m4.ms["supplier1"].modrdn_s(TEST_ENTRY_DN, 'uid={}'.format(newrdn_name))
284 except ldap.LDAPError as e:
285 log.error('Failed to modrdn entry (%s): error (%s)' % (TEST_ENTRY_DN,
286 e.message['desc']))
287 raise e
288
289 log.info('Resume all replicas')
290 topo_m4.resume_all_replicas()
291
292 log.info('Wait for replication to happen')
293 time.sleep(sleep_time)
294
295 try:
296 entries_new = get_repl_entries(topo_m4, newrdn_name, ["uid"])
297 assert all(entries_new), "Entry {} wasn't replicated successfully".format(newrdn_name)
298 finally:
299 log.info('Remove entry with new RDN {}'.format(newrdn_dn))
300 topo_m4.ms["supplier1"].delete_s(newrdn_dn)
301
302
303 def test_modify_stripattrs(topo_m4):
304 """Check that we can modify nsds5replicastripattrs
305
306 :id: f36abed8-e262-4f35-98aa-71ae55611aaa
307 :setup: Four suppliers replication setup
308 :steps:
309 1. Modify nsds5replicastripattrs attribute on any agreement
310 2. Search for the modified attribute
311 :expectedresults: It should be contain the value
312 1. nsds5replicastripattrs should be successfully set
313 2. The modified attribute should be the one we set
314 """
315
316 m1 = topo_m4.ms["supplier1"]
317 agreement = m1.agreement.list(suffix=DEFAULT_SUFFIX)[0].dn
318 attr_value = b'modifiersname modifytimestamp'
319
320 log.info('Modify nsds5replicastripattrs with {}'.format(attr_value))
321 m1.modify_s(agreement, [(ldap.MOD_REPLACE, 'nsds5replicastripattrs', [attr_value])])
322
323 log.info('Check nsds5replicastripattrs for {}'.format(attr_value))
324 entries = m1.search_s(agreement, ldap.SCOPE_BASE, "objectclass=*", ['nsds5replicastripattrs'])
325 assert attr_value in entries[0].data['nsds5replicastripattrs']
326
327
328 def test_multi_subsuffix_replication(topo_m4):
329 """Check that replication works with multiple subsuffixes
330
331 :id: ac1aaeae-173e-48e7-847f-03b9867443c4
332 :setup: Four suppliers replication setup
333 :steps:
334 1. Create additional suffixes
335 2. Setup replication for all suppliers
336 3. Generate test data for each suffix (add, modify, remove)
337 4. Wait for replication to complete across all suppliers for each suffix
338 5. Check that all expected data is present on all suppliers
339 :expectedresults:
340 1. Success
341 2. Success
342 3. Success
343 4. Success
344 5. Success (the data is replicated everywhere)
345 """
346
347 SUFFIX_2 = "dc=test2"
348 SUFFIX_3 = f"dc=test3,{DEFAULT_SUFFIX}"
349 all_suffixes = [DEFAULT_SUFFIX, SUFFIX_2, SUFFIX_3]
350
351 test_users_by_suffix = {suffix: [] for suffix in all_suffixes}
352 created_backends = []
353
354 suppliers = [
355 topo_m4.ms["supplier1"],
356 topo_m4.ms["supplier2"],
357 topo_m4.ms["supplier3"],
358 topo_m4.ms["supplier4"]
359 ]
360
361 try:
362 # Setup additional backends and replication for the new suffixes
363 for suffix in [SUFFIX_2, SUFFIX_3]:
364 repl = ReplicationManager(suffix)
365 for supplier in suppliers:
366 # Create a new backend for this suffix
367 props = {
368 'cn': f'userRoot_{suffix.split(",")[0][3:]}',
369 'nsslapd-suffix': suffix
370 }
371 be = Backend(supplier)
372 be.create(properties=props)
373 be.create_sample_entries('001004002')
374
375 # Track the backend so we can remove it later
376 created_backends.append((supplier, props['cn']))
377
378 # Enable replication
379 if supplier == suppliers[0]:
380 repl.create_first_supplier(supplier)
381 else:
382 repl.join_supplier(suppliers[0], supplier)
383
384 # Create a full mesh topology for this suffix
385 for i, supplier_i in enumerate(suppliers):
386 for j, supplier_j in enumerate(suppliers):
387 if i != j:
388 repl.ensure_agreement(supplier_i, supplier_j)
389
390 # Generate test data for each suffix (add, modify, remove)
391 for suffix in all_suffixes:
392 # Create some user entries in supplier1
393 for i in range(20):
394 user_dn = f'uid=test_user_{i},{suffix}'
395 test_user = UserAccount(suppliers[0], user_dn)
396 test_user.create(properties={
397 'uid': f'test_user_{i}',
398 'cn': f'Test User {i}',
399 'sn': f'User{i}',
400 'userPassword': 'password',
401 'uidNumber': str(1000 + i),
402 'gidNumber': '2000',
403 'homeDirectory': f'/home/test_user_{i}'
404 })
405 test_users_by_suffix[suffix].append(test_user)
406
407 # Perform modifications on these entries
408 for user in test_users_by_suffix[suffix]:
409 # Add some attributes
410 for j in range(3):
411 user.add('description', f'Description {j}')
412 # Replace an attribute
413 user.replace('cn', f'Modified User {user.get_attr_val_utf8("uid")}')
414 # Delete the attributes we added
415 for j in range(3):
416 try:
417 user.remove('description', f'Description {j}')
418 except Exception:
419 pass
420
421 # Wait for replication to complete across all suppliers, for each suffix
422 for suffix in all_suffixes:
423 repl = ReplicationManager(suffix)
424 for i, supplier_i in enumerate(suppliers):
425 for j, supplier_j in enumerate(suppliers):
426 if i != j:
427 repl.wait_for_replication(supplier_i, supplier_j)
428
429 # Verify that each user and modification replicated to all suppliers
430 for suffix in all_suffixes:
431 for i in range(20):
432 user_dn = f'uid=test_user_{i},{suffix}'
433 # Retrieve this user from all suppliers
434 all_user_objs = topo_m4.all_get_dsldapobject(user_dn, UserAccount)
435 # Ensure it exists in all 4 suppliers
436 assert len(all_user_objs) == 4, (
437 f"User {user_dn} not found on all suppliers. "
438 f"Found only on {len(all_user_objs)} suppliers."
439 )
440 # Check modifications: 'cn' should now be 'Modified User test_user_{i}'
441 for user_obj in all_user_objs:
442 expected_cn = f"Modified User test_user_{i}"
443 actual_cn = user_obj.get_attr_val_utf8("cn")
444 assert actual_cn == expected_cn, (
445 f"User {user_dn} has unexpected 'cn': {actual_cn} "
446 f"(expected '{expected_cn}') on supplier {user_obj._instance.serverid}"
447 )
448 # And check that 'description' attributes were removed
449 desc_vals = user_obj.get_attr_vals_utf8('description')
450 for j in range(3):
451 assert f"Description {j}" not in desc_vals, (
452 f"User {user_dn} on supplier {user_obj._instance.serverid} "
453 f"still has 'Description {j}'"
454 )
455
456 # Check there are no decoding errors
457 assert not topo_m4.ms["supplier1"].ds_error_log.match('.*decoding failed.*')
458 assert not topo_m4.ms["supplier2"].ds_error_log.match('.*decoding failed.*')
459 assert not topo_m4.ms["supplier3"].ds_error_log.match('.*decoding failed.*')
460 assert not topo_m4.ms["supplier4"].ds_error_log.match('.*decoding failed.*')
461
462 finally:
463 for suffix, test_users in test_users_by_suffix.items():
464 for user in test_users:
465 try:
466 if user.exists():
467 user.delete()
468 except Exception:
469 pass
470
471 for suffix in [SUFFIX_2, SUFFIX_3]:
472 repl = ReplicationManager(suffix)
473 for supplier in suppliers:
474 try:
475 repl.remove_supplier(supplier)
476 except Exception:
477 pass
478
479 for (supplier, backend_name) in created_backends:
480 be = Backend(supplier, backend_name)
481 try:
482 be.delete()
483 except Exception:
484 pass
485
486
487 def test_new_suffix(topo_m4, new_suffix):
488 """Check that we can enable replication on a new suffix
489
490 :id: d44a9ed4-26b0-4189-b0d0-b2b336ddccbd
491 :setup: Four suppliers replication setup, a new suffix
492 :steps:
493 1. Enable replication on the new suffix
494 2. Check if replication works
495 3. Disable replication on the new suffix
496 :expectedresults:
497 1. Replication on the new suffix should be enabled
498 2. Replication should work
499 3. Replication on the new suffix should be disabled
500 """
501 m1 = topo_m4.ms["supplier1"]
502 m2 = topo_m4.ms["supplier2"]
503
504 repl = ReplicationManager(NEW_SUFFIX)
505
506 repl.create_first_supplier(m1)
507
508 repl.join_supplier(m1, m2)
509
510 repl.test_replication(m1, m2)
511 repl.test_replication(m2, m1)
512
513 repl.remove_supplier(m1)
514 repl.remove_supplier(m2)
515
516
517 def test_many_attrs(topo_m4, create_entry):
518 """Check a replication with many attributes (add and delete)
519
520 :id: d540b358-f67a-43c6-8df5-7c74b3cb7523
521 :setup: Four suppliers replication setup, a test entry
522 :steps:
523 1. Add 10 new attributes to the entry
524 2. Delete few attributes: one from the beginning,
525 two from the middle and one from the end
526 3. Check that the changes were replicated in the right order
527 :expectedresults:
528 1. The attributes should be successfully added
529 2. Delete operations should be successful
530 3. The changes should be replicated in the right order
531 """
532
533 m1 = topo_m4.ms["supplier1"]
534 add_list = ensure_list_bytes(map(lambda x: "test{}".format(x), range(10)))
535 delete_list = ensure_list_bytes(map(lambda x: "test{}".format(x), [0, 4, 7, 9]))
536 test_user = UserAccount(topo_m4.ms["supplier1"], TEST_ENTRY_DN)
537
538 log.info('Modifying entry {} - 10 add operations'.format(TEST_ENTRY_DN))
539 for add_name in add_list:
540 test_user.add('description', add_name)
541
542 if DEBUGGING:
543 time.sleep(10)
544 else:
545 time.sleep(1)
546
547 log.info('Check that everything was properly replicated after an add operation')
548 entries = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["description"])
549 for entry in entries:
550 assert all(entry.getValues("description")[i] == add_name for i, add_name in enumerate(add_list))
551
552 log.info('Modifying entry {} - 4 delete operations for {}'.format(TEST_ENTRY_DN, str(delete_list)))
553 for delete_name in delete_list:
554 test_user.remove('description', delete_name)
555
556 if DEBUGGING:
557 time.sleep(10)
558 else:
559 time.sleep(1)
560
561 log.info('Check that everything was properly replicated after a delete operation')
562 entries = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["description"])
563 for entry in entries:
564 for i, value in enumerate(entry.getValues("description")):
565 assert value == [name for name in add_list if name not in delete_list][i]
566 assert value not in delete_list
567
568
569 def test_double_delete(topo_m4, create_entry):
570 """Check that double delete of the entry doesn't crash server
571
572 :id: 5b85a5af-df29-42c7-b6cb-965ec5aa478e
573 :feature: Multi supplier replication
574 :setup: Four suppliers replication setup, a test entry
575 :steps: 1. Delete the entry
576 2. Delete the entry on the second supplier
577 3. Check that server is alive
578 :expectedresults: Server hasn't crash
579 """
580
581 log.info('Deleting entry {} from supplier1'.format(TEST_ENTRY_DN))
582 topo_m4.ms["supplier1"].delete_s(TEST_ENTRY_DN)
583
584 if DEBUGGING:
585 time.sleep(5)
586 else:
587 time.sleep(1)
588
589 log.info('Deleting entry {} from supplier2'.format(TEST_ENTRY_DN))
590 try:
591 topo_m4.ms["supplier2"].delete_s(TEST_ENTRY_DN)
592 except ldap.NO_SUCH_OBJECT:
593 log.info("Entry {} wasn't found supplier2. It is expected.".format(TEST_ENTRY_DN))
594
595 if DEBUGGING:
596 time.sleep(5)
597 else:
598 time.sleep(1)
599
600 log.info('Make searches to check if server is alive')
601 entries = get_repl_entries(topo_m4, TEST_ENTRY_NAME, ["uid"])
602 assert not entries, "Entry deletion {} wasn't replicated successfully".format(TEST_ENTRY_DN)
603
604
605 def test_password_repl_error(topo_m4, create_entry):
606 """Check that error about userpassword replication is properly logged
607
608 :id: d4f12dc0-cd2c-4b92-9b8d-d764a60f0698
609 :feature: Multi supplier replication
610 :setup: Four suppliers replication setup, a test entry
611 :steps: 1. Change userpassword on supplier 1
612 2. Restart the servers to flush the logs
613 3. Check the error log for an replication error
614 :expectedresults: We don't have a replication error in the error log
615 """
616
617 m1 = topo_m4.ms["supplier1"]
618 m2 = topo_m4.ms["supplier2"]
619 m3 = topo_m4.ms["supplier3"]
620 m4 = topo_m4.ms["supplier4"]
621 TEST_ENTRY_NEW_PASS = 'new_{}'.format(TEST_ENTRY_NAME)
622
623 log.info('Clean the error log')
624 m2.deleteErrorLogs()
625
626 log.info('Set replication loglevel')
627 m1.config.loglevel((ErrorLog.REPLICA,))
628 m2.config.loglevel((ErrorLog.REPLICA,))
629 m3.config.loglevel((ErrorLog.REPLICA,))
630 m4.config.loglevel((ErrorLog.REPLICA,))
631
632
633 log.info('Modifying entry {} - change userpassword on supplier 2'.format(TEST_ENTRY_DN))
634 test_user_m1 = UserAccount(topo_m4.ms["supplier1"], TEST_ENTRY_DN)
635 test_user_m2 = UserAccount(topo_m4.ms["supplier2"], TEST_ENTRY_DN)
636 test_user_m3 = UserAccount(topo_m4.ms["supplier3"], TEST_ENTRY_DN)
637 test_user_m4 = UserAccount(topo_m4.ms["supplier4"], TEST_ENTRY_DN)
638
639 test_user_m1.set('userpassword', TEST_ENTRY_NEW_PASS)
640
641 log.info('Restart the servers to flush the logs')
642 for num in range(1, 5):
643 topo_m4.ms["supplier{}".format(num)].restart(timeout=10)
644
645 m1_conn = test_user_m1.bind(TEST_ENTRY_NEW_PASS)
646 m2_conn = test_user_m2.bind(TEST_ENTRY_NEW_PASS)
647 m3_conn = test_user_m3.bind(TEST_ENTRY_NEW_PASS)
648 m4_conn = test_user_m4.bind(TEST_ENTRY_NEW_PASS)
649
650 if DEBUGGING:
651 time.sleep(5)
652 else:
653 time.sleep(1)
654
655 log.info('Check the error log for the error with {}'.format(TEST_ENTRY_DN))
656 assert not m2.ds_error_log.match('.*can.t add a change for uid={}.*'.format(TEST_ENTRY_NAME))
657
658
659 def test_invalid_agmt(topo_m4):
660 """Test adding that an invalid agreement is properly rejected and does not crash the server
661
662 :id: 92f10f46-1be1-49ca-9358-784359397bc2
663 :setup: MMR with four suppliers
664 :steps:
665 1. Add invalid agreement (nsds5ReplicaEnabled set to invalid value)
666 2. Verify the server is still running
667 :expectedresults:
668 1. Invalid repl agreement should be rejected
669 2. Server should be still running
670 """
671 m1 = topo_m4.ms["supplier1"]
672
673 # Add invalid agreement (nsds5ReplicaEnabled set to invalid value)
674 AGMT_DN = 'cn=whatever,cn=replica,cn="dc=example,dc=com",cn=mapping tree,cn=config'
675 try:
676 invalid_props = {RA_ENABLED: 'True', # Invalid value
677 RA_SCHEDULE: '0001-2359 0123456'}
678 m1.agreement.create(suffix=DEFAULT_SUFFIX, host='localhost', port=389, properties=invalid_props)
679 except ldap.UNWILLING_TO_PERFORM:
680 m1.log.info('Invalid repl agreement correctly rejected')
681 except ldap.LDAPError as e:
682 m1.log.fatal('Got unexpected error adding invalid agreement: ' + str(e))
683 assert False
684 else:
685 m1.log.fatal('Invalid agreement was incorrectly accepted by the server')
686 assert False
687
688 # Verify the server is still running
689 try:
690 m1.simple_bind_s(DN_DM, PASSWORD)
691 except ldap.LDAPError as e:
692 m1.log.fatal('Failed to bind: ' + str(e))
693 assert False
694
695
696 def test_reject_self_referential_agmt(topo_m4):
697 """Test that creating a replication agreement pointing to self is rejected
698
699 :id: 7df2f91a-878b-4a7e-86f7-4f72ef5726c6
700 :setup: MMR with four suppliers
701 :steps:
702 1. Try to add an agreement on supplier1 that points to supplier1 host/port
703 :expectedresults:
704 1. Agreement creation should fail with UNWILLING_TO_PERFORM
705 """
706 m1 = topo_m4.ms["supplier1"]
707
708 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
709 m1.agreement.create(suffix=DEFAULT_SUFFIX, host=m1.host, port=m1.port)
710
711
712 def test_warning_for_invalid_replica(topo_m4):
713 """Testing logs to indicate the inconsistency when configuration is performed.
714
715 :id: dd689d03-69b8-4bf9-a06e-2acd19d5e2c8
716 :setup: MMR with four suppliers
717 :steps:
718 1. Setup nsds5ReplicaBackoffMin to 20
719 2. Setup nsds5ReplicaBackoffMax to 10
720 :expectedresults:
721 1. nsds5ReplicaBackoffMin should set to 20
722 2. An error should be generated and also logged in the error logs.
723 """
724 replicas = Replicas(topo_m4.ms["supplier1"])
725 replica = replicas.list()[0]
726 log.info('Set nsds5ReplicaBackoffMin to 20')
727 replica.set('nsds5ReplicaBackoffMin', '20')
728 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
729 log.info('Set nsds5ReplicaBackoffMax to 10')
730 replica.set('nsds5ReplicaBackoffMax', '10')
731 log.info('Resetting configuration: nsds5ReplicaBackoffMin')
732 replica.remove_all('nsds5ReplicaBackoffMin')
733 log.info('Check the error log for the error')
734 assert topo_m4.ms["supplier1"].ds_error_log.match('.*nsds5ReplicaBackoffMax.*10.*invalid.*')
735
736
737 def test_csnpurge_large_valueset(topo_m2):
738 """Test csn generator test
739
740 :id: 63e2bdb2-0a8f-4660-9465-7b80a9f72a74
741 :setup: MMR with 2 suppliers
742 :steps:
743 1. Create a test_user
744 2. add a large set of values (more than 10)
745 3. delete all the values (more than 10)
746 4. configure the replica to purge those values (purgedelay=5s)
747 5. Waiting for 6 second
748 6. do a series of update
749 :expectedresults:
750 1. Should succeeds
751 2. Should succeeds
752 3. Should succeeds
753 4. Should succeeds
754 5. Should succeeds
755 6. Should not crash
756 """
757 m1 = topo_m2.ms["supplier2"]
758
759 test_user = UserAccount(m1, TEST_ENTRY_DN)
760 if test_user.exists():
761 log.info('Deleting entry {}'.format(TEST_ENTRY_DN))
762 test_user.delete()
763 test_user.create(properties={
764 'uid': TEST_ENTRY_NAME,
765 'cn': TEST_ENTRY_NAME,
766 'sn': TEST_ENTRY_NAME,
767 'userPassword': TEST_ENTRY_NAME,
768 'uidNumber' : '1000',
769 'gidNumber' : '2000',
770 'homeDirectory' : '/home/mmrepl_test',
771 })
772
773 # create a large value set so that it is sorted
774 for i in range(1,20):
775 test_user.add('description', 'value {}'.format(str(i)))
776
777 # delete all values of the valueset
778 for i in range(1,20):
779 test_user.remove('description', 'value {}'.format(str(i)))
780
781 # set purging delay to 5 second and wait more that 5second
782 replicas = Replicas(m1)
783 replica = replicas.list()[0]
784 log.info('nsds5ReplicaPurgeDelay to 5')
785 replica.set('nsds5ReplicaPurgeDelay', '5')
786 time.sleep(10)
787
788 # add some new values to the valueset containing entries that should be purged
789 for i in range(21,25):
790 test_user.add('description', 'value {}'.format(str(i)))
791
792 def test_urp_trigger_substring_search(topo_m2):
793 """Test that a ADD of a entry with a '*' in its DN, triggers
794 an internal search with a escaped DN
795
796 :id: 9869bb39-419f-42c3-a44b-c93eb0b77667
797 :customerscenario: True
798 :setup: MMR with 2 suppliers
799 :steps:
800 1. enable internal operation loggging for plugins
801 2. Create on M1 a test_user with a '*' in its DN
802 3. Check the test_user is replicated
803 4. Check in access logs that the internal search does not contain '*'
804 :expectedresults:
805 1. Should succeeds
806 2. Should succeeds
807 3. Should succeeds
808 4. Should succeeds
809 """
810 m1 = topo_m2.ms["supplier1"]
811 m2 = topo_m2.ms["supplier2"]
812
813 # Enable loggging of internal operation logging to capture URP intop
814 log.info('Set nsslapd-plugin-logging to on')
815 for inst in (m1, m2):
816 inst.config.loglevel([AccessLog.DEFAULT, AccessLog.INTERNAL], service='access')
817 inst.config.set('nsslapd-plugin-logging', 'on')
818 inst.restart()
819
820 # add a user with a DN containing '*'
821 test_asterisk_uid = 'asterisk_*_in_value'
822 test_asterisk_dn = 'uid={},{}'.format(test_asterisk_uid, DEFAULT_SUFFIX)
823
824 test_user = UserAccount(m1, test_asterisk_dn)
825 if test_user.exists():
826 log.info('Deleting entry {}'.format(test_asterisk_dn))
827 test_user.delete()
828 test_user.create(properties={
829 'uid': test_asterisk_uid,
830 'cn': test_asterisk_uid,
831 'sn': test_asterisk_uid,
832 'userPassword': test_asterisk_uid,
833 'uidNumber' : '1000',
834 'gidNumber' : '2000',
835 'homeDirectory' : '/home/asterisk',
836 })
837
838 # check that the ADD was replicated on M2
839 test_user_m2 = UserAccount(m2, test_asterisk_dn)
840 for i in range(1,5):
841 if test_user_m2.exists():
842 break
843 else:
844 log.info('Entry not yet replicated on M2, wait a bit')
845 time.sleep(3)
846
847 # check that M2 access logs does not "(&(objectclass=nstombstone)(nscpentrydn=uid=asterisk_*_in_value,dc=example,dc=com))"
848 log.info('Check that on M2, URP as not triggered such internal search')
849 pattern = ".*\(Internal\).*SRCH.*\(&\(objectclass=nstombstone\)\(nscpentrydn=uid=asterisk_\*_in_value,dc=example,dc=com.*"
850 found = m2.ds_access_log.match(pattern)
851 log.info("found line: %s" % found)
852 assert not found
853
854
855 @pytest.mark.skipif(ds_is_older('1.4.4'), reason="Not implemented")
856 def test_csngen_task(topo_m2):
857 """Test csn generator test
858
859 :id: b976849f-dbed-447e-91a7-c877d5d71fd0
860 :setup: MMR with 2 suppliers
861 :steps:
862 1. Create a csngen_test task
863 2. Check that debug messages "_csngen_gen_tester_main" are in errors logs
864 :expectedresults:
865 1. Should succeeds
866 2. Should succeeds
867 """
868 m1 = topo_m2.ms["supplier1"]
869 csngen_task = csngenTestTask(m1)
870 csngen_task.create(properties={
871 'ttl': '300'
872 })
873 time.sleep(10)
874 log.info('Check the error log contains strings showing csn generator is tested')
875 assert m1.searchErrorsLog("_csngen_gen_tester_main")
876
877
878 def test_default_cl_trimming_enabled(topo_m2):
879 """Check that changelog trimming was enabled by default
880
881 :id: c37b9a28-f961-4867-b8a1-e81edd7f9bf3
882 :setup: Supplier Instance
883 :steps:
884 1. Check changelog has trimming set up by default
885 :expectedresults:
886 1. Success
887 """
888
889 # Set up changelog trimming by default
890 cl = Changelog(topo_m2.ms["supplier1"], DEFAULT_SUFFIX)
891 assert cl.get_attr_val_utf8("nsslapd-changelogmaxage") == "7d"
892
893
894 if __name__ == '__main__':
895 # Run isolated
896 # -s for DEBUG mode
897 CURRENT_FILE = os.path.realpath(__file__)
898 pytest.main("-s %s" % CURRENT_FILE)