Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_init_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 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
10 import pytest
11
12 from lib389.utils import *
13 from test389.topologies import topology_no_sample
14 from lib389._constants import *
15 from lib389.cli_base import FakeArgs
16 from lib389.cli_idm.initialise import initialise
17 from lib389.cli_base import FakeArgs
18 from lib389.idm.user import nsUserAccounts
19 from lib389.idm.group import Groups
20 from lib389.idm.organizationalunit import OrganizationalUnits
21
22
23 pytestmark = pytest.mark.tier0
24
25
26 DEBUGGING = os.getenv("DEBUGGING", default=False)
27 if DEBUGGING:
28 logging.getLogger(__name__).setLevel(logging.DEBUG)
29 else:
30 logging.getLogger(__name__).setLevel(logging.INFO)
31 log = logging.getLogger(__name__)
32
33
34 @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
35 def test_dsidm_initialise(topology_no_sample):
36 """Check that keep alive entries are created when initializing a master from another one
37
38 :id: eefb59fc-4fdd-4d68-b6c4-b067eb52e881
39 :setup: Standalone instance
40 :steps:
41 1. Create instance without sample entries
42 2. Check there are no sample entries
43 3. Run dsidm initialise
44 4. Check there are sample entries created
45 5. Run dsidm initialise again
46 :expectedresults:
47 1. Success
48 2. Success
49 3. Success
50 4. Success
51 5. Exception should be raised that entries already exist
52 """
53
54 standalone = topology_no_sample.standalone
55
56 log.info('Check there are no sample entries before running initialise')
57 users = nsUserAccounts(standalone, DEFAULT_SUFFIX)
58 groups = Groups(standalone, DEFAULT_SUFFIX)
59 ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX)
60 assert not users.exists('demo_user')
61 assert not groups.exists('demo_group')
62 assert not ous.exists('Permissions')
63 assert not ous.exists('Services')
64
65 log.info('Run dsidm initialise')
66 args = FakeArgs()
67 args.version = INSTALL_LATEST_CONFIG
68 initialise(standalone, DEFAULT_SUFFIX, topology_no_sample.logcap.log, args)
69
70 log.info('Check there are sample entries')
71 assert users.exists('demo_user')
72 assert groups.exists('demo_group')
73 assert ous.exists('Permissions')
74 assert ous.exists('Services')
75
76 log.info('Try to initialise again and exception should be raised')
77 with pytest.raises(ldap.ALREADY_EXISTS):
78 initialise(standalone, DEFAULT_SUFFIX, topology_no_sample.logcap.log, args)
79
80
81 if __name__ == '__main__':
82 # Run isolated
83 # -s for DEBUG mode
84 CURRENT_FILE = os.path.realpath(__file__)
85 pytest.main("-s %s" % CURRENT_FILE)