Debian Codegraph @

dirsrvtests/tests/suites/fractional/fractional_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 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 """
10 This test script will test fractional replication.
11 """
12
13 import logging
14 import os
15 import re
16 import time
17 from types import SimpleNamespace
18
19 import ldap
20 import pytest
21 from test389.topologies import topology_m2, topology_m2c2
22 from lib389._constants import DEFAULT_SUFFIX
23 from lib389.idm.user import UserAccounts, UserAccount
24 from lib389.replica import ReplicationManager, Replicas
25 from lib389.agreement import Agreements
26 from lib389.plugins import MemberOfPlugin
27 from lib389.idm.group import Groups
28 from lib389.config import Config
29 from lib389.utils import ensure_bytes, ensure_str
30
31 log = logging.getLogger(__name__)
32
33 pytestmark = pytest.mark.tier1
34
35 SUPPLIER1 = SUPPLIER2 = CONSUMER1 = CONSUMER2 = None
36
37
38 def _create_users(instance, cn_cn, sn_sn, givenname, ou_ou, l_l, uid, mail,
39 telephonenumber, facsimiletelephonenumber, roomnumber):
40 """
41 Will create sample user.
42 """
43 user = instance.create(properties={
44 'cn': cn_cn,
45 'sn': sn_sn,
46 'givenname': givenname,
47 'ou': ou_ou,
48 'l': l_l,
49 'uid': uid,
50 'mail': mail,
51 'telephonenumber': telephonenumber,
52 'facsimiletelephonenumber': facsimiletelephonenumber,
53 'roomnumber': roomnumber,
54 'uidNumber': '111',
55 'gidNumber': '111',
56 'homeDirectory': f'/home/{uid}',
57
58 })
59 return user
60
61
62 def check_all_replicated():
63 """
64 Will check replication status
65 """
66 for supplier in [SUPPLIER2, CONSUMER1, CONSUMER2]:
67 ReplicationManager(DEFAULT_SUFFIX).wait_for_replication(SUPPLIER1, supplier, timeout=100)
68
69
70 @pytest.fixture(scope="module")
71 def _create_entries(topology_m2c2):
72 """
73 A fixture that will create first test user and create fractional Agreement
74 """
75 # Defining as global , as same value will be used everywhere with same name.
76 global SUPPLIER1, SUPPLIER2, CONSUMER1, CONSUMER2
77 SUPPLIER1 = topology_m2c2.ms['supplier1']
78 SUPPLIER2 = topology_m2c2.ms['supplier2']
79 CONSUMER1 = topology_m2c2.cs['consumer1']
80 CONSUMER2 = topology_m2c2.cs['consumer2']
81 users = UserAccounts(SUPPLIER1, DEFAULT_SUFFIX)
82 _create_users(users, 'Sam Carter', 'Carter', 'Sam', ['Accounting', 'People'],
83 'Sunnyvale', 'scarter', '[email protected]', '+1 408 555 4798',
84 '+1 408 555 9751', '4612')
85 for ins, num in [(SUPPLIER1, 1), (SUPPLIER2, 2), (SUPPLIER1, 2), (SUPPLIER2, 1)]:
86 Agreements(ins).list()[num].replace(
87 'nsDS5ReplicatedAttributeList',
88 '(objectclass=*) $ EXCLUDE audio businessCategory carLicense departmentNumber '
89 'destinationIndicator displayName employeeNumber employeeType facsimileTelephoneNumber '
90 'roomNumber telephoneNumber memberOf manager accountUnlockTime '
91 'passwordRetryCount retryCountResetTime')
92 Agreements(ins).list()[num].replace(
93 'nsDS5ReplicatedAttributeListTotal',
94 '(objectclass=*) $ EXCLUDE audio businessCategory carLicense departmentNumber '
95 'destinationIndicator displayName employeeNumber employeeType facsimileTelephoneNumber '
96 'roomNumber telephoneNumber accountUnlockTime passwordRetryCount retryCountResetTime')
97 Agreements(ins).list()[num].begin_reinit()
98 Agreements(ins).list()[num].wait_reinit()
99
100
101 def test_fractional_agreements(_create_entries):
102 """The attributes should be present on the two suppliers with traditional replication
103 agreements, but not with fractional agreements.
104
105 :id: f22395e0-38ea-11ea-abe0-8c16451d917b
106 :setup: Supplier and Consumer
107 :steps:
108 1. Add test entry
109 2. Search for an entry with disallowed attributes on every server.
110 3. The attributes should be present on the two suppliers with traditional replication
111 agreements
112 4. Should be missing on both consumers with fractional agreements.
113 :expectedresults:
114 1. Success
115 2. Success
116 3. Success
117 4. Success
118 """
119 check_all_replicated()
120 # Search for an entry with disallowed attributes on every server.
121 for attr in ['telephonenumber', 'facsimiletelephonenumber', 'roomnumber']:
122 assert UserAccount(SUPPLIER1, f'uid=scarter,ou=People,{DEFAULT_SUFFIX}').get_attr_val(attr)
123 assert UserAccount(SUPPLIER2, f'uid=scarter,ou=People,{DEFAULT_SUFFIX}').get_attr_val(attr)
124 # The attributes should be present on the two suppliers with
125 # traditional replication agreements
126 for attr in ['telephonenumber', 'facsimiletelephonenumber', 'roomnumber']:
127 assert not UserAccount(CONSUMER1,
128 f'uid=scarter,ou=People,{DEFAULT_SUFFIX}').get_attr_val(attr)
129 assert not UserAccount(CONSUMER2,
130 f'uid=scarter,ou=People,{DEFAULT_SUFFIX}').get_attr_val(attr)
131
132
133 def test_read_only_consumer(_create_entries):
134 """Attempt to modify an entry on read-only consumer.
135
136 :id: f97f0fea-38ea-11ea-a617-8c16451d917b
137 :setup: Supplier and Consumer
138 :steps:
139 1. Add test entry
140 2. First attempt to modify an attribute that should be visible (mail)
141 3. Then attempt to modify one that should not be visible (roomnumber)
142 :expectedresults:
143 1. Success
144 2. Fail(ldap.INSUFFICIENT_ACCESS)
145 3. Fail(ldap.INSUFFICIENT_ACCESS)
146 """
147 # Add test entry
148 user_consumer1 = UserAccount(CONSUMER1, f'uid=scarter,ou=People,{DEFAULT_SUFFIX}')
149 user_consumer2 = UserAccount(CONSUMER2, f'uid=scarter,ou=People,{DEFAULT_SUFFIX}')
150 # First attempt to modify an attribute that should be visible (mail)
151 for attr, value in [('mail', '[email protected]'), ('roomnumber', '123')]:
152 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
153 user_consumer1.replace(attr, value)
154 # Then attempt to modify one that should not be visible (room number)
155 for attr, value in [('mail', '[email protected]'), ('roomnumber', '123')]:
156 with pytest.raises(ldap.INSUFFICIENT_ACCESS):
157 user_consumer2.replace(attr, value)
158
159
160 def test_read_write_supplier(_create_entries):
161 """Attempt to modify an entry on read-write supplier
162
163 :id: ff50a8b6-38ea-11ea-870f-8c16451d917b
164 :setup: Supplier and Consumer
165 :steps:
166 1. Add test entry
167 2. First attempt to modify an attribute that should be visible (mail)
168 3. Then attempt to modify one that should not be visible (roomnumber)
169 4. The change to mail should appear on all servers; the change to
170 room number should only appear on the suppliers INST[0] and INST[1].
171 :expectedresults:
172 1. Success
173 2. Success
174 3. Success
175 4. Success
176 """
177 # Add test entry
178 user_supplier1 = UserAccount(SUPPLIER1, f'uid=scarter,ou=People,{DEFAULT_SUFFIX}')
179 # First attempt to modify an attribute that should be visible (mail)
180 for attr, value in [('mail', '[email protected]'), ('roomnumber', '123')]:
181 user_supplier1.replace(attr, value)
182 check_all_replicated()
183 for ins, attr in [(SUPPLIER2, 'mail'),
184 (SUPPLIER2, 'roomnumber'),
185 (CONSUMER1, 'mail'),
186 (CONSUMER2, 'mail')]:
187 if attr == 'mail':
188 assert UserAccount(ins,
189 f'uid=scarter,'
190 f'ou=People,{DEFAULT_SUFFIX}').get_attr_val_utf8(attr) == \
191 '[email protected]'
192 elif attr == 'roomnumber':
193 assert UserAccount(ins,
194 f'uid=scarter,'
195 f'ou=People,{DEFAULT_SUFFIX}').get_attr_val_utf8(attr) == '123'
196 # Attempt to modify one that should not be visible (room number)
197 for ins in [CONSUMER1, CONSUMER2]:
198 assert not UserAccount(ins,
199 f'uid=scarter,ou=People,{DEFAULT_SUFFIX}').get_attr_val('roomnumber')
200
201
202 def test_filtered_attributes(_create_entries):
203 """Filtered attributes are not replicated to CONSUMER1 or CONSUMER2.
204
205 :id: 051b40ee-38eb-11ea-9126-8c16451d917b
206 :setup: Supplier and Consumer
207 :steps:
208 1. Add a new entry to SUPPLIER1.
209 2. Confirm that it is replicated in entirety
210 to SUPPLIER2, but that filtered attributes are not replicated to
211 CONSUMER1 or CONSUMER2.
212 3. The entry should be present in all servers. Filtered attributes should not
213 be available from the consumers with fractional replication agreements.
214 :expectedresults:
215 1. Success
216 2. Success
217 3. Success
218 """
219 # Add a new entry to SUPPLIER1.
220 users = UserAccounts(SUPPLIER1, DEFAULT_SUFFIX)
221 _create_users(users, 'Anuj Borah', 'aborah', 'Anuj', 'People', 'ok',
222 'aborah', '[email protected]', '+1121', '+121', '2121')
223 check_all_replicated()
224 for instance in [SUPPLIER1, SUPPLIER2, CONSUMER1, CONSUMER2]:
225 assert UserAccount(instance,
226 f'uid=aborah,'
227 f'ou=People,{DEFAULT_SUFFIX}').get_attr_val_utf8('mail') == \
228 '[email protected]'
229 for instance in [SUPPLIER1, SUPPLIER2]:
230 assert UserAccount(instance,
231 f'uid=aborah,'
232 f'ou=People,{DEFAULT_SUFFIX}').get_attr_val_utf8('roomnumber') == '2121'
233 # The entry should be present in all servers. Filtered attributes should not
234 # be available from the consumers with fractional replication agreements.
235 for instance in [CONSUMER1, CONSUMER2]:
236 assert not UserAccount(instance,
237 f'uid=aborah,'
238 f'ou=People,{DEFAULT_SUFFIX}').get_attr_val_utf8('roomnumber')
239
240
241 def test_fewer_changes_in_single_operation(_create_entries):
242 """For bug 154948, which cause the server to crash if there were
243 fewer changes (but more than one) in a single operation to fractionally
244 replicated attributes than the number of fractionally replicated attributes.
245 The primary test is that all servers are still alive.
246
247 :id: 0d1d6218-38eb-11ea-8945-8c16451d917b
248 :setup: Supplier and Consumer
249 :steps:
250 1. Add a new entry to SUPPLIER1.
251 2. Fewer changes (but more than one) in a single operation to fractionally
252 replicated attributes than the number of fractionally replicated attributes.
253 3. All servers are still alive.
254 :expectedresults:
255 1. Success
256 2. Success
257 3. Success
258 """
259 users = UserAccounts(SUPPLIER1, DEFAULT_SUFFIX)
260 user = _create_users(users, 'Anuj Borah1', 'aborah1', 'Anuj1', 'People',
261 'ok1', 'aborah1', '[email protected]', '+11212', '+1212', '21231')
262 check_all_replicated()
263 # Fewer changes (but more than one) in a single operation to fractionally
264 # replicated attributes than the number of fractionally replicated attributes.
265 user.replace_many(('carLicense', '111-1111'), ('description', 'Hi'))
266 check_all_replicated()
267 user.replace_many(('mail', '[email protected]'), ('sn', 'Oak'), ('l', 'NewPlace'))
268 check_all_replicated()
269 # All servers are still alive.
270 for ints in [SUPPLIER1, SUPPLIER2, CONSUMER1, CONSUMER2]:
271 assert UserAccount(ints, user.dn).get_attr_val_utf8('mail') == '[email protected]'
272 assert UserAccount(ints, user.dn).get_attr_val_utf8('sn') == 'Oak'
273
274
275 @pytest.fixture(scope="function")
276 def _add_user_clean(request):
277 # Enabling memberOf plugin and then adding few groups with member attributes.
278 MemberOfPlugin(SUPPLIER1).enable()
279 for instance in (SUPPLIER1, SUPPLIER2):
280 instance.restart()
281 user1 = UserAccounts(SUPPLIER1, DEFAULT_SUFFIX).create_test_user()
282 for attribute, value in [("displayName", "Anuj Borah"),
283 ("givenName", "aborah"),
284 ("telephoneNumber", "+1 555 999 333"),
285 ("roomnumber", "123"),
286 ("manager", f'uid=dsmith,ou=People,{DEFAULT_SUFFIX}')]:
287 user1.set(attribute, value)
288 grp = Groups(SUPPLIER1, DEFAULT_SUFFIX).create(properties={
289 "cn": "bug739172_01group",
290 "member": f'uid=test_user_1000,ou=People,{DEFAULT_SUFFIX}'
291 })
292
293 def final_call():
294 """
295 Removes User and Group after the test.
296 """
297 user1.delete()
298 grp.delete()
299 request.addfinalizer(final_call)
300
301
302 def test_newly_added_attribute_nsds5replicatedattributelisttotal(_create_entries, _add_user_clean):
303 """This test case is to test the newly added attribute nsds5replicatedattributelistTotal.
304
305 :id: 2df5971c-38eb-11ea-9e8e-8c16451d917b
306 :setup: Supplier and Consumer
307 :steps:
308 1. Enabling memberOf plugin and then adding few groups with member attributes.
309 2. No memberOf plugin enabled on read only replicas
310 3. The attributes mentioned in the nsds5replicatedattributelist
311 excluded from incremental updates.
312 :expectedresults:
313 1. Success
314 2. Success
315 3. Success
316 """
317 check_all_replicated()
318 user = f'uid=test_user_1000,ou=People,{DEFAULT_SUFFIX}'
319 for instance in (SUPPLIER1, SUPPLIER2, CONSUMER1, CONSUMER2):
320 g = Groups(instance, DEFAULT_SUFFIX).get('bug739172_01group')
321 assert g.get_attr_val_utf8("member") == user
322 assert UserAccount(instance, user).get_attr_val_utf8("sn") == "test_user_1000"
323 # The attributes mentioned in the nsds5replicatedattributelist
324 # excluded from incremental updates.
325 for instance in (CONSUMER1, CONSUMER2):
326 for value in ("roomnumber", "manager", "telephoneNumber"):
327 assert not UserAccount(instance, user).get_attr_val_utf8(value)
328
329
330 def test_attribute_nsds5replicatedattributelisttotal(_create_entries, _add_user_clean):
331 """This test case is to test the newly added attribute nsds5replicatedattributelistTotal.
332
333 :id: 35de9ff0-38eb-11ea-b420-8c16451d917b
334 :setup: Supplier and Consumer
335 :steps:
336 1. Add a new entry to SUPPLIER1.
337 2. Enabling memberOf plugin and then adding few groups with member attributes.
338 3. No memberOf plugin enabled in other consumers,ie., the read only replicas
339 won't get incremental updates for the attributes mentioned in the list.
340 4. Run total update and verify the same attributes added/modified in the read-only replicas.
341 :expectedresults:
342 1. Success
343 2. Success
344 3. Success
345 4. Success
346 """
347 # Run total update and verify the same attributes added/modified in the read-only replicas.
348 user = f'uid=test_user_1000,ou=People,{DEFAULT_SUFFIX}'
349 for agreement in Agreements(SUPPLIER1).list():
350 agreement.begin_reinit()
351 agreement.wait_reinit()
352 check_all_replicated()
353 for instance in (SUPPLIER1, SUPPLIER2):
354 assert Groups(SUPPLIER1, DEFAULT_SUFFIX).list()[1].get_attr_val_utf8("member") == user
355 assert UserAccount(instance, user).get_attr_val_utf8("sn") == "test_user_1000"
356 for instance in (CONSUMER1, CONSUMER2):
357 for value in ("memberOf", "manager", "sn"):
358 assert UserAccount(instance, user).get_attr_val_utf8(value)
359
360
361 def test_implicit_replication_of_password_policy(_create_entries):
362 """For bug 800173, we want to cause the implicit replication of password policy
363 attributes due to failed bind operations
364 we want to make sure that replication still works despite
365 the policy attributes being removed from the update leaving an empty
366 modify operation
367
368 :id: 3f4affe8-38eb-11ea-8936-8c16451d917b
369 :setup: Supplier and Consumer
370 :steps:
371 1. Add a new entry to SUPPLIER1.
372 2. Try binding user with correct password
373 3. Try binding user with incorrect password (twice)
374 4. Make sure user got locked
375 5. Run total update and verify the same attributes added/modified in the read-only replicas.
376 :expectedresults:
377 1. Success
378 2. Success
379 3. FAIL(ldap.INVALID_CREDENTIALS)
380 4. Success
381 5. Success
382 """
383 for attribute, value in [("passwordlockout", "on"),
384 ("passwordmaxfailure", "1")]:
385 Config(SUPPLIER1).set(attribute, value)
386 user = UserAccounts(SUPPLIER1, DEFAULT_SUFFIX).create_test_user()
387 user.set("userpassword", "ItsmeAnuj")
388 check_all_replicated()
389 assert UserAccount(SUPPLIER2, user.dn).get_attr_val_utf8("uid") == "test_user_1000"
390 # Try binding user with correct password
391 conn = UserAccount(SUPPLIER2, user.dn).bind("ItsmeAnuj")
392 with pytest.raises(ldap.INVALID_CREDENTIALS):
393 UserAccount(SUPPLIER1, user.dn).bind("badpass")
394 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
395 UserAccount(SUPPLIER1, user.dn).bind("badpass")
396 # asserting user got locked
397 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
398 conn = UserAccount(SUPPLIER1, user.dn).bind("ItsmeAnuj")
399 check_all_replicated()
400 # modify user and verify that replication is still working
401 user.replace("seealso", "cn=seealso")
402 check_all_replicated()
403 for instance in (SUPPLIER1, SUPPLIER2):
404 assert UserAccount(instance, user.dn).get_attr_val_utf8("seealso") == "cn=seealso"
405
406
407 # --- Two-supplier fractional replication (CSN evaluation, description sync) ---
408
409 FRACTIONAL_M2_STAGING_ACCOUNT = "new_account"
410 FRACTIONAL_M2_STAGING_COUNT = 20
411
412
413 def _fractional_m2_agreement_list(inst):
414 return Replicas(inst).get(DEFAULT_SUFFIX).get_agreements().list()
415
416
417 @pytest.fixture(scope="function")
418 def fractional_m2_setup(request, topology_m2):
419 """Create entries, tune logs, and configure fractional replication on both suppliers."""
420 supplier1 = topology_m2.ms["supplier1"]
421 supplier2 = topology_m2.ms["supplier2"]
422
423 users = UserAccounts(supplier1, DEFAULT_SUFFIX)
424 for cpt in range(FRACTIONAL_M2_STAGING_COUNT):
425 name = f"{FRACTIONAL_M2_STAGING_ACCOUNT}{cpt}"
426 props = {"uid": name, "sn": name, "cn": name,
427 "uidNumber": str(cpt), "gidNumber": str(cpt),
428 "homeDirectory": f"/home/{name}"}
429 user = users.create(properties=props)
430
431 Config(supplier1).set("nsslapd-accesslog-logbuffering", "off")
432 Config(supplier1).set("nsslapd-errorlog-level", "8192")
433 Config(supplier1).set("nsslapd-accesslog-level", "260")
434
435 Config(supplier2).set("nsslapd-accesslog-logbuffering", "off")
436 Config(supplier2).set("nsslapd-errorlog-level", "8192")
437 Config(supplier2).set("nsslapd-accesslog-level", "260")
438
439 assert len(_fractional_m2_agreement_list(supplier1)) == 1
440 assert len(_fractional_m2_agreement_list(supplier2)) == 1
441
442 fractional = (
443 ("nsDS5ReplicatedAttributeList", "(objectclass=*) $ EXCLUDE telephonenumber"),
444 ("nsds5ReplicaStripAttrs", "modifiersname modifytimestamp"),
445 )
446 for inst in (supplier1, supplier2):
447 _fractional_m2_agreement_list(inst)[0].replace_many(*fractional)
448
449 r1 = Replicas(supplier1).get(DEFAULT_SUFFIX)
450 r2 = Replicas(supplier2).get(DEFAULT_SUFFIX)
451
452 r1.replace('nsds5ReplicaKeepAliveUpdateInterval', '60')
453 r2.replace('nsds5ReplicaKeepAliveUpdateInterval', '60')
454
455 supplier1.restart()
456 supplier2.restart()
457
458 repl = ReplicationManager(DEFAULT_SUFFIX)
459 repl.ensure_agreement(supplier1, supplier2)
460 repl.test_replication(supplier1, supplier2)
461
462 def fin():
463 for cpt in range(FRACTIONAL_M2_STAGING_COUNT):
464 name = f"{FRACTIONAL_M2_STAGING_ACCOUNT}{cpt}"
465 user = UserAccounts(supplier1, DEFAULT_SUFFIX).get(name)
466 user.delete()
467 supplier1.restart()
468 supplier2.restart()
469 repl = ReplicationManager(DEFAULT_SUFFIX)
470 repl.ensure_agreement(supplier1, supplier2)
471 repl.test_replication(supplier1, supplier2)
472
473 request.addfinalizer(fin)
474
475 yield SimpleNamespace(
476 topology_m2=topology_m2,
477 supplier1=supplier1,
478 supplier2=supplier2,
479 )
480
481
482 def _parse_csn_line(line):
483 """ Helper function to extract the CSN from a line """
484 parsed = {item.split('=')[0]: item.split('=')[1] for item in line['rem'].split()}
485 return parsed['csn']
486
487
488 def _fractional_m2_get_unreplicated_csn(supplier1, dn):
489 """CSN for a telephoneNumber change (not replicated fractionally)."""
490 UserAccount(supplier1, dn).replace("telephonenumber", "123456")
491
492 raw = supplier1.getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)", ["nscpentrywsi"])
493 nscp_vals = raw.getValues("nscpentrywsi")
494 assert nscp_vals
495 tel_line = None
496 for val in nscp_vals:
497 if ensure_str(val.lower()).startswith("telephonenumber"):
498 tel_line = val
499 break
500 assert tel_line
501
502 found_ops = supplier1.ds_access_log.match(f".*MOD dn=\"{dn}\".*")
503 assert len(found_ops) > 0
504 found_op = supplier1.ds_access_log.parse_line(found_ops[-1])
505
506 found_csns = supplier1.ds_access_log.match(
507 f".*conn={found_op['conn']} op={found_op['op']} RESULT.*")
508 assert len(found_csns) > 0
509
510 found_csn = supplier1.ds_access_log.parse_line(found_csns[-1])
511 return _parse_csn_line(found_csn)
512
513
514 def _fractional_m2_count_full_session(supplier1):
515 pattern = ".*No more updates to send.*"
516 regex = re.compile(pattern)
517 no_more_updates = 0
518 with open(supplier1.errlog, "r") as file_obj:
519 while True:
520 line = file_obj.readline()
521 if regex.search(line):
522 no_more_updates = no_more_updates + 1
523 if line == "":
524 break
525 return no_more_updates
526
527
528 def test_fractional_m2_replication(topology_m2, fractional_m2_setup):
529 """Replication works between two suppliers after fractional agreement configuration.
530
531 :id: a7f39c2e-4b1d-42f8-9e63-8d501a6c2f94
532 :setup: Two suppliers (topology_m2), fractional_m2_setup
533 :steps:
534 1. Confirm a single replication agreement exists on supplier1.
535 2. Ensure the agreement from supplier1 to supplier2 exists and run a replication check.
536 :expectedresults:
537 1. Success
538 2. Success
539 """
540 ents = _fractional_m2_agreement_list(topology_m2.ms["supplier1"])
541 assert len(ents) == 1
542
543 repl = ReplicationManager(DEFAULT_SUFFIX)
544 repl.ensure_agreement(topology_m2.ms["supplier1"], topology_m2.ms["supplier2"])
545 repl.test_replication(topology_m2.ms["supplier1"], topology_m2.ms["supplier2"])
546
547
548 def test_fractional_m2_replicated_description(topology_m2, fractional_m2_setup):
549 """A non-fractional attribute modified on supplier1 appears on supplier2.
550
551 :id: b3e81d5f-6c2e-53a9-af74-9e612b7d3ea5
552 :setup: Two suppliers (topology_m2), fractional_m2_setup
553 :steps:
554 1. Set description on a staging user on supplier1.
555 2. Poll supplier2 until the same description value is present on the entry.
556 :expectedresults:
557 1. Success
558 2. Success within the wait loop
559 """
560 name = f"{FRACTIONAL_M2_STAGING_ACCOUNT}1"
561 users = UserAccounts(topology_m2.ms["supplier1"], DEFAULT_SUFFIX)
562 user = users.get(name)
563 description = "check repl. description"
564 user.set("description", description)
565
566 ReplicationManager(DEFAULT_SUFFIX).wait_for_replication(topology_m2.ms["supplier1"], topology_m2.ms["supplier2"])
567 ent = topology_m2.ms["supplier2"].getEntry(user.dn, ldap.SCOPE_BASE, "(objectclass=*)")
568 assert ent.hasAttr("description") and ent.getValue("description") == ensure_bytes(description)
569
570
571 def _wait_for_replication_sessions_to_complete(supplier1, no_more_update_cnt):
572 max_loop = 10
573 cnt = 0
574 current_no_more_update = _fractional_m2_count_full_session(supplier1)
575 while current_no_more_update == no_more_update_cnt:
576 cnt = cnt + 1
577 if cnt > max_loop:
578 assert False, f"Timeout waiting for replication sessions to complete after {cnt} loops"
579 time.sleep(5)
580 current_no_more_update = _fractional_m2_count_full_session(supplier1)
581
582 return current_no_more_update
583
584 def test_fractional_m2_csn_evaluation_count(topology_m2, fractional_m2_setup):
585 """Verify that the CSN evaluation count is correct
586
587 :id: c9f54a8b-7d3f-64ba-b085-0f723c8e4fb6
588 :setup: Two suppliers (topology_m2), fractional_m2_setup
589 :steps:
590 1. Record a CSN for a telephoneNumber change that is not replicated (fractional exclude).
591 2. Pause the agreement, apply many telephoneNumber updates on supplier1, resume and wait
592 for replication sessions to complete.
593 3. Drive further non-replicated updates and waits; scan the error log after the last CSN
594 ruv line and assert first CSN is reported with "Skipping update operation" message.
595 :expectedresults:
596 1. Success
597 2. Success
598 3. Success
599 """
600 supplier1 = topology_m2.ms["supplier1"]
601 assert len(_fractional_m2_agreement_list(supplier1)) == 1
602 dn2 = f"uid={FRACTIONAL_M2_STAGING_ACCOUNT}2,ou=people,{DEFAULT_SUFFIX}"
603 first_csn = _fractional_m2_get_unreplicated_csn(supplier1, dn2)
604
605 dn = f"uid={FRACTIONAL_M2_STAGING_ACCOUNT}3,ou=people,{DEFAULT_SUFFIX}"
606 user = UserAccount(supplier1, dn)
607 nb_session = 102
608
609 no_more_update_cnt = _fractional_m2_count_full_session(supplier1)
610 agmt = _fractional_m2_agreement_list(supplier1)[0]
611 agmt.pause()
612 for tel_number in range(nb_session):
613 user.replace("telephonenumber", str(tel_number))
614
615 agmt.resume()
616 time.sleep(65)
617
618 current_no_more_update = _wait_for_replication_sessions_to_complete(supplier1, no_more_update_cnt)
619 log.info(
620 f"after {nb_session} MODs we have completed {(current_no_more_update - no_more_update_cnt)} replication sessions")
621 no_more_update_cnt = current_no_more_update
622
623 dn5 = f"uid={FRACTIONAL_M2_STAGING_ACCOUNT}5,ou=people,{DEFAULT_SUFFIX}"
624 last_csn = _fractional_m2_get_unreplicated_csn(supplier1, dn5)
625
626 current_no_more_update = _wait_for_replication_sessions_to_complete(supplier1, no_more_update_cnt)
627 log.info(
628 f"This MODs {last_csn} triggered the send of the dummy update completed {(current_no_more_update - no_more_update_cnt)} replication sessions")
629 no_more_update_cnt = current_no_more_update
630
631 agmt = _fractional_m2_agreement_list(supplier1)[0]
632 agmt.pause()
633 last_csn = _fractional_m2_get_unreplicated_csn(supplier1, dn5)
634 agmt.resume()
635
636 current_no_more_update = _wait_for_replication_sessions_to_complete(supplier1, no_more_update_cnt)
637 log.info(
638 f"This MODs {last_csn} completed in {(current_no_more_update - no_more_update_cnt)} replication sessions, should be sent without evaluating {first_csn}")
639 no_more_update_cnt = current_no_more_update
640
641 pattern = f".*ruv_add_csn_inprogress - Successfully inserted csn {last_csn}.*"
642 regex = re.compile(pattern)
643 found_ruv = None
644
645 with open(supplier1.errlog, "r") as file_obj:
646 while True:
647 line = file_obj.readline()
648 if regex.search(line):
649 found_ruv = line
650 break
651 if line == "":
652 break
653 assert found_ruv
654 log.info(f"Last operation was found at {file_obj.tell()}")
655 log.info(found_ruv)
656
657 log.info(f"Now check the first csn {first_csn} is not present in the log")
658
659 pattern_skip = f".*Skipping update operation.*CSN {first_csn}.*"
660 regex_skip = re.compile(pattern_skip)
661 found_skip = False
662 while True:
663 line = file_obj.readline()
664 if regex_skip.search(line):
665 found_skip = True
666 break
667 if line == "":
668 break
669 assert not found_skip
670 log.info(f"First csn {first_csn} not found in the log")
671
672
673 if __name__ == '__main__':
674 CURRENT_FILE = os.path.realpath(__file__)
675 pytest.main("-s -v %s" % CURRENT_FILE)