Debian Codegraph @

dirsrvtests/tests/suites/replication/changelog_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2017 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 os
10 import logging
11 import ldap
12 import ldif
13 import pytest
14 import time
15 import subprocess
16 import glob
17 import re
18 from lib389.properties import TASK_WAIT
19 from lib389.replica import Changelog, Changelog5, Replicas
20 from lib389.idm.user import UserAccounts
21 from test389.topologies import topology_m2 as topo
22 from lib389._constants import (
23 BDB_CL_FILENAME,
24 DEFAULT_BENAME,
25 DEFAULT_CHANGELOG_DB,
26 DEFAULT_SUFFIX,
27 DN_DM,
28 DN_USERROOT_LDBM,
29 HOST_SUPPLIER_1,
30 PASSWORD,
31 PORT_SUPPLIER_1,
32 )
33 from lib389.plugins import RetroChangelogPlugin
34 from lib389.dseldif import DSEldif
35 from lib389.utils import (
36 ds_is_older,
37 ds_supports_new_changelog,
38 ensure_bytes,
39 )
40
41 pytestmark = pytest.mark.tier1
42
43 TEST_ENTRY_NAME = 'replusr'
44 NEW_RDN_NAME = 'cl5usr'
45 if ds_supports_new_changelog():
46 CHANGELOG = 'cn=changelog,{}'.format(DN_USERROOT_LDBM)
47 else:
48 CHANGELOG = 'cn=changelog5,cn=config'
49 RETROCHANGELOG = 'cn=Retro Changelog Plugin,cn=plugins,cn=config'
50 MAXAGE = 'nsslapd-changelogmaxage'
51 TRIMINTERVAL = 'nsslapd-changelogtrim-interval'
52 COMPACTDBINTERVAL = 'nsslapd-changelogcompactdb-interval'
53 FILTER = '(cn=*)'
54
55 DEBUGGING = os.getenv('DEBUGGING', default=False)
56 if DEBUGGING:
57 logging.getLogger(__name__).setLevel(logging.DEBUG)
58 else:
59 logging.getLogger(__name__).setLevel(logging.INFO)
60 log = logging.getLogger(__name__)
61
62
63 def _check_repl_changelog_backup(instance, backup_dir):
64 # Note: there is no way to check dbi on lmdb backup
65 # That said dbscan may perhaps do it ...
66 if instance.get_db_lib() == 'bdb':
67 if ds_supports_new_changelog():
68 backup_checkdir = os.path.join(backup_dir, DEFAULT_BENAME, BDB_CL_FILENAME)
69 else:
70 backup_checkdir = os.path.join(backup_dir, '.repl_changelog_backup', DEFAULT_CHANGELOG_DB)
71 if glob.glob(f'{backup_checkdir}*'):
72 log.info('Database backup is created successfully')
73 else:
74 log.fatal('test_changelog5: backup directory does not exist : {}*'.format(backup_checkdir))
75 assert False
76
77
78 def _perform_ldap_operations(topo):
79 """Add a test user, modify description, modrdn user and delete it"""
80
81 log.info('Adding user {}'.format(TEST_ENTRY_NAME))
82 users = UserAccounts(topo.ms['supplier1'], DEFAULT_SUFFIX)
83 user_properties = {
84 'uid': TEST_ENTRY_NAME,
85 'cn': TEST_ENTRY_NAME,
86 'sn': TEST_ENTRY_NAME,
87 'uidNumber': '1001',
88 'gidNumber': '2001',
89 'userpassword': PASSWORD,
90 'description': 'userdesc',
91 'homeDirectory': '/home/{}'.format(TEST_ENTRY_NAME)}
92 tuser = users.create(properties=user_properties)
93 tuser.replace('description', 'newdesc')
94 log.info('Modify RDN of user {}'.format(tuser.dn))
95 try:
96 topo.ms['supplier1'].modrdn_s(tuser.dn, 'uid={}'.format(NEW_RDN_NAME), 0)
97 except ldap.LDAPError as e:
98 log.fatal('Failed to modrdn entry {}'.format(tuser.dn))
99 raise e
100 tuser = users.get(NEW_RDN_NAME)
101 log.info('Deleting user: {}'.format(tuser.dn))
102 tuser.delete()
103
104
105 def _create_changelog_dump(topo):
106 """Dump changelog using nss5task and check if ldap operations are logged"""
107
108 log.info('Dump changelog using nss5task and check if ldap operations are logged')
109 if ds_supports_new_changelog():
110 changelog_dir = topo.ms['supplier1'].get_ldif_dir()
111 changelog_end = '_cl.ldif'
112 else:
113 changelog_dir = topo.ms['supplier1'].get_changelog_dir()
114 changelog_end = '.ldif'
115 replicas = Replicas(topo.ms["supplier1"])
116 replica = replicas.get(DEFAULT_SUFFIX)
117 log.info('Remove ldif files, if present in: {}'.format(changelog_dir))
118 for files in os.listdir(changelog_dir):
119 if files.endswith(changelog_end):
120 changelog_file = os.path.join(changelog_dir, files)
121 try:
122 os.remove(changelog_file)
123 except OSError as e:
124 log.fatal('Failed to remove ldif file: {}'.format(changelog_file))
125 raise e
126 log.info('Existing changelog ldif file: {} removed'.format(changelog_file))
127 else:
128 log.info('No existing changelog ldif files present')
129
130 log.info('Running nsds5task to dump changelog database to a file')
131 replica.begin_task_cl2ldif()
132
133 log.info('Check if changelog ldif file exist in: {}'.format(changelog_dir))
134 for files in os.listdir(changelog_dir):
135 if files.endswith(changelog_end):
136 changelog_ldif = os.path.join(changelog_dir, files)
137 log.info('Changelog ldif file exist: {}'.format(changelog_ldif))
138 return changelog_ldif
139 else:
140 log.fatal('Changelog ldif file does not exist in: {}'.format(changelog_dir))
141 assert False
142
143
144 def _check_changelog_ldif(topo, changelog_ldif):
145 """Check changelog ldif file for required ldap operations"""
146
147 log.info('Checking changelog ldif file for ldap operations')
148 assert os.stat(changelog_ldif).st_size > 0, 'Changelog file has no contents'
149 with open(changelog_ldif, 'r') as fh:
150 content = fh.read()
151 ldap_operations = set()
152 log.info('Checking if all required changetype operations are present')
153 for entry_ldif in content.split('\n\n'):
154 for line in entry_ldif.split('\n'):
155 if line.startswith('changetype: '):
156 ldap_operations.add(line.split(': ')[1])
157 valid_operations = set(ldif.valid_changetype_dict.keys())
158 log.info('Valid ldap operations: {}'.format(valid_operations))
159 log.info('Ldap operations found: {}'.format(ldap_operations))
160 assert ldap_operations == valid_operations, 'Changelog ldif file does not contain all \
161 changetype operations'
162
163
164 def get_ldap_error_msg(e, type):
165 return e.args[0][type]
166
167
168 @pytest.fixture(scope="module")
169 def changelog_init(topo):
170 """ changlog dir is not configuarable, just
171 enable cn=Retro Changelog Plugin,cn=plugins,cn=config
172 """
173 log.info('Testing Ticket 47669 - Test duration syntax in the changelogs')
174
175 # bind as directory manager
176 topo.ms["supplier1"].log.info("Bind as %s" % DN_DM)
177 topo.ms["supplier1"].simple_bind_s(DN_DM, PASSWORD)
178
179 if not ds_supports_new_changelog():
180 try:
181 changelogdir = os.path.join(os.path.dirname(topo.ms["supplier1"].dbdir), 'changelog')
182 topo.ms["supplier1"].modify_s(CHANGELOG, [(ldap.MOD_REPLACE, 'nsslapd-changelogdir',
183 ensure_bytes(changelogdir))])
184 except ldap.LDAPError as e:
185 log.error('Failed to modify ' + CHANGELOG + ': error {}'.format(get_ldap_error_msg(e,'desc')))
186 assert False
187
188 try:
189 topo.ms["supplier1"].modify_s(RETROCHANGELOG, [(ldap.MOD_REPLACE, 'nsslapd-pluginEnabled', b'on')])
190 except ldap.LDAPError as e:
191 log.error('Failed to enable ' + RETROCHANGELOG + ': error {}'.format(get_ldap_error_msg(e, 'desc')))
192 assert False
193
194 # restart the server
195 topo.ms["supplier1"].restart(timeout=10)
196
197
198 def add_and_check(topo, plugin, attr, val, isvalid):
199 """
200 Helper function to add/replace attr: val and check the added value
201 """
202 if isvalid:
203 log.info('Test %s: %s -- valid' % (attr, val))
204 try:
205 topo.ms["supplier1"].modify_s(plugin, [(ldap.MOD_REPLACE, attr, ensure_bytes(val))])
206 except ldap.LDAPError as e:
207 log.error('Failed to add ' + attr + ': ' + val + ' to ' + plugin + ': error {}'.format(get_ldap_error_msg(e,'desc')))
208 assert False
209 else:
210 log.info('Test %s: %s -- invalid' % (attr, val))
211 if plugin == CHANGELOG:
212 try:
213 topo.ms["supplier1"].modify_s(plugin, [(ldap.MOD_REPLACE, attr, ensure_bytes(val))])
214 except ldap.LDAPError as e:
215 log.error('Expectedly failed to add ' + attr + ': ' + val +
216 ' to ' + plugin + ': error {}'.format(get_ldap_error_msg(e,'desc')))
217 else:
218 try:
219 topo.ms["supplier1"].modify_s(plugin, [(ldap.MOD_REPLACE, attr, ensure_bytes(val))])
220 except ldap.LDAPError as e:
221 log.error('Failed to add ' + attr + ': ' + val + ' to ' + plugin + ': error {}'.format(get_ldap_error_msg(e,'desc')))
222
223 try:
224 entries = topo.ms["supplier1"].search_s(plugin, ldap.SCOPE_BASE, FILTER, [attr])
225 if isvalid:
226 if not entries[0].hasValue(attr, val):
227 log.fatal('%s does not have expected (%s: %s)' % (plugin, attr, val))
228 assert False
229 else:
230 if entries[0].hasValue(attr, val):
231 log.fatal('%s has unexpected (%s: %s)' % (plugin, attr, val))
232 assert False
233
234 except ldap.LDAPError as e:
235 log.fatal('Unable to search for entry %s: error %s' % (plugin, e.message['desc']))
236 assert False
237
238 def remove_ldif_files_from_changelogdir(topo, extension):
239 """
240 Remove existing ldif files from changelog dir
241 """
242 if ds_supports_new_changelog():
243 changelog_dir = topo.ms['supplier1'].get_ldif_dir()
244 else:
245 changelog_dir = topo.ms['supplier1'].get_changelog_dir()
246
247 log.info('Remove %s files, if present in: %s' % (extension, changelog_dir))
248 for files in os.listdir(changelog_dir):
249 if files.endswith(extension):
250 changelog_file = os.path.join(changelog_dir, files)
251 try:
252 os.remove(changelog_file)
253 except OSError as e:
254 log.fatal('Failed to remove %s file: %s' % (extension,changelog_file))
255 raise e
256 else:
257 log.info('Existing changelog %s file: %s removed' % (extension,changelog_file))
258
259
260 @pytest.mark.xfail(ds_is_older('1.3.10.1', '1.4.3'), reason="bug bz1685059")
261 @pytest.mark.skip(reason="does not work for prefix builds")
262 def test_cldump_files_removed(topo):
263 """Verify bz1685059 : cl-dump generated ldif files are removed at the end, -l option is the way to keep them
264
265 :id: fbb2f2a3-167b-4bc6-b513-9e0318b09edc
266 :setup: Replication with two supplier, nsslapd-changelogdir is '/var/lib/dirsrv/slapd-supplier1/changelog'
267 retrochangelog plugin disabled
268 :steps:
269 1. Clean the changelog directory, removing .ldif files present, if any
270 2. Clean the changelog directory, removing .done files present, if any
271 3. Perform ldap operations to record replication changes
272 4. Try a cl-dump call with invalid arguments to secure the next steps and to check bz1769296
273 5. Launch cl-dump cli without -l option
274 6. Wait so that all cl-dump tasks be finished
275 7. Check that all .ldif.done generated files have been removed from the changelog dir
276 8. Launch cl-dump cli with -l option
277 9. Wait so that all cl-dump tasks be finished
278 10. Check that the generated .ldif.done files are present in the changelog dir
279
280 :expectedresults:
281 1. No remaining .ldif file in the changelog directory
282 2. No remaining .ldif.done file in the changelog directory
283 3. ldap operations are replicated and recorded in changelog
284 4. A result code different from 0 is raised
285 5. cl-dump is successfully executed
286 6. cl-dump process has finished
287 7. No .ldif.done files in the changelog dir
288 8. cl-dump is successfully executed
289 9. cl-dump process has finished
290 10. .ldif.done generated files are present in the changelog dir
291 """
292
293 changelog_dir = topo.ms['supplier1'].get_changelog_dir()
294
295 # Remove existing .ldif files in changelog dir
296 remove_ldif_files_from_changelogdir(topo, '.ldif')
297
298 # Remove existing .ldif.done files in changelog dir
299 remove_ldif_files_from_changelogdir(topo, '.done')
300
301 _perform_ldap_operations(topo)
302
303 # This part to make sure that an error in the cl-dump script execution will be detected,
304 # primary condition before executing the core goal of this case : management of cl-dump generated files.
305 # As of today the returned code by cl-dump.pl is incorrect when run with invalid arguments (bz1769296)
306 # This piece of code will serve as reproducer and verification mean for bz1769296
307
308 log.info("Use cl-dump perl script without -l option : no generated ldif files should remain in %s " % changelog_dir)
309 cmdline=['/usr/bin/cl-dump', '-h', HOST_SUPPLIER_1, '-p', 'invalid port', '-D', DN_DM, '-w', PASSWORD]
310 log.info('Command used : %s' % cmdline)
311 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
312 msg = proc.communicate()
313 log.info('output message : %s' % msg[0])
314 assert proc.returncode != 0
315
316 # Now the core goal of the test case
317 # Using cl-dump without -l option
318 log.info("Use cl-dump perl script without -l option : no generated ldif files should remain in %s " % changelog_dir)
319 cmdline=['/usr/bin/cl-dump', '-h', HOST_SUPPLIER_1, '-p', str(PORT_SUPPLIER_1), '-D', DN_DM, '-w', PASSWORD]
320 log.info('Command used : %s' % cmdline)
321 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
322 proc.communicate()
323 assert proc.returncode == 0
324
325 log.info('Wait for all cl-dump files to be generated')
326 time.sleep(1)
327
328 log.info('Check if cl-dump generated .ldif.done files are present - should not')
329 for files in os.listdir(changelog_dir):
330 if files.endswith('.done'):
331 log.fatal('cl-dump generated .ldif.done files are present in %s - they should not' % changelog_dir)
332 assert False
333 else:
334 log.info('All cl-dump generated .ldif files have been successfully removed from %s ' % changelog_dir)
335
336
337 # Using cl-dump with -l option
338 log.info("Use cl-dump perl script with -l option : generated ldif files should be kept in %s " % changelog_dir)
339 cmdline=['/usr/bin/cl-dump', '-h', HOST_SUPPLIER_1, '-p', str(PORT_SUPPLIER_1), '-D', DN_DM, '-w', PASSWORD, '-l']
340 log.info('Command used : %s' % cmdline)
341 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
342 msg = proc.communicate()
343 assert proc.returncode == 0
344
345 log.info('Wait for all cl-dump files to be generated')
346 time.sleep(1)
347
348 log.info('Check if cl-dump generated .ldif.done files are present - should be')
349 for files in os.listdir(changelog_dir):
350 if files.endswith('.done'):
351 cldump_file = os.path.join(changelog_dir, files)
352 log.info('Success : ldif file %s is present' % cldump_file)
353 break
354 else:
355 log.fatal('.ldif.done files are not present in %s - they should be' % changelog_dir)
356 assert False
357
358 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
359 def test_dsconf_dump_changelog_files_removed(topo):
360 """Verify that the python counterpart of cl-dump (using dsconf) has a correct management of generated files
361
362 :id: e41dcf90-098a-4386-acb5-789384579bf7
363 :setup: Replication with two supplier, nsslapd-changelogdir is '/var/lib/dirsrv/slapd-supplier1/changelog'
364 retrochangelog plugin disabled
365 :steps:
366 1. Clean the changelog directory, removing .ldif files present, if any
367 2. Clean the changelog directory, removing .ldif.done files present, if any
368 3. Perform ldap operations to record replication changes
369 4. Try a dsconf call with invalid arguments to secure the next steps
370 5. Launch dsconf export-changelog cli without -l option
371 6. Wait so that all dsconf tasks be finished
372 7. Check that all .ldif.done generated files have been removed from the changelog dir
373 8. Launch dsconf export-changelog cli with -l option
374 9. Wait so that all dsconf tasks be finished
375 10. Check that the generated .ldif.done files are present in the changelog dir
376
377 :expectedresults:
378 1. No remaining .ldif file in the changelog directory
379 2. No remaining .ldif.done file in the changelog directory
380 3. ldap operations are replicated and recorded in changelog
381 4. A result code different from 0 is raised
382 5. dsconf export-changelog is successfully executed
383 6. dsconf process has finished
384 7. No .ldif.done files in the changelog dir
385 8. dsconf export-changelog is successfully executed
386 9. dsconf process has finished
387 10. .ldif.done generated files are present in the changelog dir
388 """
389
390 if ds_supports_new_changelog():
391 changelog_dir = topo.ms['supplier1'].get_ldif_dir()
392 else:
393 changelog_dir = topo.ms['supplier1'].get_changelog_dir()
394 instance = topo.ms['supplier1']
395 instance_url = 'ldap://%s:%s' % (HOST_SUPPLIER_1, PORT_SUPPLIER_1)
396
397 # Remove existing .ldif files in changelog dir
398 remove_ldif_files_from_changelogdir(topo, '.ldif')
399
400 # Remove existing .ldif.done files from changelog dir
401 remove_ldif_files_from_changelogdir(topo, '.done')
402
403 _perform_ldap_operations(topo)
404
405 # This part to make sure that an error in the python dsconf export-changelog execution will be detected,
406 # primary condition before executing the core goal of this case : management of generated files.
407
408 log.info("Use dsconf export-changelog with invalid parameters")
409 cmdline=['/usr/sbin/dsconf', instance_url, '-D', DN_DM, '-w', 'badpasswd', 'replication', 'export-changelog']
410 log.info('Command used : %s' % cmdline)
411 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
412 msg = proc.communicate()
413 log.info('output message : %s' % msg[0])
414 assert proc.returncode != 0
415
416 # Now the core goal of the test case
417 # Using dsconf replication changelog without -l option
418 log.info('Use dsconf replication changelog without -l option: no generated ldif files should be present in %s ' % changelog_dir)
419 cmdline=['/usr/sbin/dsconf', instance_url, '-D', DN_DM, '-w', PASSWORD, 'replication', 'export-changelog',
420 'default', '-r', DEFAULT_SUFFIX]
421 log.info('Command used : %s' % cmdline)
422 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
423 proc.communicate()
424 assert proc.returncode == 0
425
426 log.info('Wait for all dsconf export-changelog files to be generated')
427 time.sleep(1)
428
429 log.info('Check if dsconf export-changelog generated .ldif.done files are present - should not')
430 for files in os.listdir(changelog_dir):
431 if files.endswith('.done'):
432 log.fatal('export-changelog generated .ldif.done files are present in %s - they should not' % changelog_dir)
433 assert False
434 else:
435 log.info('All dsconf export-changelog generated .ldif files have been successfully removed from %s ' % changelog_dir)
436
437 # Using dsconf replication changelog without -l option
438 log.info('Use dsconf replication changelog with -l option: generated ldif files should be kept in %s ' % changelog_dir)
439 cmdline=['/usr/sbin/dsconf', instance_url, '-D', DN_DM, '-w', PASSWORD, 'replication', 'export-changelog',
440 'to-ldif', '-o', changelog_dir + '/test.ldif', '-r', DEFAULT_SUFFIX, '-l']
441 log.info('Command used : %s' % cmdline)
442 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
443 proc.communicate()
444 assert proc.returncode == 0
445
446 log.info('Wait for all dsconf export-changelog files to be generated')
447 time.sleep(1)
448
449 log.info('Check if dsconf export-changelog generated .ldif.done files are present - should be')
450 for files in os.listdir(changelog_dir):
451 if files.endswith('.done'):
452 cldump_file = os.path.join(changelog_dir, files)
453 log.info('Success : ldif file %s is present' % cldump_file)
454 break
455 else:
456 log.fatal('.ldif.done files are not present in %s - they should be' % changelog_dir)
457 assert False
458
459
460 def test_verify_changelog(topo):
461 """Check if changelog dump file contains required ldap operations
462
463 :id: 15ead076-8c18-410b-90eb-c2fe9eab966b
464 :setup: Replication with two suppliers.
465 :steps: 1. Add user to server.
466 2. Perform ldap modify, modrdn and delete operations.
467 3. Dump the changelog to a file using nsds5task.
468 4. Check if changelog is updated with ldap operations.
469 :expectedresults:
470 1. Add user should PASS.
471 2. Ldap operations should PASS.
472 3. Changelog should be dumped successfully.
473 4. Changelog dump file should contain ldap operations
474 """
475
476 log.info('LDAP operations add, modify, modrdn and delete')
477 _perform_ldap_operations(topo)
478 changelog_ldif = _create_changelog_dump(topo)
479 _check_changelog_ldif(topo, changelog_ldif)
480
481
482 def test_verify_changelog_online_backup(topo):
483 """Check ldap operations in changelog dump file after online backup
484
485 :id: 4001c34f-35b4-439e-8c2d-fa7e30375219
486 :setup: Replication with two suppliers.
487 :steps: 1. Add user to server.
488 2. Take online backup using db2bak task.
489 3. Restore the database using bak2db task.
490 4. Perform ldap modify, modrdn and delete operations.
491 5. Dump the changelog to a file using nsds5task.
492 6. Check if changelog is updated with ldap operations.
493 :expectedresults:
494 1. Add user should PASS.
495 2. Backup of database should PASS.
496 3. Restore of database should PASS.
497 4. Ldap operations should PASS.
498 5. Changelog should be dumped successfully.
499 6. Changelog dump file should contain ldap operations
500 """
501
502 backup_dir = os.path.join(topo.ms['supplier1'].get_bak_dir(), 'online_backup')
503 log.info('Run db2bak script to take database backup')
504 try:
505 topo.ms['supplier1'].tasks.db2bak(backup_dir=backup_dir, args={TASK_WAIT: True})
506 except ValueError:
507 log.fatal('test_changelog5: Online backup failed')
508 assert False
509
510 # Note: there is no way to check dbi on lmdb backup
511 # That said dbscan may perhaps do it ...
512 _check_repl_changelog_backup(topo.ms['supplier1'], backup_dir);
513
514 log.info('Run bak2db to restore directory server')
515 try:
516 topo.ms['supplier1'].tasks.bak2db(backup_dir=backup_dir, args={TASK_WAIT: True})
517 except ValueError:
518 log.fatal('test_changelog5: Online restore failed')
519 assert False
520
521 log.info('LDAP operations add, modify, modrdn and delete')
522 _perform_ldap_operations(topo)
523 changelog_ldif = _create_changelog_dump(topo)
524 _check_changelog_ldif(topo, changelog_ldif)
525
526
527 def test_verify_changelog_offline_backup(topo):
528 """Check ldap operations in changelog dump file after offline backup
529
530 :id: feed290d-57dd-46e4-9ab3-422c77589867
531 :setup: Replication with two suppliers.
532 :steps: 1. Add user to server.
533 2. Stop server and take offline backup using db2bak.
534 3. Restore the database using bak2db.
535 4. Perform ldap modify, modrdn and delete operations.
536 5. Start the server and dump the changelog using nsds5task.
537 6. Check if changelog is updated with ldap operations.
538 :expectedresults:
539 1. Add user should PASS.
540 2. Backup of database should PASS.
541 3. Restore of database should PASS.
542 4. Ldap operations should PASS.
543 5. Changelog should be dumped successfully.
544 6. Changelog dump file should contain ldap operations
545 """
546
547 backup_dir = os.path.join(topo.ms['supplier1'].get_bak_dir(), 'offline_backup')
548
549 topo.ms['supplier1'].stop()
550 log.info('Run db2bak to take database backup')
551 try:
552 topo.ms['supplier1'].db2bak(backup_dir)
553 except ValueError:
554 log.fatal('test_changelog5: Offline backup failed')
555 assert False
556
557 log.info('Run bak2db to restore directory server')
558 try:
559 topo.ms['supplier1'].bak2db(backup_dir)
560 except ValueError:
561 log.fatal('test_changelog5: Offline restore failed')
562 assert False
563 topo.ms['supplier1'].start()
564
565 _check_repl_changelog_backup(topo.ms['supplier1'], backup_dir);
566
567 log.info('LDAP operations add, modify, modrdn and delete')
568 _perform_ldap_operations(topo)
569 changelog_ldif = _create_changelog_dump(topo)
570 _check_changelog_ldif(topo, changelog_ldif)
571
572
573 def test_changelog_maxage(topo, changelog_init):
574 """Check nsslapd-changelog max age values
575
576 :id: d284ff27-03b2-412c-ac74-ac4f2d2fae3b
577 :setup: Replication with two supplier, change nsslapd-changelogdir to
578 '/var/lib/dirsrv/slapd-supplier1/changelog' and
579 set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
580 :steps:
581 1. Set nsslapd-changelogmaxage in cn=changelog5,cn=config to values:
582 '100s','100S','30m','30M','12h','12H','2d','2D','4w','4W'
583 2. Set nsslapd-changelogmaxage in cn=changelog5,cn=config to values:
584 '12345', 'd', '-123', '-123d', '345345xyz', '0d', 'xyz'
585
586 :expectedresults:
587 1. Operation should be successful
588 2. Operation should be unsuccessful
589 """
590 log.info('1. Test nsslapd-changelogmaxage in cn=changelog5,cn=config')
591
592 # bind as directory manager
593 topo.ms["supplier1"].log.info("Bind as %s" % DN_DM)
594 topo.ms["supplier1"].simple_bind_s(DN_DM, PASSWORD)
595
596 add_and_check(topo, CHANGELOG, MAXAGE, '100s', True)
597 add_and_check(topo, CHANGELOG, MAXAGE, '100S', True)
598 add_and_check(topo, CHANGELOG, MAXAGE, '30m', True)
599 add_and_check(topo, CHANGELOG, MAXAGE, '30M', True)
600 add_and_check(topo, CHANGELOG, MAXAGE, '12h', True)
601 add_and_check(topo, CHANGELOG, MAXAGE, '12H', True)
602 add_and_check(topo, CHANGELOG, MAXAGE, '2d', True)
603 add_and_check(topo, CHANGELOG, MAXAGE, '2D', True)
604 add_and_check(topo, CHANGELOG, MAXAGE, '4w', True)
605 add_and_check(topo, CHANGELOG, MAXAGE, '4W', True)
606 add_and_check(topo, CHANGELOG, MAXAGE, '12345', False)
607 add_and_check(topo, CHANGELOG, MAXAGE, 'd', False)
608 add_and_check(topo, CHANGELOG, MAXAGE, '-123', False)
609 add_and_check(topo, CHANGELOG, MAXAGE, '-123d', False)
610 add_and_check(topo, CHANGELOG, MAXAGE, '345345xyz', False)
611 add_and_check(topo, CHANGELOG, MAXAGE, '0d', False)
612 add_and_check(topo, CHANGELOG, MAXAGE, 'xyz', False)
613
614
615 def test_ticket47669_changelog_triminterval(topo, changelog_init):
616 """Check nsslapd-changelog triminterval values
617
618 :id: 8f850c37-7e7c-49dd-a4e0-9344638616d6
619 :setup: Replication with two supplier, change nsslapd-changelogdir to
620 '/var/lib/dirsrv/slapd-supplier1/changelog' and
621 set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
622 :steps:
623 1. Set nsslapd-changelogtrim-interval in cn=changelog5,cn=config to values -
624 '12345','10s','30M','12h','2D','4w'
625 2. Set nsslapd-changelogtrim-interval in cn=changelog5,cn=config to values - '-123','xyz'
626
627 :expectedresults:
628 1. Operation should be successful
629 2. Operation should be unsuccessful
630 """
631 log.info('2. Test nsslapd-changelogtrim-interval in cn=changelog5,cn=config')
632
633 # bind as directory manager
634 topo.ms["supplier1"].log.info("Bind as %s" % DN_DM)
635 topo.ms["supplier1"].simple_bind_s(DN_DM, PASSWORD)
636
637 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '12345', True)
638 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '10s', True)
639 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '30M', True)
640 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '12h', True)
641 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '2D', True)
642 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '4w', True)
643 add_and_check(topo, CHANGELOG, TRIMINTERVAL, '-123', False)
644 add_and_check(topo, CHANGELOG, TRIMINTERVAL, 'xyz', False)
645
646
647 @pytest.mark.skipif(ds_supports_new_changelog(), reason="changelog compaction is done by the backend itself, with id2entry as well, nsslapd-changelogcompactdb-interval is no longer supported")
648 def test_changelog_compactdbinterval(topo, changelog_init):
649 """Check nsslapd-changelog compactdbinterval values
650
651 :id: 0f4b3118-9dfa-4c2a-945c-72847b42a48c
652 :setup: Replication with two supplier, change nsslapd-changelogdir to
653 '/var/lib/dirsrv/slapd-supplier1/changelog' and
654 set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
655 :steps:
656 1. Set nsslapd-changelogcompactdb-interval in cn=changelog5,cn=config to values -
657 '12345','10s','30M','12h','2D','4w'
658 2. Set nsslapd-changelogcompactdb-interval in cn=changelog5,cn=config to values -
659 '-123','xyz'
660
661 :expectedresults:
662 1. Operation should be successful
663 2. Operation should be unsuccessful
664 """
665 log.info('3. Test nsslapd-changelogcompactdb-interval in cn=changelog5,cn=config')
666
667 # bind as directory manager
668 topo.ms["supplier1"].log.info("Bind as %s" % DN_DM)
669 topo.ms["supplier1"].simple_bind_s(DN_DM, PASSWORD)
670
671 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '12345', True)
672 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '10s', True)
673 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '30M', True)
674 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '12h', True)
675 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '2D', True)
676 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '4w', True)
677 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '-123', False)
678 add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, 'xyz', False)
679
680
681 def test_retrochangelog_maxage(topo, changelog_init):
682 """Check nsslapd-retrochangelog max age values
683
684 :id: 0cb84d81-3e86-4dbf-84a2-66aefd8281db
685 :setup: Replication with two supplier, change nsslapd-changelogdir to
686 '/var/lib/dirsrv/slapd-supplier1/changelog' and
687 set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
688 :steps:
689 1. Set nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config to values -
690 '100s','100S','30m','30M','12h','12H','2d','2D','4w','4W'
691 2. Set nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config to values -
692 '12345', 'd', '-123', '-123d', '345345xyz', '0d', 'xyz'
693
694 :expectedresults:
695 1. Operation should be successful
696 2. Operation should be unsuccessful
697 """
698 log.info('4. Test nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config')
699
700 # bind as directory manager
701 topo.ms["supplier1"].log.info("Bind as %s" % DN_DM)
702 topo.ms["supplier1"].simple_bind_s(DN_DM, PASSWORD)
703
704 add_and_check(topo, RETROCHANGELOG, MAXAGE, '100s', True)
705 add_and_check(topo, RETROCHANGELOG, MAXAGE, '100S', True)
706 add_and_check(topo, RETROCHANGELOG, MAXAGE, '30m', True)
707 add_and_check(topo, RETROCHANGELOG, MAXAGE, '30M', True)
708 add_and_check(topo, RETROCHANGELOG, MAXAGE, '12h', True)
709 add_and_check(topo, RETROCHANGELOG, MAXAGE, '12H', True)
710 add_and_check(topo, RETROCHANGELOG, MAXAGE, '2d', True)
711 add_and_check(topo, RETROCHANGELOG, MAXAGE, '2D', True)
712 add_and_check(topo, RETROCHANGELOG, MAXAGE, '4w', True)
713 add_and_check(topo, RETROCHANGELOG, MAXAGE, '4W', True)
714 add_and_check(topo, RETROCHANGELOG, MAXAGE, '12345', False)
715 add_and_check(topo, RETROCHANGELOG, MAXAGE, 'd', False)
716 add_and_check(topo, RETROCHANGELOG, MAXAGE, '-123', False)
717 add_and_check(topo, RETROCHANGELOG, MAXAGE, '-123d', False)
718 add_and_check(topo, RETROCHANGELOG, MAXAGE, '345345xyz', False)
719 add_and_check(topo, RETROCHANGELOG, MAXAGE, '0d', False)
720 add_and_check(topo, RETROCHANGELOG, MAXAGE, 'xyz', False)
721
722 topo.ms["supplier1"].log.info("ticket47669 was successfully verified.")
723
724 def test_retrochangelog_trimming_crash(topo, changelog_init):
725 """Check that when retroCL nsslapd-retrocthangelog contains invalid
726 value, then the instance does not crash at shutdown
727
728 :id: 5d9bd7ca-e9bf-4be9-8fc8-902aa5513052
729 :customerscenario: True
730 :setup: Replication with two supplier, change nsslapd-changelogdir to
731 '/var/lib/dirsrv/slapd-supplier1/changelog' and
732 set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
733 :steps:
734 1. Set nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config to value '-1'
735 This value is invalid. To disable retroCL trimming it should be set to 0
736 2. Do several restart
737 3. check there is no 'Detected Disorderly Shutdown' message (crash)
738 4. restore valid value for nsslapd-changelogmaxage '1w'
739
740 :expectedresults:
741 1. Operation should be successful
742 2. Operation should be successful
743 3. Operation should be successful
744 4. Operation should be successful
745 """
746 log.info('1. Test retroCL trimming crash in cn=Retro Changelog Plugin,cn=plugins,cn=config')
747
748 # set the nsslapd-changelogmaxage directly on dse.ldif
749 # because the set value is invalid
750 topo.ms["supplier1"].log.info("ticket50736 start verification")
751 topo.ms["supplier1"].stop()
752 retroPlugin = RetroChangelogPlugin(topo.ms["supplier1"])
753 dse_ldif = DSEldif(topo.ms["supplier1"])
754 dse_ldif.replace(retroPlugin.dn, 'nsslapd-changelogmaxage', '-1')
755 topo.ms["supplier1"].start()
756
757 # The crash should be systematic, but just in case do several restart
758 # with a delay to let all plugin init
759 for i in range(5):
760 time.sleep(1)
761 topo.ms["supplier1"].stop()
762 topo.ms["supplier1"].start()
763
764 assert not topo.ms["supplier1"].detectDisorderlyShutdown()
765
766 topo.ms["supplier1"].log.info("ticket 50736 was successfully verified.")
767
768
769 @pytest.mark.skipif(not os.path.isfile("/usr/bin/db_stat"), reason="libdb-utils package is not installed")
770 def test_changelog_pagesize(topo):
771 """Test that changelog page size is set properly
772
773 :id: 584a9a82-756d-11ed-8b38-482ae39447e5
774 :setup: Replication with two suppliers
775 :steps:
776 1. Check that file system preferred block size is 4K
777 2. Run db_stat -e -h db_home_dir
778 3. Check for 4K page size in db_stat output
779 :expectedresults:
780 1. Mark the test as skipped if block size is not 4K
781 2. Success
782 3. Should not have any 4K page size in db_stat output
783 """
784
785 s1 = topo.ms["supplier1"]
786 fs_pagesize = os.statvfs(s1.ds_paths.db_home_dir).f_bsize
787 if fs_pagesize != 4096:
788 pytest.skip("This test requires that database filesystem prefered block size is 4K.")
789 return
790 try:
791 cmd = ["/usr/bin/db_stat", "-h", s1.ds_paths.db_home_dir, "-e"]
792 log.debug(f"DEBUG: Running {cmd}")
793 output = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT)
794 except subprocess.CalledProcessError as e:
795 log.error(f'Failed to gather db statistics {cmd}: "{e.output.decode()}')
796 log.error(e)
797 raise e
798 assert not re.match("^4096 *Page size", output, flags=re.MULTILINE)
799
800
801 def test_changelog_type_validation(topo):
802 """Verify that changelog configuration properly validates attribute values
803
804 :id: 4c7681ff-0511-4256-9589-bdcad84c13e6
805 :setup: Replication with two suppliers
806 :steps:
807 1. Get changelog configuration object
808 2. Set valid string values for maxage and trim interval attributes
809 3. Verify the values were set correctly
810 :expectedresults:
811 1. Changelog object retrieved successfully
812 2. Valid string values should be accepted
813 3. Configuration should be updated with correct values
814 """
815
816 supplier = topo.ms["supplier1"]
817
818 log.info('Getting changelog configuration object')
819 if ds_supports_new_changelog():
820 cl = Changelog(supplier, suffix=DEFAULT_SUFFIX)
821 else:
822 cl = Changelog5(supplier)
823
824 log.info('Reading current changelog max age configuration')
825 current_maxage = cl.get_attr_val_utf8(MAXAGE)
826 log.info(f'Current {MAXAGE}: {current_maxage}')
827
828 log.info('Setting changelog maxage to 60s')
829 cl.replace(MAXAGE, '60s')
830
831 log.info('Setting changelog trim interval to 10s')
832 cl.replace(TRIMINTERVAL, '10s')
833
834 log.info('Verifying changelog maxage was updated')
835 new_maxage = cl.get_attr_val_utf8(MAXAGE)
836 assert new_maxage == '60s', f'Expected maxage "60s", got "{new_maxage}"'
837
838 log.info('Verifying changelog trim interval was updated')
839 new_triminterval = cl.get_attr_val_utf8(TRIMINTERVAL)
840 assert new_triminterval == '10s', f'Expected triminterval "10s", got "{new_triminterval}"'
841
842 log.info('Changelog configuration validated successfully')
843
844
845 if __name__ == '__main__':
846 # Run isolated
847 # -s for DEBUG mode
848 CURRENT_FILE = os.path.realpath(__file__)
849 pytest.main("-s %s" % CURRENT_FILE)