Debian Codegraph @

dirsrvtests/tests/suites/clu/dbgen_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
13 from lib389.cli_ctl.dbgen import *
14 from lib389.cos import CosClassicDefinitions, CosPointerDefinitions, CosIndirectDefinitions, CosTemplates
15 from lib389.idm.account import Accounts
16 from lib389.idm.group import Groups
17 from lib389.idm.role import ManagedRoles, FilteredRoles, NestedRoles
18 from lib389.tasks import *
19 from lib389.utils import *
20 from test389.topologies import topology_st
21 from lib389.cli_base import FakeArgs
22
23 pytestmark = pytest.mark.tier0
24
25 LOG_FILE = '/tmp/dbgen.log'
26 logging.getLogger(__name__).setLevel(logging.DEBUG)
27 log = logging.getLogger(__name__)
28
29
30 @pytest.fixture(scope="function")
31 def set_log_file_and_ldif(topology_st, request):
32 global ldif_file
33 ldif_file = get_ldif_dir(topology_st.standalone) + '/created.ldif'
34
35 fh = logging.FileHandler(LOG_FILE)
36 fh.setLevel(logging.DEBUG)
37 log.addHandler(fh)
38
39 def fin():
40 log.info('Delete files')
41 os.remove(LOG_FILE)
42 os.remove(ldif_file)
43
44 request.addfinalizer(fin)
45
46
47 def run_offline_import(instance, ldif_file):
48 log.info('Stopping the server and running offline import...')
49 instance.stop()
50 assert instance.ldif2db(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], encrypt=None, excludeSuffixes=None,
51 import_file=ldif_file)
52 instance.start()
53
54
55 def run_ldapmodify_from_file(instance, ldif_file, output_to_check=None):
56 LDAP_MOD = '/usr/bin/ldapmodify'
57 log.info('Add entries from ldif file with ldapmodify')
58 result = subprocess.check_output([LDAP_MOD, '-cx', '-D', DN_DM, '-w', PASSWORD,
59 '-H', f'ldap://{instance.host}:{instance.port}', '-af', ldif_file])
60
61 if output_to_check is not None:
62 assert output_to_check in ensure_str(result)
63
64
65 def check_value_in_log_and_reset(content_list):
66 with open(LOG_FILE, 'r+') as f:
67 file_content = f.read()
68 log.info('Check if content is present in output')
69 for item in content_list:
70 assert item in file_content
71
72 log.info('Reset log file for next test')
73 f.truncate(0)
74
75
76 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
77 def test_dsconf_dbgen_users(topology_st, set_log_file_and_ldif):
78 """Test ldifgen (formerly dbgen) tool to create ldif with users
79
80 :id: 426b5b94-9923-454d-a736-7e71ca985e98
81 :setup: Standalone instance
82 :steps:
83 1. Create DS instance
84 2. Run ldifgen to generate ldif with users
85 3. Import generated ldif to database
86 4. Check it was properly imported
87 :expectedresults:
88 1. Success
89 2. Success
90 3. Success
91 4. Success
92 """
93
94 standalone = topology_st.standalone
95
96 args = FakeArgs()
97 args.suffix = DEFAULT_SUFFIX
98 args.parent = 'ou=people,dc=example,dc=com'
99 args.number = 1000
100 args.rdn_cn = False
101 args.generic = True
102 args.start_idx = 50
103 args.localize = False
104 args.ldif_file = ldif_file
105
106 content_list = ['Generating LDIF with the following options:',
107 'suffix={}'.format(args.suffix),
108 'parent={}'.format(args.parent),
109 'number={}'.format(args.number),
110 'rdn-cn={}'.format(args.rdn_cn),
111 'generic={}'.format(args.generic),
112 'start-idx={}'.format(args.start_idx),
113 'localize={}'.format(args.localize),
114 'ldif-file={}'.format(args.ldif_file),
115 'Writing LDIF',
116 'Successfully created LDIF file: {}'.format(args.ldif_file)]
117
118 log.info('Run ldifgen to create users ldif')
119 dbgen_create_users(standalone, log, args)
120
121 log.info('Check if file exists')
122 assert os.path.exists(ldif_file)
123
124 check_value_in_log_and_reset(content_list)
125
126 log.info('Get number of accounts before import')
127 accounts = Accounts(standalone, DEFAULT_SUFFIX)
128 count_account = len(accounts.filter('(uid=*)'))
129
130 run_offline_import(standalone, ldif_file)
131
132 log.info('Check that accounts are imported')
133 assert len(accounts.filter('(uid=*)')) > count_account
134
135
136 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
137 def test_dsconf_dbgen_groups(topology_st, set_log_file_and_ldif):
138 """Test ldifgen (formerly dbgen) tool to create ldif with group
139
140 :id: 97207413-9a93-4065-a5ec-63aa93801a3f
141 :setup: Standalone instance
142 :steps:
143 1. Create DS instance
144 2. Run ldifgen to generate ldif with group
145 3. Import generated ldif to database
146 4. Check it was properly imported
147 :expectedresults:
148 1. Success
149 2. Success
150 3. Success
151 4. Success
152 """
153 LDAP_RESULT = 'adding new entry "cn=myGroup-1,ou=groups,dc=example,dc=com"'
154
155 standalone = topology_st.standalone
156
157 args = FakeArgs()
158 args.NAME = 'myGroup'
159 args.parent = 'ou=groups,dc=example,dc=com'
160 args.suffix = DEFAULT_SUFFIX
161 args.number = 1
162 args.num_members = 1000
163 args.create_members = True
164 args.member_attr = 'uniquemember'
165 args.member_parent = 'ou=people,dc=example,dc=com'
166 args.ldif_file = ldif_file
167
168 content_list = ['Generating LDIF with the following options:',
169 'NAME={}'.format(args.NAME),
170 'number={}'.format(args.number),
171 'suffix={}'.format(args.suffix),
172 'num-members={}'.format(args.num_members),
173 'create-members={}'.format(args.create_members),
174 'member-parent={}'.format(args.member_parent),
175 'member-attr={}'.format(args.member_attr),
176 'ldif-file={}'.format(args.ldif_file),
177 'Writing LDIF',
178 'Successfully created LDIF file: {}'.format(args.ldif_file)]
179
180 log.info('Run ldifgen to create group ldif')
181 dbgen_create_groups(standalone, log, args)
182
183 log.info('Check if file exists')
184 assert os.path.exists(ldif_file)
185
186 check_value_in_log_and_reset(content_list)
187
188 log.info('Get number of accounts before import')
189 accounts = Accounts(standalone, DEFAULT_SUFFIX)
190 count_account = len(accounts.filter('(uid=*)'))
191
192 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
193 # ldapmodify will complain about already existing parent which causes subprocess to return exit code != 0
194 with pytest.raises(subprocess.CalledProcessError):
195 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
196
197 log.info('Check that accounts are imported')
198 assert len(accounts.filter('(uid=*)')) > count_account
199
200 log.info('Check that group is imported')
201 groups = Groups(standalone, DEFAULT_SUFFIX)
202 assert groups.exists(args.NAME + '-1')
203 new_group = groups.get(args.NAME + '-1')
204 new_group.present('uniquemember', 'uid=group_entry1-0152,ou=people,dc=example,dc=com')
205
206
207 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
208 def test_dsconf_dbgen_cos_classic(topology_st, set_log_file_and_ldif):
209 """Test ldifgen (formerly dbgen) tool to create a COS definition
210
211 :id: 8557f994-8a91-4f8a-86f6-9cb826a0b8fd
212 :setup: Standalone instance
213 :steps:
214 1. Create DS instance
215 2. Run ldifgen to generate ldif with classic COS definition
216 3. Import generated ldif to database
217 4. Check it was properly imported
218 :expectedresults:
219 1. Success
220 2. Success
221 3. Success
222 4. Success
223 """
224
225 LDAP_RESULT = 'adding new entry "cn=My_Postal_Def,ou=cos definitions,dc=example,dc=com"'
226
227 standalone = topology_st.standalone
228
229 args = FakeArgs()
230 args.type = 'classic'
231 args.NAME = 'My_Postal_Def'
232 args.parent = 'ou=cos definitions,dc=example,dc=com'
233 args.create_parent = True
234 args.cos_specifier = 'businessCategory'
235 args.cos_attr = ['postalcode', 'telephonenumber']
236 args.cos_template = 'cn=sales,cn=classicCoS,dc=example,dc=com'
237 args.ldif_file = ldif_file
238
239 content_list = ['Generating LDIF with the following options:',
240 'NAME={}'.format(args.NAME),
241 'type={}'.format(args.type),
242 'parent={}'.format(args.parent),
243 'create-parent={}'.format(args.create_parent),
244 'cos-specifier={}'.format(args.cos_specifier),
245 'cos-template={}'.format(args.cos_template),
246 'cos-attr={}'.format(args.cos_attr),
247 'ldif-file={}'.format(args.ldif_file),
248 'Writing LDIF',
249 'Successfully created LDIF file: {}'.format(args.ldif_file)]
250
251 log.info('Run ldifgen to create COS definition ldif')
252 dbgen_create_cos_def(standalone, log, args)
253
254 log.info('Check if file exists')
255 assert os.path.exists(ldif_file)
256
257 check_value_in_log_and_reset(content_list)
258
259 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
260 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
261
262 log.info('Check that COS definition is imported')
263 cos_def = CosClassicDefinitions(standalone, args.parent)
264 assert cos_def.exists(args.NAME)
265 new_cos = cos_def.get(args.NAME)
266 assert new_cos.present('cosTemplateDN', args.cos_template)
267 assert new_cos.present('cosSpecifier', args.cos_specifier)
268 assert new_cos.present('cosAttribute', args.cos_attr[0])
269 assert new_cos.present('cosAttribute', args.cos_attr[1])
270
271
272 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
273 def test_dsconf_dbgen_cos_pointer(topology_st, set_log_file_and_ldif):
274 """Test ldifgen (formerly dbgen) tool to create a COS definition
275
276 :id: 6b26ca6d-226a-4f93-925e-faf95cc20214
277 :setup: Standalone instance
278 :steps:
279 1. Create DS instance
280 2. Run ldifgen to generate ldif with pointer COS definition
281 3. Import generated ldif to database
282 4. Check it was properly imported
283 :expectedresults:
284 1. Success
285 2. Success
286 3. Success
287 4. Success
288 """
289
290 LDAP_RESULT = 'adding new entry "cn=My_Postal_Def_pointer,ou=cos pointer definitions,dc=example,dc=com"'
291
292 standalone = topology_st.standalone
293
294 args = FakeArgs()
295 args.type = 'pointer'
296 args.NAME = 'My_Postal_Def_pointer'
297 args.parent = 'ou=cos pointer definitions,dc=example,dc=com'
298 args.create_parent = True
299 args.cos_specifier = None
300 args.cos_attr = ['postalcode', 'telephonenumber']
301 args.cos_template = 'cn=sales,cn=pointerCoS,dc=example,dc=com'
302 args.ldif_file = ldif_file
303
304 content_list = ['Generating LDIF with the following options:',
305 'NAME={}'.format(args.NAME),
306 'type={}'.format(args.type),
307 'parent={}'.format(args.parent),
308 'create-parent={}'.format(args.create_parent),
309 'cos-template={}'.format(args.cos_template),
310 'cos-attr={}'.format(args.cos_attr),
311 'ldif-file={}'.format(args.ldif_file),
312 'Writing LDIF',
313 'Successfully created LDIF file: {}'.format(args.ldif_file)]
314
315 log.info('Run ldifgen to create COS definition ldif')
316 dbgen_create_cos_def(standalone, log, args)
317
318 log.info('Check if file exists')
319 assert os.path.exists(ldif_file)
320
321 check_value_in_log_and_reset(content_list)
322
323 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
324 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
325
326 log.info('Check that COS definition is imported')
327 cos_def = CosPointerDefinitions(standalone, args.parent)
328 assert cos_def.exists(args.NAME)
329 new_cos = cos_def.get(args.NAME)
330 assert new_cos.present('cosTemplateDN', args.cos_template)
331 assert new_cos.present('cosAttribute', args.cos_attr[0])
332 assert new_cos.present('cosAttribute', args.cos_attr[1])
333
334
335 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
336 def test_dsconf_dbgen_cos_indirect(topology_st, set_log_file_and_ldif):
337 """Test ldifgen (formerly dbgen) tool to create a COS definition
338
339 :id: ab4b799e-e801-432a-a61d-badad2628203
340 :setup: Standalone instance
341 :steps:
342 1. Create DS instance
343 2. Run ldifgen to generate ldif with indirect COS definition
344 3. Import generated ldif to database
345 4. Check it was properly imported
346 :expectedresults:
347 1. Success
348 2. Success
349 3. Success
350 4. Success
351 """
352
353 LDAP_RESULT = 'adding new entry "cn=My_Postal_Def_indirect,ou=cos indirect definitions,dc=example,dc=com"'
354
355 standalone = topology_st.standalone
356
357 args = FakeArgs()
358 args.type = 'indirect'
359 args.NAME = 'My_Postal_Def_indirect'
360 args.parent = 'ou=cos indirect definitions,dc=example,dc=com'
361 args.create_parent = True
362 args.cos_specifier = 'businessCategory'
363 args.cos_attr = ['postalcode', 'telephonenumber']
364 args.cos_template = None
365 args.ldif_file = ldif_file
366
367 content_list = ['Generating LDIF with the following options:',
368 'NAME={}'.format(args.NAME),
369 'type={}'.format(args.type),
370 'parent={}'.format(args.parent),
371 'create-parent={}'.format(args.create_parent),
372 'cos-specifier={}'.format(args.cos_specifier),
373 'cos-attr={}'.format(args.cos_attr),
374 'ldif-file={}'.format(args.ldif_file),
375 'Writing LDIF',
376 'Successfully created LDIF file: {}'.format(args.ldif_file)]
377
378 log.info('Run ldifgen to create COS definition ldif')
379 dbgen_create_cos_def(standalone, log, args)
380
381 log.info('Check if file exists')
382 assert os.path.exists(ldif_file)
383
384 check_value_in_log_and_reset(content_list)
385
386 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
387 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
388
389 log.info('Check that COS definition is imported')
390 cos_def = CosIndirectDefinitions(standalone, args.parent)
391 assert cos_def.exists(args.NAME)
392 new_cos = cos_def.get(args.NAME)
393 assert new_cos.present('cosIndirectSpecifier', args.cos_specifier)
394 assert new_cos.present('cosAttribute', args.cos_attr[0])
395 assert new_cos.present('cosAttribute', args.cos_attr[1])
396
397
398 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
399 def test_dsconf_dbgen_cos_template(topology_st, set_log_file_and_ldif):
400 """Test ldifgen (formerly dbgen) tool to create a COS template
401
402 :id: 544017c7-4a82-4e7d-a047-00b68a28e070
403 :setup: Standalone instance
404 :steps:
405 1. Create DS instance
406 2. Run ldifgen to generate ldif with COS template
407 3. Import generated ldif to database
408 4. Check it was properly imported
409 :expectedresults:
410 1. Success
411 2. Success
412 3. Success
413 4. Success
414 """
415
416 LDAP_RESULT = 'adding new entry "cn=My_Template,ou=cos templates,dc=example,dc=com"'
417
418 standalone = topology_st.standalone
419
420 args = FakeArgs()
421 args.NAME = 'My_Template'
422 args.parent = 'ou=cos templates,dc=example,dc=com'
423 args.create_parent = True
424 args.cos_priority = 1
425 args.cos_attr_val = 'postalcode:12345'
426 args.ldif_file = ldif_file
427
428 content_list = ['Generating LDIF with the following options:',
429 'NAME={}'.format(args.NAME),
430 'parent={}'.format(args.parent),
431 'create-parent={}'.format(args.create_parent),
432 'cos-priority={}'.format(args.cos_priority),
433 'cos-attr-val={}'.format(args.cos_attr_val),
434 'ldif-file={}'.format(args.ldif_file),
435 'Writing LDIF',
436 'Successfully created LDIF file: {}'.format(args.ldif_file)]
437
438 log.info('Run ldifgen to create COS template ldif')
439 dbgen_create_cos_tmp(standalone, log, args)
440
441 log.info('Check if file exists')
442 assert os.path.exists(ldif_file)
443
444 check_value_in_log_and_reset(content_list)
445
446 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
447 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
448
449 log.info('Check that COS template is imported')
450 cos_temp = CosTemplates(standalone, args.parent)
451 assert cos_temp.exists(args.NAME)
452 new_cos = cos_temp.get(args.NAME)
453 assert new_cos.present('cosPriority', str(args.cos_priority))
454 assert new_cos.present('postalcode', '12345')
455
456
457 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
458 def test_dsconf_dbgen_managed_role(topology_st, set_log_file_and_ldif):
459 """Test ldifgen (formerly dbgen) tool to create a managed role
460
461 :id: 10e77b41-0bc1-4ad5-a144-2c5107455b92
462 :setup: Standalone instance
463 :steps:
464 1. Create DS instance
465 2. Run ldifgen to generate ldif with managed role
466 3. Import generated ldif to database
467 4. Check it was properly imported
468 :expectedresults:
469 1. Success
470 2. Success
471 3. Success
472 4. Success
473 """
474
475 LDAP_RESULT = 'adding new entry "cn=My_Managed_Role,ou=managed roles,dc=example,dc=com"'
476
477 standalone = topology_st.standalone
478
479 args = FakeArgs()
480
481 args.NAME = 'My_Managed_Role'
482 args.parent = 'ou=managed roles,dc=example,dc=com'
483 args.create_parent = True
484 args.type = 'managed'
485 args.filter = None
486 args.role_dn = None
487 args.ldif_file = ldif_file
488
489 content_list = ['Generating LDIF with the following options:',
490 'NAME={}'.format(args.NAME),
491 'parent={}'.format(args.parent),
492 'create-parent={}'.format(args.create_parent),
493 'type={}'.format(args.type),
494 'ldif-file={}'.format(args.ldif_file),
495 'Writing LDIF',
496 'Successfully created LDIF file: {}'.format(args.ldif_file)]
497
498 log.info('Run ldifgen to create managed role ldif')
499 dbgen_create_role(standalone, log, args)
500
501 log.info('Check if file exists')
502 assert os.path.exists(ldif_file)
503
504 check_value_in_log_and_reset(content_list)
505
506 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
507 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
508
509 log.info('Check that managed role is imported')
510 roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
511 assert roles.exists(args.NAME)
512
513
514 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
515 def test_dsconf_dbgen_filtered_role(topology_st, set_log_file_and_ldif):
516 """Test ldifgen (formerly dbgen) tool to create a filtered role
517
518 :id: cb3c8ea8-4234-40e2-8810-fb6a25973927
519 :setup: Standalone instance
520 :steps:
521 1. Create DS instance
522 2. Run ldifgen to generate ldif with filtered role
523 3. Import generated ldif to database
524 4. Check it was properly imported
525 :expectedresults:
526 1. Success
527 2. Success
528 3. Success
529 4. Success
530 """
531
532 LDAP_RESULT = 'adding new entry "cn=My_Filtered_Role,ou=filtered roles,dc=example,dc=com"'
533
534 standalone = topology_st.standalone
535
536 args = FakeArgs()
537
538 args.NAME = 'My_Filtered_Role'
539 args.parent = 'ou=filtered roles,dc=example,dc=com'
540 args.create_parent = True
541 args.type = 'filtered'
542 args.filter = '"objectclass=posixAccount"'
543 args.role_dn = None
544 args.ldif_file = ldif_file
545
546 content_list = ['Generating LDIF with the following options:',
547 'NAME={}'.format(args.NAME),
548 'parent={}'.format(args.parent),
549 'create-parent={}'.format(args.create_parent),
550 'type={}'.format(args.type),
551 'filter={}'.format(args.filter),
552 'ldif-file={}'.format(args.ldif_file),
553 'Writing LDIF',
554 'Successfully created LDIF file: {}'.format(args.ldif_file)]
555
556 log.info('Run ldifgen to create filtered role ldif')
557 dbgen_create_role(standalone, log, args)
558
559 log.info('Check if file exists')
560 assert os.path.exists(ldif_file)
561
562 check_value_in_log_and_reset(content_list)
563
564 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
565 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
566
567 log.info('Check that filtered role is imported')
568 roles = FilteredRoles(standalone, DEFAULT_SUFFIX)
569 assert roles.exists(args.NAME)
570 new_role = roles.get(args.NAME)
571 assert new_role.present('nsRoleFilter', args.filter)
572
573
574 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
575 def test_dsconf_dbgen_nested_role(topology_st, set_log_file_and_ldif):
576 """Test ldifgen (formerly dbgen) tool to create a nested role
577
578 :id: 97fff0a8-3103-4adb-be04-2799ff58d8f4
579 :setup: Standalone instance
580 :steps:
581 1. Create DS instance
582 2. Run ldifgen to generate ldif with nested role
583 3. Import generated ldif to database
584 4. Check it was properly imported
585 :expectedresults:
586 1. Success
587 2. Success
588 3. Success
589 4. Success
590 """
591
592 LDAP_RESULT = 'adding new entry "cn=My_Nested_Role,ou=nested roles,dc=example,dc=com"'
593
594 standalone = topology_st.standalone
595
596 args = FakeArgs()
597 args.NAME = 'My_Nested_Role'
598 args.parent = 'ou=nested roles,dc=example,dc=com'
599 args.create_parent = True
600 args.type = 'nested'
601 args.filter = None
602 args.role_dn = ['cn=some_role,ou=roles,dc=example,dc=com']
603 args.ldif_file = ldif_file
604
605 content_list = ['Generating LDIF with the following options:',
606 'NAME={}'.format(args.NAME),
607 'parent={}'.format(args.parent),
608 'create-parent={}'.format(args.create_parent),
609 'type={}'.format(args.type),
610 'role-dn={}'.format(args.role_dn),
611 'ldif-file={}'.format(args.ldif_file),
612 'Writing LDIF',
613 'Successfully created LDIF file: {}'.format(args.ldif_file)]
614
615 log.info('Run ldifgen to create nested role ldif')
616 dbgen_create_role(standalone, log, args)
617
618 log.info('Check if file exists')
619 assert os.path.exists(ldif_file)
620
621 check_value_in_log_and_reset(content_list)
622
623 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
624 run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
625
626 log.info('Check that nested role is imported')
627 roles = NestedRoles(standalone, DEFAULT_SUFFIX)
628 assert roles.exists(args.NAME)
629 new_role = roles.get(args.NAME)
630 assert new_role.present('nsRoleDN', args.role_dn[0])
631
632
633 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
634 def test_dsconf_dbgen_mod_ldif_mixed(topology_st, set_log_file_and_ldif):
635 """Test ldifgen (formerly dbgen) tool to create mixed modification ldif
636
637 :id: 4a2e0901-2b48-452e-a4a0-507735132c8d
638 :setup: Standalone instance
639 :steps:
640 1. Create DS instance
641 2. Run ldifgen to generate modification ldif
642 3. Import generated ldif to database
643 4. Check it was properly imported
644 :expectedresults:
645 1. Success
646 2. Success
647 3. Success
648 4. Success
649 """
650
651 standalone = topology_st.standalone
652
653 args = FakeArgs()
654 args.parent = DEFAULT_SUFFIX
655 args.create_users = True
656 args.delete_users = True
657 args.create_parent = False
658 args.num_users = 1000
659 args.add_users = 100
660 args.del_users = 999
661 args.modrdn_users = 100
662 args.mod_users = 10
663 args.mod_attrs = ['cn', 'uid', 'sn']
664 args.randomize = False
665 args.ldif_file = ldif_file
666
667 content_list = ['Generating LDIF with the following options:',
668 'create-users={}'.format(args.create_users),
669 'parent={}'.format(args.parent),
670 'create-parent={}'.format(args.create_parent),
671 'delete-users={}'.format(args.delete_users),
672 'num-users={}'.format(args.num_users),
673 'add-users={}'.format(args.add_users),
674 'del-users={}'.format(args.del_users),
675 'modrdn-users={}'.format(args.modrdn_users),
676 'mod-users={}'.format(args.mod_users),
677 'mod-attrs={}'.format(args.mod_attrs),
678 'randomize={}'.format(args.randomize),
679 'ldif-file={}'.format(args.ldif_file),
680 'Writing LDIF',
681 'Successfully created LDIF file: {}'.format(args.ldif_file)]
682
683 log.info('Run ldifgen to create modification ldif')
684 dbgen_create_mods(standalone, log, args)
685
686 log.info('Check if file exists')
687 assert os.path.exists(ldif_file)
688
689 check_value_in_log_and_reset(content_list)
690
691 log.info('Get number of accounts before import')
692 accounts = Accounts(standalone, DEFAULT_SUFFIX)
693 count_account = len(accounts.filter('(uid=*)'))
694
695 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
696 # ldapmodify will complain about a lot of changes done which causes subprocess to return exit code != 0
697 with pytest.raises(subprocess.CalledProcessError):
698 run_ldapmodify_from_file(standalone, ldif_file)
699
700 log.info('Check that some accounts are imported')
701 assert len(accounts.filter('(uid=*)')) > count_account
702
703
704 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
705 def test_dsconf_dbgen_nested_ldif(topology_st, set_log_file_and_ldif):
706 """Test ldifgen (formerly dbgen) tool to create nested ldif
707
708 :id: 9c281c28-4169-45e0-8c07-c5502d9a7585
709 :setup: Standalone instance
710 :steps:
711 1. Create DS instance
712 2. Run ldifgen to generate nested ldif
713 3. Import generated ldif to database
714 4. Check it was properly imported
715 :expectedresults:
716 1. Success
717 2. Success
718 3. Success
719 4. Success
720 """
721
722 standalone = topology_st.standalone
723
724 args = FakeArgs()
725 args.suffix = DEFAULT_SUFFIX
726 args.node_limit = 100
727 args.num_users = 600
728 args.ldif_file = ldif_file
729
730 content_list = ['Generating LDIF with the following options:',
731 'suffix={}'.format(args.suffix),
732 'node-limit={}'.format(args.node_limit),
733 'num-users={}'.format(args.num_users),
734 'ldif-file={}'.format(args.ldif_file),
735 'Writing LDIF',
736 'Successfully created nested LDIF file ({}) containing 6 nodes/subtrees'.format(args.ldif_file)]
737
738 log.info('Run ldifgen to create nested ldif')
739 dbgen_create_nested(standalone, log, args)
740
741 log.info('Check if file exists')
742 assert os.path.exists(ldif_file)
743
744 check_value_in_log_and_reset(content_list)
745
746 log.info('Get number of accounts before import')
747 accounts = Accounts(standalone, DEFAULT_SUFFIX)
748 count_account = len(accounts.filter('(uid=*)'))
749 count_ou = len(accounts.filter('(ou=*)'))
750
751 # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
752 # ldapmodify will complain about already existing suffix which causes subprocess to return exit code != 0
753 with pytest.raises(subprocess.CalledProcessError):
754 run_ldapmodify_from_file(standalone, ldif_file)
755
756 standalone.restart()
757
758 log.info('Check that accounts are imported')
759 assert len(accounts.filter('(uid=*)')) > count_account
760 assert len(accounts.filter('(ou=*)')) > count_ou
761
762
763 if __name__ == '__main__':
764 # Run isolated
765 # -s for DEBUG mode
766 CURRENT_FILE = os.path.realpath(__file__)
767 pytest.main("-s %s" % CURRENT_FILE)