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

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