Blame SOURCES/0009-Issue-4440-BUG-ldifgen-with-start-idx-option-fails-w.patch

be9751
From 201cb1147c0a34bddbd3e5c03aecd804c47a9905 Mon Sep 17 00:00:00 2001
be9751
From: progier389 <72748589+progier389@users.noreply.github.com>
be9751
Date: Thu, 19 Nov 2020 10:21:10 +0100
be9751
Subject: [PATCH 2/2] Issue 4440 - BUG - ldifgen with --start-idx option fails
be9751
 with unsupported operand (#4444)
be9751
be9751
Bug description:
be9751
Got TypeError exception when usign:
be9751
  dsctl -v slapd-localhost ldifgen users --suffix
be9751
     dc=example,dc=com --parent ou=people,dc=example,dc=com
be9751
     --number 100000 --generic --start-idx=50
be9751
The reason is that by default python parser provides
be9751
 value for numeric options:
be9751
  as an integer if specified by "--option value" or
be9751
  as a string if specified by "--option=value"
be9751
be9751
Fix description:
be9751
convert the numeric parameters to integer when using it.
be9751
 options impacted are:
be9751
  - in users subcommand:   --number ,  --start-idx
be9751
  - in mod-load subcommand:   --num-users, --add-users,
be9751
               --del-users, --modrdn-users, --mod-users
be9751
be9751
FYI: An alternative solution would have been to indicate the
be9751
parser that these values are an integer. But two reasons
be9751
 leaded me to implement the first solution:
be9751
 - first solution fix the problem for all users while the
be9751
   second one fixes only dsctl command.
be9751
 - first solution is easier to test:
be9751
    I just added a new test file generated by a script
be9751
      that duplicated existing ldifgen test, renamed the
be9751
       test cases and replaced the numeric arguments by
be9751
       strings.
be9751
   Second solution would need to redesign the test framework
be9751
    to be able to test the parser.
be9751
be9751
relates: https://github.com/389ds/389-ds-base/issues/4440
be9751
be9751
Reviewed by:
be9751
be9751
Platforms tested: F32
be9751
be9751
(cherry picked from commit 3c3e1f30cdb046a1aabb93aacebcf261a76a0892)
be9751
---
be9751
 .../tests/suites/clu/dbgen_test_usan.py       | 806 ++++++++++++++++++
be9751
 src/lib389/lib389/cli_ctl/dbgen.py            |  10 +-
be9751
 src/lib389/lib389/dbgen.py                    |   3 +
be9751
 3 files changed, 814 insertions(+), 5 deletions(-)
be9751
 create mode 100644 dirsrvtests/tests/suites/clu/dbgen_test_usan.py
be9751
be9751
diff --git a/dirsrvtests/tests/suites/clu/dbgen_test_usan.py b/dirsrvtests/tests/suites/clu/dbgen_test_usan.py
be9751
new file mode 100644
be9751
index 000000000..80ff63417
be9751
--- /dev/null
be9751
+++ b/dirsrvtests/tests/suites/clu/dbgen_test_usan.py
be9751
@@ -0,0 +1,806 @@
be9751
+# --- BEGIN COPYRIGHT BLOCK ---
be9751
+# Copyright (C) 2020 Red Hat, Inc.
be9751
+# All rights reserved.
be9751
+#
be9751
+# License: GPL (version 3 or any later version).
be9751
+# See LICENSE for details.
be9751
+# --- END COPYRIGHT BLOCK ---
be9751
+#
be9751
+import time
be9751
+
be9751
+"""
be9751
+ This file contains tests similar to dbgen_test.py
be9751
+ except that paramaters that are number are expressed as string
be9751
+ (to mimic the parameters parser default behavior which returns an
be9751
+   int when parsing "option value" and a string when parsing "option=value"
be9751
+ This file has been generated by usign:
be9751
+sed '
be9751
+9r z1
be9751
+s/ test_/ test_usan/
be9751
+/args.*= [0-9]/s,[0-9]*$,"&",
be9751
+/:id:/s/.$/1/
be9751
+' dbgen_test.py > dbgen_test_usan.py
be9751
+ ( with z1 file containing this comment )
be9751
+"""
be9751
+
be9751
+ 
be9751
+
be9751
+import subprocess
be9751
+import pytest
be9751
+
be9751
+from lib389.cli_ctl.dbgen import *
be9751
+from lib389.cos import CosClassicDefinitions, CosPointerDefinitions, CosIndirectDefinitions, CosTemplates
be9751
+from lib389.idm.account import Accounts
be9751
+from lib389.idm.group import Groups
be9751
+from lib389.idm.role import ManagedRoles, FilteredRoles, NestedRoles
be9751
+from lib389.tasks import *
be9751
+from lib389.utils import *
be9751
+from lib389.topologies import topology_st
be9751
+from lib389.cli_base import FakeArgs
be9751
+
be9751
+pytestmark = pytest.mark.tier0
be9751
+
be9751
+LOG_FILE = '/tmp/dbgen.log'
be9751
+logging.getLogger(__name__).setLevel(logging.DEBUG)
be9751
+log = logging.getLogger(__name__)
be9751
+
be9751
+
be9751
+@pytest.fixture(scope="function")
be9751
+def set_log_file_and_ldif(topology_st, request):
be9751
+    global ldif_file
be9751
+    ldif_file = get_ldif_dir(topology_st.standalone) + '/created.ldif'
be9751
+
be9751
+    fh = logging.FileHandler(LOG_FILE)
be9751
+    fh.setLevel(logging.DEBUG)
be9751
+    log.addHandler(fh)
be9751
+
be9751
+    def fin():
be9751
+        log.info('Delete files')
be9751
+        os.remove(LOG_FILE)
be9751
+        os.remove(ldif_file)
be9751
+
be9751
+    request.addfinalizer(fin)
be9751
+
be9751
+
be9751
+def run_offline_import(instance, ldif_file):
be9751
+    log.info('Stopping the server and running offline import...')
be9751
+    instance.stop()
be9751
+    assert instance.ldif2db(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], encrypt=None, excludeSuffixes=None,
be9751
+                              import_file=ldif_file)
be9751
+    instance.start()
be9751
+
be9751
+
be9751
+def run_ldapmodify_from_file(instance, ldif_file, output_to_check=None):
be9751
+    LDAP_MOD = '/usr/bin/ldapmodify'
be9751
+    log.info('Add entries from ldif file with ldapmodify')
be9751
+    result = subprocess.check_output([LDAP_MOD, '-cx', '-D', DN_DM, '-w', PASSWORD,
be9751
+                                      '-h', instance.host, '-p', str(instance.port), '-af', ldif_file])
be9751
+    if output_to_check is not None:
be9751
+        assert output_to_check in ensure_str(result)
be9751
+
be9751
+
be9751
+def check_value_in_log_and_reset(content_list):
be9751
+    with open(LOG_FILE, 'r+') as f:
be9751
+        file_content = f.read()
be9751
+        log.info('Check if content is present in output')
be9751
+        for item in content_list:
be9751
+            assert item in file_content
be9751
+
be9751
+        log.info('Reset log file for next test')
be9751
+        f.truncate(0)
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_users(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create ldif with users
be9751
+
be9751
+    :id: 426b5b94-9923-454d-a736-7e71ca985e91
be9751
+    :setup: Standalone instance
be9751
+    :steps:
be9751
+         1. Create DS instance
be9751
+         2. Run ldifgen to generate ldif with users
be9751
+         3. Import generated ldif to database
be9751
+         4. Check it was properly imported
be9751
+    :expectedresults:
be9751
+         1. Success
be9751
+         2. Success
be9751
+         3. Success
be9751
+         4. Success
be9751
+    """
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.suffix = DEFAULT_SUFFIX
be9751
+    args.parent = 'ou=people,dc=example,dc=com'
be9751
+    args.number = "1000"
be9751
+    args.rdn_cn = False
be9751
+    args.generic = True
be9751
+    args.start_idx = "50"
be9751
+    args.localize = False
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'suffix={}'.format(args.suffix),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'number={}'.format(args.number),
be9751
+                    'rdn-cn={}'.format(args.rdn_cn),
be9751
+                    'generic={}'.format(args.generic),
be9751
+                    'start-idx={}'.format(args.start_idx),
be9751
+                    'localize={}'.format(args.localize),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create users ldif')
be9751
+    dbgen_create_users(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    log.info('Get number of accounts before import')
be9751
+    accounts = Accounts(standalone, DEFAULT_SUFFIX)
be9751
+    count_account = len(accounts.filter('(uid=*)'))
be9751
+
be9751
+    run_offline_import(standalone, ldif_file)
be9751
+
be9751
+    log.info('Check that accounts are imported')
be9751
+    assert len(accounts.filter('(uid=*)')) > count_account
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_groups(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create ldif with group
be9751
+
be9751
+            :id: 97207413-9a93-4065-a5ec-63aa93801a31
be9751
+            :setup: Standalone instance
be9751
+            :steps:
be9751
+                 1. Create DS instance
be9751
+                 2. Run ldifgen to generate ldif with group
be9751
+                 3. Import generated ldif to database
be9751
+                 4. Check it was properly imported
be9751
+            :expectedresults:
be9751
+                 1. Success
be9751
+                 2. Success
be9751
+                 3. Success
be9751
+                 4. Success
be9751
+            """
be9751
+    LDAP_RESULT = 'adding new entry "cn=myGroup-1,ou=groups,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.NAME = 'myGroup'
be9751
+    args.parent = 'ou=groups,dc=example,dc=com'
be9751
+    args.suffix = DEFAULT_SUFFIX
be9751
+    args.number = "1"
be9751
+    args.num_members = "1000"
be9751
+    args.create_members = True
be9751
+    args.member_attr = 'uniquemember'
be9751
+    args.member_parent = 'ou=people,dc=example,dc=com'
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'number={}'.format(args.number),
be9751
+                    'suffix={}'.format(args.suffix),
be9751
+                    'num-members={}'.format(args.num_members),
be9751
+                    'create-members={}'.format(args.create_members),
be9751
+                    'member-parent={}'.format(args.member_parent),
be9751
+                    'member-attr={}'.format(args.member_attr),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create group ldif')
be9751
+    dbgen_create_groups(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    log.info('Get number of accounts before import')
be9751
+    accounts = Accounts(standalone, DEFAULT_SUFFIX)
be9751
+    count_account = len(accounts.filter('(uid=*)'))
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    # ldapmodify will complain about already existing parent which causes subprocess to return exit code != 0
be9751
+    with pytest.raises(subprocess.CalledProcessError):
be9751
+        run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that accounts are imported')
be9751
+    assert len(accounts.filter('(uid=*)')) > count_account
be9751
+
be9751
+    log.info('Check that group is imported')
be9751
+    groups = Groups(standalone, DEFAULT_SUFFIX)
be9751
+    assert groups.exists(args.NAME + '-1')
be9751
+    new_group = groups.get(args.NAME + '-1')
be9751
+    new_group.present('uniquemember', 'uid=group_entry1-0152,ou=people,dc=example,dc=com')
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_cos_classic(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a COS definition
be9751
+
be9751
+        :id: 8557f994-8a91-4f8a-86f6-9cb826a0b8f1
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with classic COS definition
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Postal_Def,ou=cos definitions,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.type = 'classic'
be9751
+    args.NAME = 'My_Postal_Def'
be9751
+    args.parent = 'ou=cos definitions,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.cos_specifier = 'businessCategory'
be9751
+    args.cos_attr = ['postalcode', 'telephonenumber']
be9751
+    args.cos_template = 'cn=sales,cn=classicCoS,dc=example,dc=com'
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'type={}'.format(args.type),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'cos-specifier={}'.format(args.cos_specifier),
be9751
+                    'cos-template={}'.format(args.cos_template),
be9751
+                    'cos-attr={}'.format(args.cos_attr),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create COS definition ldif')
be9751
+    dbgen_create_cos_def(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that COS definition is imported')
be9751
+    cos_def = CosClassicDefinitions(standalone, args.parent)
be9751
+    assert cos_def.exists(args.NAME)
be9751
+    new_cos = cos_def.get(args.NAME)
be9751
+    assert new_cos.present('cosTemplateDN', args.cos_template)
be9751
+    assert new_cos.present('cosSpecifier', args.cos_specifier)
be9751
+    assert new_cos.present('cosAttribute', args.cos_attr[0])
be9751
+    assert new_cos.present('cosAttribute', args.cos_attr[1])
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_cos_pointer(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a COS definition
be9751
+
be9751
+        :id: 6b26ca6d-226a-4f93-925e-faf95cc20211
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with pointer COS definition
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Postal_Def_pointer,ou=cos pointer definitions,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.type = 'pointer'
be9751
+    args.NAME = 'My_Postal_Def_pointer'
be9751
+    args.parent = 'ou=cos pointer definitions,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.cos_specifier = None
be9751
+    args.cos_attr = ['postalcode', 'telephonenumber']
be9751
+    args.cos_template = 'cn=sales,cn=pointerCoS,dc=example,dc=com'
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'type={}'.format(args.type),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'cos-template={}'.format(args.cos_template),
be9751
+                    'cos-attr={}'.format(args.cos_attr),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create COS definition ldif')
be9751
+    dbgen_create_cos_def(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that COS definition is imported')
be9751
+    cos_def = CosPointerDefinitions(standalone, args.parent)
be9751
+    assert cos_def.exists(args.NAME)
be9751
+    new_cos = cos_def.get(args.NAME)
be9751
+    assert new_cos.present('cosTemplateDN', args.cos_template)
be9751
+    assert new_cos.present('cosAttribute', args.cos_attr[0])
be9751
+    assert new_cos.present('cosAttribute', args.cos_attr[1])
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_cos_indirect(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a COS definition
be9751
+
be9751
+        :id: ab4b799e-e801-432a-a61d-badad2628201
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with indirect COS definition
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Postal_Def_indirect,ou=cos indirect definitions,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.type = 'indirect'
be9751
+    args.NAME = 'My_Postal_Def_indirect'
be9751
+    args.parent = 'ou=cos indirect definitions,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.cos_specifier = 'businessCategory'
be9751
+    args.cos_attr = ['postalcode', 'telephonenumber']
be9751
+    args.cos_template = None
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'type={}'.format(args.type),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'cos-specifier={}'.format(args.cos_specifier),
be9751
+                    'cos-attr={}'.format(args.cos_attr),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create COS definition ldif')
be9751
+    dbgen_create_cos_def(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that COS definition is imported')
be9751
+    cos_def = CosIndirectDefinitions(standalone, args.parent)
be9751
+    assert cos_def.exists(args.NAME)
be9751
+    new_cos = cos_def.get(args.NAME)
be9751
+    assert new_cos.present('cosIndirectSpecifier', args.cos_specifier)
be9751
+    assert new_cos.present('cosAttribute', args.cos_attr[0])
be9751
+    assert new_cos.present('cosAttribute', args.cos_attr[1])
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_cos_template(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a COS template
be9751
+
be9751
+        :id: 544017c7-4a82-4e7d-a047-00b68a28e071
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with COS template
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Template,ou=cos templates,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.NAME = 'My_Template'
be9751
+    args.parent = 'ou=cos templates,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.cos_priority = "1"
be9751
+    args.cos_attr_val = 'postalcode:12345'
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'cos-priority={}'.format(args.cos_priority),
be9751
+                    'cos-attr-val={}'.format(args.cos_attr_val),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create COS template ldif')
be9751
+    dbgen_create_cos_tmp(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that COS template is imported')
be9751
+    cos_temp = CosTemplates(standalone, args.parent)
be9751
+    assert cos_temp.exists(args.NAME)
be9751
+    new_cos = cos_temp.get(args.NAME)
be9751
+    assert new_cos.present('cosPriority', str(args.cos_priority))
be9751
+    assert new_cos.present('postalcode', '12345')
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_managed_role(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a managed role
be9751
+
be9751
+        :id: 10e77b41-0bc1-4ad5-a144-2c5107455b91
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with managed role
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Managed_Role,ou=managed roles,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+
be9751
+    args.NAME = 'My_Managed_Role'
be9751
+    args.parent = 'ou=managed roles,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.type = 'managed'
be9751
+    args.filter = None
be9751
+    args.role_dn = None
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'type={}'.format(args.type),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create managed role ldif')
be9751
+    dbgen_create_role(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that managed role is imported')
be9751
+    roles = ManagedRoles(standalone, DEFAULT_SUFFIX)
be9751
+    assert roles.exists(args.NAME)
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_filtered_role(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a filtered role
be9751
+
be9751
+        :id: cb3c8ea8-4234-40e2-8810-fb6a25973921
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with filtered role
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Filtered_Role,ou=filtered roles,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+
be9751
+    args.NAME = 'My_Filtered_Role'
be9751
+    args.parent = 'ou=filtered roles,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.type = 'filtered'
be9751
+    args.filter = '"objectclass=posixAccount"'
be9751
+    args.role_dn = None
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'type={}'.format(args.type),
be9751
+                    'filter={}'.format(args.filter),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create filtered role ldif')
be9751
+    dbgen_create_role(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that filtered role is imported')
be9751
+    roles = FilteredRoles(standalone, DEFAULT_SUFFIX)
be9751
+    assert roles.exists(args.NAME)
be9751
+    new_role = roles.get(args.NAME)
be9751
+    assert new_role.present('nsRoleFilter', args.filter)
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_nested_role(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create a nested role
be9751
+
be9751
+        :id: 97fff0a8-3103-4adb-be04-2799ff58d8f1
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate ldif with nested role
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    LDAP_RESULT = 'adding new entry "cn=My_Nested_Role,ou=nested roles,dc=example,dc=com"'
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.NAME = 'My_Nested_Role'
be9751
+    args.parent = 'ou=nested roles,dc=example,dc=com'
be9751
+    args.create_parent = True
be9751
+    args.type = 'nested'
be9751
+    args.filter = None
be9751
+    args.role_dn = ['cn=some_role,ou=roles,dc=example,dc=com']
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'NAME={}'.format(args.NAME),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'type={}'.format(args.type),
be9751
+                    'role-dn={}'.format(args.role_dn),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create nested role ldif')
be9751
+    dbgen_create_role(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    run_ldapmodify_from_file(standalone, ldif_file, LDAP_RESULT)
be9751
+
be9751
+    log.info('Check that nested role is imported')
be9751
+    roles = NestedRoles(standalone, DEFAULT_SUFFIX)
be9751
+    assert roles.exists(args.NAME)
be9751
+    new_role = roles.get(args.NAME)
be9751
+    assert new_role.present('nsRoleDN', args.role_dn[0])
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_mod_ldif_mixed(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create mixed modification ldif
be9751
+
be9751
+        :id: 4a2e0901-2b48-452e-a4a0-507735132c81
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate modification ldif
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.parent = DEFAULT_SUFFIX
be9751
+    args.create_users = True
be9751
+    args.delete_users = True
be9751
+    args.create_parent = False
be9751
+    args.num_users = "1000"
be9751
+    args.add_users = "100"
be9751
+    args.del_users = "999"
be9751
+    args.modrdn_users = "100"
be9751
+    args.mod_users = "10"
be9751
+    args.mod_attrs = ['cn', 'uid', 'sn']
be9751
+    args.randomize = False
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'create-users={}'.format(args.create_users),
be9751
+                    'parent={}'.format(args.parent),
be9751
+                    'create-parent={}'.format(args.create_parent),
be9751
+                    'delete-users={}'.format(args.delete_users),
be9751
+                    'num-users={}'.format(args.num_users),
be9751
+                    'add-users={}'.format(args.add_users),
be9751
+                    'del-users={}'.format(args.del_users),
be9751
+                    'modrdn-users={}'.format(args.modrdn_users),
be9751
+                    'mod-users={}'.format(args.mod_users),
be9751
+                    'mod-attrs={}'.format(args.mod_attrs),
be9751
+                    'randomize={}'.format(args.randomize),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created LDIF file: {}'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create modification ldif')
be9751
+    dbgen_create_mods(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    log.info('Get number of accounts before import')
be9751
+    accounts = Accounts(standalone, DEFAULT_SUFFIX)
be9751
+    count_account = len(accounts.filter('(uid=*)'))
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    # ldapmodify will complain about a lot of changes done which causes subprocess to return exit code != 0
be9751
+    with pytest.raises(subprocess.CalledProcessError):
be9751
+        run_ldapmodify_from_file(standalone, ldif_file)
be9751
+
be9751
+    log.info('Check that some accounts are imported')
be9751
+    assert len(accounts.filter('(uid=*)')) > count_account
be9751
+
be9751
+
be9751
+@pytest.mark.ds50545
be9751
+@pytest.mark.bz1798394
be9751
+@pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
be9751
+def test_usandsconf_dbgen_nested_ldif(topology_st, set_log_file_and_ldif):
be9751
+    """Test ldifgen (formerly dbgen) tool to create nested ldif
be9751
+
be9751
+        :id: 9c281c28-4169-45e0-8c07-c5502d9a7581
be9751
+        :setup: Standalone instance
be9751
+        :steps:
be9751
+             1. Create DS instance
be9751
+             2. Run ldifgen to generate nested ldif
be9751
+             3. Import generated ldif to database
be9751
+             4. Check it was properly imported
be9751
+        :expectedresults:
be9751
+             1. Success
be9751
+             2. Success
be9751
+             3. Success
be9751
+             4. Success
be9751
+        """
be9751
+
be9751
+    standalone = topology_st.standalone
be9751
+
be9751
+    args = FakeArgs()
be9751
+    args.suffix = DEFAULT_SUFFIX
be9751
+    args.node_limit = "100"
be9751
+    args.num_users = "600"
be9751
+    args.ldif_file = ldif_file
be9751
+
be9751
+    content_list = ['Generating LDIF with the following options:',
be9751
+                    'suffix={}'.format(args.suffix),
be9751
+                    'node-limit={}'.format(args.node_limit),
be9751
+                    'num-users={}'.format(args.num_users),
be9751
+                    'ldif-file={}'.format(args.ldif_file),
be9751
+                    'Writing LDIF',
be9751
+                    'Successfully created nested LDIF file ({}) containing 6 nodes/subtrees'.format(args.ldif_file)]
be9751
+
be9751
+    log.info('Run ldifgen to create nested ldif')
be9751
+    dbgen_create_nested(standalone, log, args)
be9751
+
be9751
+    log.info('Check if file exists')
be9751
+    assert os.path.exists(ldif_file)
be9751
+
be9751
+    check_value_in_log_and_reset(content_list)
be9751
+
be9751
+    log.info('Get number of accounts before import')
be9751
+    accounts = Accounts(standalone, DEFAULT_SUFFIX)
be9751
+    count_account = len(accounts.filter('(uid=*)'))
be9751
+    count_ou = len(accounts.filter('(ou=*)'))
be9751
+
be9751
+    # Groups, COS, Roles and modification ldifs are designed to be used by ldapmodify, not ldif2db
be9751
+    # ldapmodify will complain about already existing suffix which causes subprocess to return exit code != 0
be9751
+    with pytest.raises(subprocess.CalledProcessError):
be9751
+        run_ldapmodify_from_file(standalone, ldif_file)
be9751
+
be9751
+    standalone.restart()
be9751
+
be9751
+    log.info('Check that accounts are imported')
be9751
+    assert len(accounts.filter('(uid=*)')) > count_account
be9751
+    assert len(accounts.filter('(ou=*)')) > count_ou
be9751
+
be9751
+
be9751
+if __name__ == '__main__':
be9751
+    # Run isolated
be9751
+    # -s for DEBUG mode
be9751
+    CURRENT_FILE = os.path.realpath(__file__)
be9751
+    pytest.main("-s %s" % CURRENT_FILE)
be9751
diff --git a/src/lib389/lib389/cli_ctl/dbgen.py b/src/lib389/lib389/cli_ctl/dbgen.py
be9751
index 7bc3892ba..058342fb1 100644
be9751
--- a/src/lib389/lib389/cli_ctl/dbgen.py
be9751
+++ b/src/lib389/lib389/cli_ctl/dbgen.py
be9751
@@ -451,13 +451,13 @@ def dbgen_create_mods(inst, log, args):
be9751
     props = {
be9751
         "createUsers": args.create_users,
be9751
         "deleteUsers": args.delete_users,
be9751
-        "numUsers": args.num_users,
be9751
+        "numUsers": int(args.num_users),
be9751
         "parent": args.parent,
be9751
         "createParent": args.create_parent,
be9751
-        "addUsers": args.add_users,
be9751
-        "delUsers": args.del_users,
be9751
-        "modrdnUsers": args.modrdn_users,
be9751
-        "modUsers": args.mod_users,
be9751
+        "addUsers": int(args.add_users),
be9751
+        "delUsers": int(args.del_users),
be9751
+        "modrdnUsers": int(args.modrdn_users),
be9751
+        "modUsers": int(args.mod_users),
be9751
         "random": args.randomize,
be9751
         "modAttrs": args.mod_attrs
be9751
     }
be9751
diff --git a/src/lib389/lib389/dbgen.py b/src/lib389/lib389/dbgen.py
be9751
index 6273781a2..10fb200f7 100644
be9751
--- a/src/lib389/lib389/dbgen.py
be9751
+++ b/src/lib389/lib389/dbgen.py
be9751
@@ -220,6 +220,9 @@ def dbgen_users(instance, number, ldif_file, suffix, generic=False, entry_name="
be9751
     """
be9751
     Generate an LDIF of randomly named entries
be9751
     """
be9751
+    # Lets insure that integer parameters are not string
be9751
+    number=int(number)
be9751
+    startIdx=int(startIdx)
be9751
     familyname_file = os.path.join(instance.ds_paths.data_dir, 'dirsrv/data/dbgen-FamilyNames')
be9751
     givename_file = os.path.join(instance.ds_paths.data_dir, 'dirsrv/data/dbgen-GivenNames')
be9751
     familynames = []
be9751
-- 
be9751
2.26.2
be9751