Debian Codegraph @

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