Debian Codegraph @

dirsrvtests/tests/suites/replication/multiple_changelogs_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 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 ldap
10 import logging
11 import pytest
12 import os
13 import threading
14 import time
15 from lib389._constants import *
16 from test389.topologies import topology_m1c1 as topo
17 from lib389.idm.directorymanager import DirectoryManager
18 from lib389.idm.domain import Domain
19 from lib389.backend import Backend
20 from lib389.replica import Replicas, ReplicationManager
21 from lib389.config import LDBMConfig
22
23 log = logging.getLogger(__name__)
24
25 SECOND_SUFFIX = 'dc=second_suffix'
26 MOD_COUNT = 50
27
28 class DoMods(threading.Thread):
29 """modify the suffix entry"""
30 def __init__(self, inst, task):
31 """
32 Initialize the thread
33 """
34 threading.Thread.__init__(self)
35 self.daemon = True
36 self.inst = inst
37 self.name = inst.serverid
38 self.task = task
39
40 def run(self):
41 """
42 Start adding users
43 """
44 idx = 0
45 conn = DirectoryManager(self.inst).bind()
46 domain = Domain(conn, DEFAULT_SUFFIX)
47 while idx < MOD_COUNT:
48 try:
49 domain.replace('description', str(idx))
50 except:
51 if self.task == "import":
52 # Failures are expected during an import
53 pass
54 else:
55 # export, should not fail
56 log.fatal('Updates should not fail during an export')
57 assert False
58 idx += 1
59
60
61 def test_multiple_changelogs(topo):
62 """Test the multiple suffixes can be replicated with the new per backend
63 changelog.
64
65 :id: eafcdb57-4ea2-4887-a0a8-9e4d295f4f4d
66 :setup: Supplier Instance, Consumer Instance
67 :steps:
68 1. Create s second suffix
69 2. Enable replication for second backend
70 3. Perform some updates on both backends and make sure replication is
71 working for both backends
72
73 :expectedresults:
74 1. Success
75 2. Success
76 3. Success
77 """
78 supplier = topo.ms['supplier1']
79 consumer = topo.cs['consumer1']
80
81 # Create second suffix dc=second_backend on both replicas
82 for inst in [supplier, consumer]:
83 # Create the backends
84 props = {'cn': 'secondRoot', 'nsslapd-suffix': SECOND_SUFFIX}
85 be = Backend(inst)
86 be.create(properties=props)
87 be.create_sample_entries('001004002')
88
89 # Setup replication for second suffix
90 repl = ReplicationManager(SECOND_SUFFIX)
91 repl.create_first_supplier(supplier)
92 repl.join_consumer(supplier, consumer)
93
94 # Test replication works for each backend
95 for suffix in [DEFAULT_SUFFIX, SECOND_SUFFIX]:
96 replicas = Replicas(supplier)
97 replica = replicas.get(suffix)
98 log.info("Testing replication for: " + suffix)
99 assert replica.test_replication([consumer])
100
101
102 def test_multiple_changelogs_export_import(topo):
103 """Test that we can export and import the replication changelog
104
105 :id: b74fcaaf-a13f-4ee0-98f9-248b281f8700
106 :setup: Supplier Instance, Consumer Instance
107 :steps:
108 1. Create s second suffix
109 2. Enable replication for second backend
110 3. Perform some updates on a backend, and export the changelog
111 4. Do an export and import while the server is idle
112 5. Do an import while the server is under load
113
114 :expectedresults:
115 1. Success
116 2. Success
117 3. Success
118 4. Success
119 5. Success
120 """
121 SECOND_SUFFIX = 'dc=second_suffix'
122 supplier = topo.ms['supplier1']
123 consumer = topo.cs['consumer1']
124 supplier.config.set('nsslapd-errorlog-level', '0')
125 # Create second suffix dc=second_backend on both replicas
126 for inst in [supplier, consumer]:
127 # Create the backends
128 props = {'cn': 'secondRoot', 'nsslapd-suffix': SECOND_SUFFIX}
129 be = Backend(inst)
130 try:
131 be.create(properties=props)
132 be.create_sample_entries('001004002')
133 except ldap.UNWILLING_TO_PERFORM:
134 pass
135
136 # Setup replication for second suffix
137 try:
138 repl = ReplicationManager(SECOND_SUFFIX)
139 repl.create_first_supplier(supplier)
140 repl.join_consumer(supplier, consumer)
141 except ldap.ALREADY_EXISTS:
142 pass
143
144 # Put the replica under load, and export the changelog
145 replicas = Replicas(supplier)
146 replica = replicas.get(DEFAULT_SUFFIX)
147 doMods1 = DoMods(supplier, task="export")
148 doMods1.start()
149 replica.begin_task_cl2ldif()
150 doMods1.join()
151 replica.task_finished()
152
153 supplier.restart()
154 assert replica.test_replication([consumer])
155
156 # While idle, do an export and import, and make sure replication still works
157 log.info("Testing idle server with CL export and import...")
158 ldbm_config = LDBMConfig(supplier)
159 ldbm_config.set('nsslapd-readonly', 'on') # prevent keep alive updates
160 replica.begin_task_cl2ldif()
161 replica.task_finished()
162 replica.begin_task_ldif2cl()
163 replica.task_finished()
164 ldbm_config.set('nsslapd-readonly', 'off')
165 assert replica.test_replication([consumer])
166
167 # stability test, put the replica under load, import the changelog, and make
168 # sure server did not crash.
169 log.info("Testing busy server with CL import...")
170 doMods2 = DoMods(supplier, task="import")
171 doMods2.start()
172 replica.begin_task_ldif2cl()
173 doMods2.join()
174 replica.task_finished()
175 # Replication will be broken so no need to test it. This is just make sure
176 # the import works, and the server is stable
177 assert supplier.status()
178 assert consumer.status()
179
180
181 if __name__ == '__main__':
182 # Run isolated
183 # -s for DEBUG mode
184 CURRENT_FILE = os.path.realpath(__file__)
185 pytest.main(["-s", CURRENT_FILE])
186