Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_organizational_unit_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 time
10 import subprocess
11 import pytest
12 import logging
13 import os
14 import json
15
16 from lib389 import DEFAULT_SUFFIX
17 from lib389.cli_idm.organizationalunit import get, get_dn, create, modify, delete, list, rename
18 from test389.topologies import topology_st
19 from lib389.cli_base import FakeArgs
20 from lib389.utils import ds_is_older, is_a_dn
21 from lib389.idm.organizationalunit import OrganizationalUnits
22 from . import check_value_in_log_and_reset
23
24 pytestmark = pytest.mark.tier0
25
26 logging.getLogger(__name__).setLevel(logging.DEBUG)
27 log = logging.getLogger(__name__)
28
29 ou_name = 'test_ou'
30
31 @pytest.fixture(scope="function")
32 def create_test_ou(topology_st, request):
33 log.info('Create organizational unit')
34 ous = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX)
35 if ous.exists(ou_name):
36 test_ou = ous.get(ou_name)
37 test_ou.delete()
38
39 test_ou = ous.create(properties={
40 'ou': ou_name,
41 'description': 'Test OU',
42 })
43
44 def fin():
45 log.info('Delete organizational unit')
46 if test_ou.exists():
47 test_ou.delete()
48
49 request.addfinalizer(fin)
50
51
52 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
53 def test_dsidm_organizational_unit_create(topology_st):
54 """ Test dsidm organizationalunit create
55
56 :id: 9bfd63d6-6689-436e-bad1-f18b7bcff471
57 :setup: Standalone instance
58 :steps:
59 1. Run dsidm organizationalunit create
60 2. Check that a message is provided on creation
61 3. Check that created organizational unit exists
62 :expectedresults:
63 1. Success
64 2. Success
65 3. Success
66 """
67
68 standalone = topology_st.standalone
69 output = 'Successfully created {}'.format(ou_name)
70
71 args = FakeArgs()
72 args.ou = ou_name
73
74 log.info('Test dsidm organizationalunit create')
75 create(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
76 check_value_in_log_and_reset(topology_st, check_value=output)
77
78 log.info('Check that organizational unit is present')
79 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
80 new_ou = ous.get(ou_name)
81 assert new_ou.exists()
82
83 log.info('Clean up for next test')
84 new_ou.delete()
85
86
87 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
88 def test_dsidm_organizational_unit_list(topology_st, create_test_ou):
89 """ Test dsidm organizationalunit list option
90
91 :id: 14f1fb93-64e2-41f9-b3fd-d0cea3bd2ea1
92 :setup: Standalone instance
93 :steps:
94 1. Run dsidm organizationalunit list option without json
95 2. Check the output content is correct
96 3. Run dsidm organizationalunit list option with json
97 4. Check the output content is correct
98 5. Delete the organizational unit
99 6. Check the organizational unit is not in the list with json
100 7. Check the organizational unit is not in the list without json
101 :expectedresults:
102 1. Success
103 2. Success
104 3. Success
105 4. Success
106 5. Success
107 6. Success
108 7. Success
109 """
110
111 standalone = topology_st.standalone
112 args = FakeArgs()
113 args.json = False
114 args.full_dn = False
115 json_list = ['type',
116 'list',
117 'items']
118
119 log.info('Empty the log file to prevent false data to check about group')
120 topology_st.logcap.flush()
121
122 log.info('Test dsidm organizationalunit list without json')
123 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
124 check_value_in_log_and_reset(topology_st, check_value=ou_name)
125
126 log.info('Test dsidm organizationalunit list with json')
127 args.json = True
128 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
129 check_value_in_log_and_reset(topology_st, check_value=ou_name)
130
131 log.info('Test full_dn option with list')
132 args.full_dn = True
133 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
134 result = topology_st.logcap.get_raw_outputs()
135 json_result = json.loads(result[0])
136 assert is_a_dn(json_result['items'][0])
137 args.full_dn = False
138
139 log.info('Delete the organizational unit')
140 topology_st.logcap.flush()
141 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
142 test_ou = ous.get(ou_name)
143 test_ou.delete()
144
145 log.info('Test empty dsidm organizationalunit list with json')
146 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
147 check_value_in_log_and_reset(topology_st, content_list=json_list, check_value_not=ou_name)
148
149 log.info('Test empty dsidm organizationalunit list without json')
150 args.json = False
151 list(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
152 check_value_in_log_and_reset(topology_st, check_value_not=ou_name)
153
154
155 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
156 def test_dsidm_organizational_unit_modify(topology_st, create_test_ou):
157 """ Test dsidm organizationalunit modify option
158
159 :id: 20159281-ebcb-4126-aef5-0c2b24ece5df
160 :setup: Standalone instance
161 :steps:
162 1. Run dsidm organizationalunit modify add description value
163 2. Run dsidm organizationalunit modify replace description value
164 3. Run dsidm organizationalunit modify delete description value
165 :expectedresults:
166 1. Description value is present
167 2. Description value is replaced with the new one
168 3. Description value is deleted
169 """
170
171 standalone = topology_st.standalone
172 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
173 test_ou = ous.get(ou_name)
174 output = 'Successfully modified {}'.format(test_ou.dn)
175
176 args = FakeArgs()
177 args.selector = ou_name
178
179 log.info('Test dsidm organizationalunit modify add')
180 args.changes = ['add:description:test']
181 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
182 check_value_in_log_and_reset(topology_st, check_value=output)
183 assert test_ou.present('description', 'test')
184
185 log.info('Test dsidm organizationalunit modify replace')
186 args.changes = ['replace:description:replaced']
187 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
188 check_value_in_log_and_reset(topology_st, check_value=output)
189 assert test_ou.present('description', 'replaced')
190
191 log.info('Test dsidm organizationalunit modify delete')
192 args.changes = ['delete:description:replaced']
193 modify(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
194 check_value_in_log_and_reset(topology_st, check_value=output)
195 assert not test_ou.present('description', 'replaced')
196
197
198 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
199 def test_dsidm_organizational_unit_get_rdn(topology_st, create_test_ou):
200 """ Test dsidm organizationalunit get option
201
202 :id: 56840d36-fa23-4f0c-9682-ca90d9f2923e
203 :setup: Standalone instance
204 :steps:
205 1. Run dsidm get option for created organizational unit with json
206 2. Check the output content is correct
207 3. Run dsidm get option for created organizational unit without json
208 4. Check the json content is correct
209 :expectedresults:
210 1. Success
211 2. Success
212 3. Success
213 4. Success
214 """
215
216 standalone = topology_st.standalone
217 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
218 test_ou = ous.get(ou_name)
219
220 ou_content = ['dn: {}'.format(test_ou.dn),
221 'ou: {}'.format(test_ou.rdn),
222 'description: Test OU',
223 'objectClass: top',
224 'objectClass: organizationalunit']
225
226 json_content = ['attrs',
227 'objectclass',
228 'top',
229 'organizationalunit',
230 'ou',
231 test_ou.rdn,
232 'creatorsname',
233 'cn=directory manager',
234 'modifiersname',
235 'createtimestamp',
236 'modifytimestamp',
237 'nsuniqueid',
238 'parentid',
239 'entryid',
240 'entryuuid',
241 'description',
242 'Test OU',
243 'dsentrydn',
244 'entrydn',
245 test_ou.dn]
246
247 args = FakeArgs()
248 args.json = False
249 args.selector = ou_name
250
251 log.info('Empty the log file to prevent false data to check about organizational unit')
252 topology_st.logcap.flush()
253
254 log.info('Test dsidm organizationalunit get without json')
255 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
256 check_value_in_log_and_reset(topology_st, content_list=ou_content)
257
258 log.info('Test dsidm organizationalunit get with json')
259 args.json = True
260 get(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
261 check_value_in_log_and_reset(topology_st, content_list=json_content)
262
263
264 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
265 def test_dsidm_organizational_unit_rename(topology_st, create_test_ou):
266 """ Test dsidm organizationalunit rename option
267
268 :id: c1fe31c1-748d-4d8c-aa77-c770be13bfa4
269 :setup: Standalone instance
270 :steps:
271 1. Run dsidm organizationalunit rename option on created organizational unit
272 2. Check the organizational unit does not have another ou attribute with the old rdn
273 3. Check the old organizational unit is deleted
274 :expectedresults:
275 1. Success
276 2. Success
277 3. Success
278 """
279
280 standalone = topology_st.standalone
281 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
282 test_ou = ous.get(ou_name)
283
284 args = FakeArgs()
285 args.selector = ou_name
286 args.new_name = 'new_ou'
287 args.keep_old_rdn = False
288
289 log.info('Test dsidm organizationalunit rename')
290 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
291 new_ou = ous.get(args.new_name)
292 output = 'Successfully renamed to {}'.format(new_ou.dn)
293 check_value_in_log_and_reset(topology_st, check_value=output)
294
295 log.info('Verify the new organizational unit does not have ou attribute with the old rdn')
296 assert not new_ou.present('ou', ou_name)
297 assert new_ou.get_attr_val_utf8('description') == 'Test OU'
298
299 log.info('Verify old organizational unit dn does not exist')
300 assert not test_ou.exists()
301
302 log.info('Clean up')
303 new_ou.delete()
304
305
306 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
307 def test_dsidm_organizational_unit_rename_keep_old_rdn(topology_st, create_test_ou):
308 """ Test dsidm organizationalunit rename option with keep-old-rdn
309
310 :id: 398e2734-abc8-48ba-9dc0-9489368fa625
311 :setup: Standalone instance
312 :steps:
313 1. Run dsidm organizationalunit rename option on created organizational unit with keep-old-rdn
314 2. Check the organizational unit has another ou attribute with the old rdn
315 3. Check the old organizational unit is deleted
316 :expectedresults:
317 1. Success
318 2. Success
319 3. Success
320 """
321
322 standalone = topology_st.standalone
323 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
324 test_ou = ous.get(ou_name)
325
326 args = FakeArgs()
327 args.selector = ou_name
328 args.new_name = 'new_ou'
329 args.keep_old_rdn = True
330
331 log.info('Test dsidm organizationalunit rename with keep-old-rdn')
332 rename(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
333 new_ou = ous.get(args.new_name)
334 output = 'Successfully renamed to {}'.format(new_ou.dn)
335 check_value_in_log_and_reset(topology_st, check_value=output)
336
337 log.info('Verify the new organizational unit has ou attribute with the old rdn')
338 assert new_ou.present('ou', ou_name)
339 assert new_ou.get_attr_val_utf8('description') == 'Test OU'
340
341 log.info('Verify old organizational unit dn does not exist')
342 assert not test_ou.exists()
343
344 log.info('Clean up')
345 new_ou.delete()
346
347
348 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
349 def test_dsidm_organizational_unit_get_dn(topology_st, create_test_ou):
350 """ Test dsidm organizationalunit get_dn option
351
352 :id: e2b8370e-cb75-4d71-b3c5-364a970366c7
353 :setup: Standalone instance
354 :steps:
355 1. Run dsidm organizationalunit get_dn for a created group without json
356 2. Check the output content is correct
357 3. Run dsidm organizationalunit get_dn for a created group with json
358 4. Check the output content is correct
359 :expectedresults:
360 1. Success
361 2. Success
362 3. Success
363 4. Success
364 """
365
366 standalone = topology_st.standalone
367 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
368 test_ou = ous.get(ou_name)
369
370 args = FakeArgs()
371 args.dn = test_ou.dn
372 args.json = False
373
374 log.info('Empty the log file to prevent false data to check about organizational unit')
375 topology_st.logcap.flush()
376
377 log.info('Test dsidm organizationalunit get_dn without json')
378 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
379 check_value_in_log_and_reset(topology_st, content_list=ou_name)
380
381 log.info('Test dsidm organizationalunit get_dn with json')
382 args.json = True
383 get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
384 check_value_in_log_and_reset(topology_st, content_list=ou_name)
385
386
387 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
388 @pytest.mark.xfail(ds_is_older("1.4.3.16"), reason="Might fail because of bz1866294")
389 def test_dsidm_organizational_unit_delete(topology_st, create_test_ou):
390 """ Test dsidm organizationalunit delete
391
392 :id: 5d35a5ee-85c2-4b83-9101-938ba7732ccd
393 :customerscenario: True
394 :setup: Standalone instance
395 :steps:
396 1. Run dsidm organizationalunit delete
397 2. Check the ou is deleted
398 :expectedresults:
399 1. Success
400 2. Entry is deleted
401 """
402
403 standalone = topology_st.standalone
404 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
405 test_ou = ous.get(ou_name)
406 delete_value = 'Successfully deleted {}'.format(test_ou.dn)
407
408 args = FakeArgs()
409 args.dn = test_ou.dn
410
411 log.info('Test dsidm organizationalunit delete')
412 delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False)
413 check_value_in_log_and_reset(topology_st, check_value=delete_value)
414
415 log.info('Check the entry is deleted')
416 assert not test_ou.exists()
417
418
419 if __name__ == '__main__':
420 # Run isolated
421 # -s for DEBUG mode
422 CURRENT_FILE = os.path.realpath(__file__)
423 pytest.main("-s %s" % CURRENT_FILE)