Debian Codegraph @

dirsrvtests/tests/suites/replication/regression_m2c2_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2021 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 pytest
12 from lib389.utils import *
13 from lib389._constants import *
14 from lib389.replica import Replicas, ReplicationManager
15 from lib389.agreement import Agreements
16 from lib389.dseldif import *
17 from test389.topologies import topology_m2c2 as topo_m2c2
18
19
20 pytestmark = pytest.mark.tier1
21
22 NEW_SUFFIX_NAME = 'test_repl'
23 NEW_SUFFIX = 'o={}'.format(NEW_SUFFIX_NAME)
24 NEW_BACKEND = 'repl_base'
25 CHANGELOG = 'cn=changelog,{}'.format(DN_USERROOT_LDBM)
26 MAXAGE_ATTR = 'nsslapd-changelogmaxage'
27 MAXAGE_STR = '30'
28 TRIMINTERVAL_STR = '5'
29 TRIMINTERVAL = 'nsslapd-changelogtrim-interval'
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 def get_agreement(agmts, consumer):
40 # Get agreement towards consumer among the agremment list
41 for agmt in agmts.list():
42 if (agmt.get_attr_val_utf8('nsDS5ReplicaPort') == str(consumer.port) and
43 agmt.get_attr_val_utf8('nsDS5ReplicaHost') == consumer.host):
44 return agmt
45 return None
46
47
48 def test_ruv_url_not_added_if_different_uuid(topo_m2c2):
49 """Check that RUV url is not updated if RUV generation uuid are different
50
51 :id: 7cc30a4e-0ffd-4758-8f00-e500279af344
52 :setup: Two suppliers + two consumers replication setup
53 :steps:
54 1. Generate ldif without replication data
55 2. Init both suppliers from that ldif
56 (to clear the ruvs and generates different generation uuid)
57 3. Perform on line init from supplier1 to consumer1
58 and from supplier2 to consumer2
59 4. Perform update on both suppliers
60 5. Check that c1 RUV does not contains URL towards m2
61 6. Check that c2 RUV does contains URL towards m2
62 7. Perform on line init from supplier1 to supplier2
63 8. Perform update on supplier2
64 9. Check that c1 RUV does contains URL towards m2
65 :expectedresults:
66 1. No error while generating ldif
67 2. No error while importing the ldif file
68 3. No error and Initialization done.
69 4. No error
70 5. supplier2 replicaid should not be in the consumer1 RUV
71 6. supplier2 replicaid should be in the consumer2 RUV
72 7. No error and Initialization done.
73 8. No error
74 9. supplier2 replicaid should be in the consumer1 RUV
75
76 """
77
78 # Variables initialization
79 repl = ReplicationManager(DEFAULT_SUFFIX)
80
81 m1 = topo_m2c2.ms["supplier1"]
82 m2 = topo_m2c2.ms["supplier2"]
83 c1 = topo_m2c2.cs["consumer1"]
84 c2 = topo_m2c2.cs["consumer2"]
85
86 replica_m1 = Replicas(m1).get(DEFAULT_SUFFIX)
87 replica_m2 = Replicas(m2).get(DEFAULT_SUFFIX)
88 replica_c1 = Replicas(c1).get(DEFAULT_SUFFIX)
89 replica_c2 = Replicas(c2).get(DEFAULT_SUFFIX)
90
91 replicid_m2 = replica_m2.get_rid()
92
93 agmts_m1 = Agreements(m1, replica_m1.dn)
94 agmts_m2 = Agreements(m2, replica_m2.dn)
95
96 m1_m2 = get_agreement(agmts_m1, m2)
97 m1_c1 = get_agreement(agmts_m1, c1)
98 m1_c2 = get_agreement(agmts_m1, c2)
99 m2_m1 = get_agreement(agmts_m2, m1)
100 m2_c1 = get_agreement(agmts_m2, c1)
101 m2_c2 = get_agreement(agmts_m2, c2)
102
103 # Step 1: Generate ldif without replication data
104 m1.stop()
105 m2.stop()
106 ldif_file = '%s/norepl.ldif' % m1.get_ldif_dir()
107 m1.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX],
108 excludeSuffixes=None, repl_data=False,
109 outputfile=ldif_file, encrypt=False)
110 # Remove replication metadata that are still in the ldif
111 # _remove_replication_data(ldif_file)
112
113 # Step 2: Init both suppliers from that ldif
114 m1.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)
115 m2.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)
116 m1.start()
117 m2.start()
118
119 # Step 3: Perform on line init from supplier1 to consumer1
120 # and from supplier2 to consumer2
121 m1_c1.begin_reinit()
122 m2_c2.begin_reinit()
123 (done, error) = m1_c1.wait_reinit()
124 assert done is True
125 assert error is False
126 (done, error) = m2_c2.wait_reinit()
127 assert done is True
128 assert error is False
129
130 # Step 4: Perform update on both suppliers
131 repl.test_replication(m1, c1)
132 repl.test_replication(m2, c2)
133
134 # Step 5: Check that c1 RUV does not contains URL towards m2
135 ruv = replica_c1.get_ruv()
136 log.debug(f"c1 RUV: {ruv}")
137 url = ruv._rid_url.get(replica_m2.get_rid())
138 if url is None:
139 log.debug(f"No URL for RID {replica_m2.get_rid()} in RUV")
140 else:
141 log.debug(f"URL for RID {replica_m2.get_rid()} in RUV is {url}")
142 log.error(f"URL for RID {replica_m2.get_rid()} found in RUV")
143 # Note: this assertion fails if issue 2054 is not fixed.
144 assert False
145
146 # Step 6: Check that c2 RUV does contains URL towards m2
147 ruv = replica_c2.get_ruv()
148 log.debug(f"c1 RUV: {ruv} {ruv._rids} ")
149 url = ruv._rid_url.get(replica_m2.get_rid())
150 if url is None:
151 log.error(f"No URL for RID {replica_m2.get_rid()} in RUV")
152 assert False
153 else:
154 log.debug(f"URL for RID {replica_m2.get_rid()} in RUV is {url}")
155
156 # Step 7: Perform on line init from supplier1 to supplier2
157 m1_m2.begin_reinit()
158 (done, error) = m1_m2.wait_reinit()
159 assert done is True
160 assert error is False
161
162 # Step 8: Perform update on supplier2
163 repl.test_replication(m2, c1)
164
165 # Step 9: Check that c1 RUV does contains URL towards m2
166 ruv = replica_c1.get_ruv()
167 log.debug(f"c1 RUV: {ruv} {ruv._rids} ")
168 url = ruv._rid_url.get(replica_m2.get_rid())
169 if url is None:
170 log.error(f"No URL for RID {replica_m2.get_rid()} in RUV")
171 assert False
172 else:
173 log.debug(f"URL for RID {replica_m2.get_rid()} in RUV is {url}")
174
175
176 def test_csngen_state_not_updated_if_different_uuid(topo_m2c2):
177 """Check that csngen remote offset is not updated if RUV generation uuid are different
178
179 :id: 77694b8e-22ae-11eb-89b2-482ae39447e5
180 :setup: Two suppliers + two consumers replication setup
181 :steps:
182 1. Disable m1<->m2 agreement to avoid propagate timeSkew
183 2. Generate ldif without replication data
184 3. Increase time skew on supplier2
185 4. Init both suppliers from that ldif
186 (to clear the ruvs and generates different generation uuid)
187 5. Perform on line init from supplier1 to consumer1 and supplier2 to consumer2
188 6. Perform update on both suppliers
189 7. Check that c1 has no time skew
190 8. Check that c2 has time skew
191 9. Init supplier2 from supplier1
192 10. Perform update on supplier2
193 11. Check that c1 has time skew
194 :expectedresults:
195 1. No error
196 2. No error while generating ldif
197 3. No error
198 4. No error while importing the ldif file
199 5. No error and Initialization done.
200 6. No error
201 7. c1 time skew should be lesser than threshold
202 8. c2 time skew should be higher than threshold
203 9. No error and Initialization done.
204 10. No error
205 11. c1 time skew should be higher than threshold
206
207 """
208
209 # Variables initialization
210 repl = ReplicationManager(DEFAULT_SUFFIX)
211
212 m1 = topo_m2c2.ms["supplier1"]
213 m2 = topo_m2c2.ms["supplier2"]
214 c1 = topo_m2c2.cs["consumer1"]
215 c2 = topo_m2c2.cs["consumer2"]
216
217 replica_m1 = Replicas(m1).get(DEFAULT_SUFFIX)
218 replica_m2 = Replicas(m2).get(DEFAULT_SUFFIX)
219 replica_c1 = Replicas(c1).get(DEFAULT_SUFFIX)
220 replica_c2 = Replicas(c2).get(DEFAULT_SUFFIX)
221
222 replicid_m2 = replica_m2.get_rid()
223
224 agmts_m1 = Agreements(m1, replica_m1.dn)
225 agmts_m2 = Agreements(m2, replica_m2.dn)
226
227 m1_m2 = get_agreement(agmts_m1, m2)
228 m1_c1 = get_agreement(agmts_m1, c1)
229 m1_c2 = get_agreement(agmts_m1, c2)
230 m2_m1 = get_agreement(agmts_m2, m1)
231 m2_c1 = get_agreement(agmts_m2, c1)
232 m2_c2 = get_agreement(agmts_m2, c2)
233
234 # Step 1: Disable m1<->m2 agreement to avoid propagate timeSkew
235 m1_m2.pause()
236 m2_m1.pause()
237
238 # Step 2: Generate ldif without replication data
239 m1.stop()
240 m2.stop()
241 ldif_file = '%s/norepl.ldif' % m1.get_ldif_dir()
242 m1.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX],
243 excludeSuffixes=None, repl_data=False,
244 outputfile=ldif_file, encrypt=False)
245 # Remove replication metadata that are still in the ldif
246 # _remove_replication_data(ldif_file)
247
248 # Step 3: Increase time skew on supplier2
249 timeSkew = 6*3600
250 # We can modify supplier2 time skew
251 # But the time skew on the consumer may be smaller
252 # depending on when the cnsgen generation time is updated
253 # and when first csn get replicated.
254 # Since we use timeSkew has threshold value to detect
255 # whether there are time skew or not,
256 # lets add a significative margin (longer than the test duration)
257 # to avoid any risk of erroneous failure
258 timeSkewMargin = 300
259 DSEldif(m2)._increaseTimeSkew(DEFAULT_SUFFIX, timeSkew+timeSkewMargin)
260
261 # Step 4: Init both suppliers from that ldif
262 m1.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)
263 m2.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)
264 m1.start()
265 m2.start()
266
267 # Step 5: Perform on line init from supplier1 to consumer1
268 # and from supplier2 to consumer2
269 m1_c1.begin_reinit()
270 m2_c2.begin_reinit()
271 (done, error) = m1_c1.wait_reinit()
272 assert done is True
273 assert error is False
274 (done, error) = m2_c2.wait_reinit()
275 assert done is True
276 assert error is False
277
278 # Step 6: Perform update on both suppliers
279 repl.test_replication(m1, c1)
280 repl.test_replication(m2, c2)
281
282 # Step 7: Check that c1 has no time skew
283 # Stop server to insure that dse.ldif is uptodate
284 c1.stop()
285 c1_nsState = DSEldif(c1).readNsState(DEFAULT_SUFFIX)[0]
286 c1_timeSkew = int(c1_nsState['time_skew'])
287 log.debug(f"c1 time skew: {c1_timeSkew}")
288 if (c1_timeSkew >= timeSkew):
289 log.error(f"c1 csngen state has unexpectedly been synchronized with m2: time skew {c1_timeSkew}")
290 assert False
291 c1.start()
292 time.sleep(5)
293
294 # Step 8: Check that c2 has time skew
295 # Stop server to insure that dse.ldif is uptodate
296 c2.stop()
297 c2_nsState = DSEldif(c2).readNsState(DEFAULT_SUFFIX)[0]
298 c2_timeSkew = int(c2_nsState['time_skew'])
299 log.debug(f"c2 time skew: {c2_timeSkew}")
300 if (c2_timeSkew < timeSkew):
301 log.error(f"c2 csngen state has not been synchronized with m2: time skew {c2_timeSkew}")
302 assert False
303 c2.start()
304
305 # Step 9: Perform on line init from supplier1 to supplier2
306 m1_c1.pause()
307 m1_m2.resume()
308 m1_m2.begin_reinit()
309 (done, error) = m1_m2.wait_reinit()
310 assert done is True
311 assert error is False
312
313 # Step 10: Perform update on supplier2
314 repl.test_replication(m2, c1)
315
316 # Step 11: Check that c1 has time skew
317 # Stop server to insure that dse.ldif is uptodate
318 c1.stop()
319 c1_nsState = DSEldif(c1).readNsState(DEFAULT_SUFFIX)[0]
320 c1_timeSkew = int(c1_nsState['time_skew'])
321 log.debug(f"c1 time skew: {c1_timeSkew}")
322 if (c1_timeSkew < timeSkew):
323 log.error(f"c1 csngen state has not been synchronized with m2: time skew {c1_timeSkew}")
324 assert False
325
326
327 if __name__ == '__main__':
328 # Run isolated
329 # -s for DEBUG mode
330 CURRENT_FILE = os.path.realpath(__file__)
331 pytest.main("-s %s" % CURRENT_FILE)