Debian Codegraph @

dirsrvtests/tests/suites/replication/series_of_repl_bugs_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 import pytest
10 from lib389.tasks import *
11 from lib389.utils import *
12 from test389.topologies import topology_m2 as topo_m2
13 from test389.topologies import topology_m1c1 as m1c1
14 from test389.topologies import topology_st as topo
15 from lib389.idm.user import UserAccount, UserAccounts
16 from lib389.plugins import USNPlugin
17 from lib389.replica import ReplicationManager
18 from lib389.tombstone import Tombstones
19 from lib389.agreement import Agreements
20 from lib389._constants import *
21
22
23 pytestmark = pytest.mark.tier1
24
25
26 @pytest.fixture(scope="function")
27 def _delete_after(request, topo_m2):
28 def last():
29 m1 = topo_m2.ms["supplier1"]
30 if UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).list():
31 for user in UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).list():
32 user.delete()
33
34 request.addfinalizer(last)
35
36
37 def test_deletions_are_not_replicated(topo_m2):
38 """usn + mmr = deletions are not replicated
39
40 :id: aa4f67ce-a64c-11ea-a6fd-8c16451d917b
41 :setup: MMR with 2 suppliers
42 :steps:
43 1. Enable USN plugin on both servers
44 2. Enable USN plugin on Supplier 2
45 3. Add user
46 4. Check that user propagated to Supplier 2
47 5. Check user`s USN on Supplier 1
48 6. Check user`s USN on Supplier 2
49 7. Delete user
50 8. Check that deletion of user propagated to Supplier 1
51 :expectedresults:
52 1. Should succeeds
53 2. Should succeeds
54 3. Should succeeds
55 4. Should succeeds
56 5. Should succeeds
57 6. Should succeeds
58 7. Should succeeds
59 8. Should succeeds
60 """
61 m1 = topo_m2.ms["supplier1"]
62 m2 = topo_m2.ms["supplier2"]
63 # Enable USN plugin on both servers
64 usn1 = USNPlugin(m1)
65 usn2 = USNPlugin(m2)
66 for usn_usn in [usn1, usn2]:
67 usn_usn.enable()
68 for instance in [m1, m2]:
69 instance.restart()
70 # Add user
71 user = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=1, gid=1)
72 repl_manager = ReplicationManager(DEFAULT_SUFFIX)
73 repl_manager.wait_for_replication(m1, m2, timeout=100)
74 # Check that user propagated to Supplier 2
75 assert user.dn in [i.dn for i in UserAccounts(m2, DEFAULT_SUFFIX, rdn=None).list()]
76 user2 = UserAccount(m2, f'uid=test_user_1,{DEFAULT_SUFFIX}')
77 # Check user`s USN on Supplier 1
78 assert user.get_attr_val_utf8('entryusn')
79 # Check user`s USN on Supplier 2
80 assert user2.get_attr_val_utf8('entryusn')
81 # Delete user
82 user2.delete()
83 repl_manager.wait_for_replication(m1, m2, timeout=100)
84 # Check that deletion of user propagated to Supplier 1
85 with pytest.raises(ldap.NO_SUCH_OBJECT):
86 user.status()
87
88
89 def test_error_20(topo_m2, _delete_after):
90 """DS returns error 20 when replacing values of a multi-valued attribute (only when replication is enabled)
91
92 :id: a55bccc6-a64c-11ea-bac8-8c16451d917b
93 :setup: MMR with 2 suppliers
94 :steps:
95 1. Add user
96 2. Change multivalue attribute
97 :expectedresults:
98 1. Should succeeds
99 2. Should succeeds
100 """
101 m1 = topo_m2.ms["supplier1"]
102 m2 = topo_m2.ms["supplier2"]
103 # Add user
104 user = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=1, gid=1)
105 repl_manager = ReplicationManager(DEFAULT_SUFFIX)
106 repl_manager.wait_for_replication(m1, m2, timeout=100)
107 # Change multivalue attribute
108 assert user.replace_many(('cn', 'BUG 891866'), ('cn', 'Test'))
109
110
111 def test_enable_repl_w_master(topo):
112 """Check that enabling replication with the role "master" succeeds.
113
114 :id: 074fbb38-069e-11ec-98ca-fa163ec212ff
115 :customerscenario: True
116 :setup: Create DS standalone instance
117 :steps:
118 1. Create DS standalone instance
119 2. Enable replication on supplier with role='master' attribute OR Display appropriate message.
120 3. Disable role created above if it was created.
121 4. Re-enable replication on supplier with role='supplier' attribute
122
123 :expectedresults:
124 1. Success
125 2. Success
126 3. Success
127 4. Success
128 """
129 _err_unknown_role = 'Error: Unknown replication role (master), you must use "supplier", "hub", or "consumer"'
130 log.info("Enabling replication on supplier with role='master' attribute")
131 cmd = ('dsconf -D "' + DN_DM + '" standalone1 ' + ' -w ' + PW_DM + ' replication enable --suffix="' + DEFAULT_SUFFIX +
132 '" --role="master" --replica-id=1 ')
133 if os.system(cmd) == 0:
134 log.info("Replication role enabled successfully")
135 cmd = ('dsconf -D "' + DN_DM + '" standalone1 ' + ' -w ' + PW_DM + ' replication disable --suffix="' + DEFAULT_SUFFIX+' "')
136 os.system(cmd)
137 log.info("Disabling replication on supplier with role='master' attribute")
138 time.sleep(.5)
139 elif topo.logcap.contains(_err_unknown_role):
140 log.info("Replication role provided is not supported")
141 log.info("Enabling replication on supplier with role='supplier' attribute")
142 cmd = ('dsconf -D "' + DN_DM + '" standalone1 ' + ' -w ' + PW_DM + ' replication enable --suffix="' + DEFAULT_SUFFIX +
143 '" --role="supplier" --replica-id=1 ')
144 assert os.system(cmd) == 0
145
146
147 def test_segfaults(topo_m2, _delete_after):
148 """ns-slapd segfaults while trying to delete a tombstone entry
149
150 :id: 9f8f7388-a64c-11ea-b5f7-8c16451d917b
151 :setup: MMR with 2 suppliers
152 :steps:
153 1. Add new user
154 2. Delete user - should leave tombstone entry
155 3. Search for tombstone entry
156 4. Try to delete tombstone entry
157 5. Check if server is still alive
158 :expectedresults:
159 1. Should succeeds
160 2. Should succeeds
161 3. Should succeeds
162 4. Should succeeds
163 5. Should succeeds
164 """
165 m1 = topo_m2.ms["supplier1"]
166 # Add user
167 user = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=10, gid=1)
168 # Delete user - should leave tombstone entry
169 user.delete()
170 tombstones = Tombstones(m1, DEFAULT_SUFFIX)
171 # Search for tombstone entry
172 fil = tombstones.filter("(&(objectClass=nstombstone)(uid=test_user_10))")
173 assert fil
174 # Try to delete tombstone entry
175 for user in fil:
176 user.delete()
177 # Check if server is still alive
178 assert m1.status()
179
180
181 def test_adding_deleting(topo_m2, _delete_after):
182 """Adding attribute with 11 values to entry
183
184 :id: 99842b1e-a64c-11ea-b8e3-8c16451d917b
185 :setup: MMR with 2 suppliers
186 :steps:
187 1. Adding entry
188 2. Adding attribute with 11 values to entry
189 3. Removing 4 values from the attribute in the entry
190 :expectedresults:
191 1. Should succeeds
192 2. Should succeeds
193 3. Should succeeds
194 """
195 m1 = topo_m2.ms["supplier1"]
196 # Adding entry
197 user = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=1, gid=1)
198 # Adding attribute with 11 values to entry
199 for val1, val2 in [('description', 'first description'),
200 ('description', 'second description'),
201 ('description', 'third description'),
202 ('description', 'fourth description'),
203 ('description', 'fifth description'),
204 ('description', 'sixth description'),
205 ('description', 'seventh description'),
206 ('description', 'eighth description'),
207 ('description', 'nineth description'),
208 ('description', 'tenth description'),
209 ('description', 'eleventh description')]:
210 user.add(val1, val2)
211 # Removing 4 values from the attribute in the entry
212 for val1, val2 in [('description', 'first description'),
213 ('description', 'second description'),
214 ('description', 'third description'),
215 ('description', 'fourth description')]:
216 user.remove(val1, val2)
217
218
219 def test_deleting_twice(topo_m2):
220 """Deleting entry twice crashed a server
221
222 :id: 94045560-a64c-11ea-93d6-8c16451d917b
223 :setup: MMR with 2 suppliers
224 :steps:
225 1. Adding entry
226 2. Deleting the same entry from s1
227 3. Deleting the same entry from s2 after some seconds
228 :expectedresults:
229 1. Should succeeds
230 2. Should succeeds
231 3. Should succeeds
232 """
233 m1 = topo_m2.ms["supplier1"]
234 m2 = topo_m2.ms["supplier2"]
235 # Adding entry
236 user1 = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=1, gid=1)
237 repl_manager = ReplicationManager(DEFAULT_SUFFIX)
238 repl_manager.wait_for_replication(m1, m2, timeout=100)
239 user2 = UserAccount(m2, f'uid=test_user_1,{DEFAULT_SUFFIX}')
240 assert user2.status()
241 # Deleting the same entry from s1
242 user1.delete()
243 repl_manager.wait_for_replication(m1, m2, timeout=100)
244 # Deleting the same entry from s2 after some seconds
245 with pytest.raises(ldap.NO_SUCH_OBJECT):
246 user2.delete()
247 assert m1.status()
248 assert m2.status()
249
250
251 def test_rename_entry(topo_m2, _delete_after):
252 """Rename entry crashed a server
253
254 :id: 3866f9d6-a946-11ea-a3f8-8c16451d917b
255 :setup: MMR with 2 suppliers
256 :steps:
257 1. Adding entry
258 2. Stop Agreement for both
259 3. Change description
260 4. Change will not reflect on other supplier
261 5. Turn on agreement on both
262 6. Change will reflect on other supplier
263 :expectedresults:
264 1. Should succeeds
265 2. Should succeeds
266 3. Should succeeds
267 4. Should succeeds
268 5. Should succeeds
269 6. Should succeeds
270 """
271 m1 = topo_m2.ms["supplier1"]
272 m2 = topo_m2.ms["supplier2"]
273 # Adding entry
274 user1 = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=1, gid=1)
275 repl_manager = ReplicationManager(DEFAULT_SUFFIX)
276 repl_manager.wait_for_replication(m1, m2, timeout=100)
277 user2 = UserAccount(m2, user1.dn)
278 assert user2.status()
279 # Stop Agreement for both
280 agree1 = Agreements(m1).list()[0]
281 agree2 = Agreements(m2).list()[0]
282 for agree in [agree1, agree2]:
283 agree.pause()
284 # change description
285 user1.replace('description', 'New Des')
286 assert user1.get_attr_val_utf8('description')
287 # Change will not reflect on other supplier
288 with pytest.raises(AssertionError):
289 assert user2.get_attr_val_utf8('description')
290 # Turn on agreement on both
291 for agree in [agree1, agree2]:
292 agree.resume()
293 repl_manager.wait_for_replication(m1, m2, timeout=100)
294 for instance in [user1, user2]:
295 assert instance.get_attr_val_utf8('description')
296
297
298 def test_userpassword_attribute(topo_m2, _delete_after):
299 """Modifications of userpassword attribute in an MMR environment were successful
300 however a error message was displayed in the error logs which was curious.
301
302 :id: bdcf0464-a947-11ea-9f0d-8c16451d917b
303 :setup: MMR with 2 suppliers
304 :steps:
305 1. Add the test user to S1
306 2. Check that user's has been propogated to Supplier 2
307 3. modify user's userpassword attribute on supplier 2
308 4. check the error logs on suppler 1 to make sure the error message is not there
309 :expectedresults:
310 1. Should succeeds
311 2. Should succeeds
312 3. Should succeeds
313 4. Should succeeds
314 """
315 m1 = topo_m2.ms["supplier1"]
316 m2 = topo_m2.ms["supplier2"]
317 # Add the test user to S1
318 user1 = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=1, gid=1)
319 repl_manager = ReplicationManager(DEFAULT_SUFFIX)
320 repl_manager.wait_for_replication(m1, m2, timeout=100)
321 # Check that user's has been propogated to Supplier 2
322 user2 = UserAccount(m2, user1.dn)
323 assert user2.status()
324 # modify user's userpassword attribute on supplier 2
325 user2.replace('userpassword', 'fred1')
326 repl_manager.wait_for_replication(m1, m2, timeout=100)
327 assert user1.get_attr_val_utf8('userpassword')
328 # check the error logs on suppler 1 to make sure the error message is not there
329 assert not m1.searchErrorsLog("can\'t add a change for uid=")
330
331
332 def _create_and_delete_tombstone(topo_m2, id):
333 m1 = topo_m2.ms["supplier1"]
334 # Add new user
335 user1 = UserAccounts(m1, DEFAULT_SUFFIX, rdn=None).create_test_user(uid=id, gid=id)
336 # Delete user - should leave tombstone entry
337 user1.delete()
338 tombstones = Tombstones(m1, DEFAULT_SUFFIX)
339 # Search for tombstone entry
340 fil = tombstones.filter("(&(objectClass=nstombstone)(uid=test_user_{}*))".format(id))[0]
341 assert fil
342 fil.rename("uid=engineer")
343 assert m1
344
345
346 def test_tombstone_modrdn(topo_m2):
347 """rhds90 crash on tombstone modrdn
348
349 :id: 846f5042-a948-11ea-ade2-8c16451d917b
350 :setup: MMR with 2 suppliers
351 :steps:
352 1. Add new user
353 2. Delete user - should leave tombstone entry
354 3. Search for tombstone entry
355 4. Try to modrdn with deleteoldrdn
356 :expectedresults:
357 1. Should succeeds
358 2. Should succeeds
359 3. Should succeeds
360 4. Should succeeds
361 """
362 for id_id in [11, 12, 13, 14]:
363 _create_and_delete_tombstone(topo_m2, id_id)
364
365
366 if __name__ == '__main__':
367 # Run isolated
368 # -s for DEBUG mode
369 CURRENT_FILE = os.path.realpath(__file__)
370 pytest.main("-s %s" % CURRENT_FILE)