Debian Codegraph @

dirsrvtests/tests/suites/clu/dsctl_dblib_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2021 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 logging
10 import pytest
11 import ldap
12 import os
13 import time
14 from lib389._constants import DEFAULT_SUFFIX, BDB_IMPL_STATUS
15 from lib389.backend import DatabaseConfig
16 from lib389.cli_ctl.dblib import (
17 FakeArgs,
18 dblib_bdb2mdb,
19 dblib_mdb2bdb,
20 dblib_cleanup,
21 is_bdb_supported)
22 from lib389.idm.user import UserAccounts
23 from lib389.replica import ReplicationManager
24 from test389.topologies import topology_m2 as topo_m2, topology_st as topo_st
25 from lib389.utils import check_plugin_strings
26 from lib389.cli_ctl.dblib import get_bdb_impl_status
27
28
29 log = logging.getLogger(__name__)
30
31
32 @pytest.fixture(scope='function', params=['topo_st','topo_m2'])
33 def init_user(topo_m2, topo_st, request):
34 """Initialize a user - Delete and re-add test user
35 """
36 if request.param == 'topo_st':
37 s1 = topo_st.standalone
38 s2 = None
39 else:
40 s1 = topo_m2.ms["supplier1"]
41 s2 = topo_m2.ms["supplier2"]
42 users = UserAccounts(s1, DEFAULT_SUFFIX)
43 try:
44 user_data = {'uid': 'test entry',
45 'cn': 'test entry',
46 'sn': 'test entry',
47 'uidNumber': '3000',
48 'gidNumber': '4000',
49 'homeDirectory': '/home/test_entry',
50 'userPassword': 'foo'}
51 test_user = users.create(properties=user_data)
52 except ldap.ALREADY_EXISTS:
53 pass
54 except ldap.SERVER_DOWN:
55 pass
56
57 def fin():
58 try:
59 test_user.delete()
60 except (ldap.NO_SUCH_OBJECT, ldap.SERVER_DOWN):
61 pass
62
63 request.addfinalizer(fin)
64 return (s1, s2)
65
66
67 def _check_db(inst, log, impl):
68 users = UserAccounts(inst, DEFAULT_SUFFIX)
69 # Cannot use inst..get_db_lib() because it caches the value
70 assert DatabaseConfig(inst).get_db_lib() == impl
71 assert users.get('test entry')
72
73 db_files = os.listdir(inst.dbdir)
74 if inst.ds_paths.db_home_dir is not None and inst.ds_paths.db_home_dir != inst.dbdir:
75 db_files.extend(os.listdir(inst.ds_paths.db_home_dir))
76 db_files = [ file for file in db_files if not file.startswith('log.00') ]
77
78 mdb_list = ['data.mdb', 'INFO.mdb', 'lock.mdb']
79 bdb_list = ['__db.001', 'DBVERSION', '__db.003', 'userRoot', '__db.002']
80 mdb_list.sort()
81 bdb_list.sort()
82 db_files = sorted(set(db_files))
83 log.debug(f"INFO: _check_db db_home={inst.ds_paths.db_home_dir}")
84 log.debug(f"INFO: _check_db dbdir={inst.dbdir}")
85 log.debug(f"INFO: _check_db db_files={db_files}")
86 log.debug(f"INFO: _check_db mdb_list={mdb_list}")
87 log.debug(f"INFO: _check_db bdb_list={bdb_list}")
88 if impl == 'bdb':
89 assert db_files == bdb_list
90 assert db_files != mdb_list
91 else:
92 assert db_files != bdb_list
93 assert db_files == mdb_list
94
95
96 @pytest.mark.skipif(is_bdb_supported() is False, reason='This test requires bdb support')
97 @pytest.mark.skipif(get_bdb_impl_status() == BDB_IMPL_STATUS.READ_ONLY, reason = 'Cannot read with read-only bdb')
98 def test_dblib_migration(init_user):
99 """
100 Verify dsctl dblib xxxxxxx sub commands (migration between bdb and lmdb)
101
102 :id: 5d327c34-e77a-46e5-a8aa-0a552f9bbdef
103 :setup: Two suppliers Instance
104 :steps:
105 1. Determine current database
106 2. Switch to the other database
107 3. Check that replication works
108 :expectedresults:
109 1. Success
110 2. Success
111 3. Success
112 """
113 s1, s2 = init_user
114 db_lib = s1.get_db_lib()
115 if s2 is not None:
116 repl = ReplicationManager(DEFAULT_SUFFIX)
117 users = UserAccounts(s1, DEFAULT_SUFFIX)
118 assert users.get('test entry')
119 args = FakeArgs({'tmpdir': None})
120 if db_lib == 'bdb':
121 dblib_bdb2mdb(s1, log, args)
122 s1.open()
123 dblib_cleanup(s1, log, args)
124 _check_db(s1, log, 'mdb')
125 if s2 is not None:
126 repl.test_replication_topology([s1, s2])
127 dblib_mdb2bdb(s1, log, args)
128 s1.open()
129 dblib_cleanup(s1, log, args)
130 _check_db(s1, log, 'bdb')
131 if s2 is not None:
132 repl.test_replication_topology([s1, s2])
133 else:
134 dblib_mdb2bdb(s1, log, args)
135 s1.open()
136 dblib_cleanup(s1, log, args)
137 _check_db(s1, log, 'bdb')
138 if s2 is not None:
139 repl.test_replication_topology([s1, s2])
140 dblib_bdb2mdb(s1, log, args)
141 s1.open()
142 dblib_cleanup(s1, log, args)
143 _check_db(s1, log, 'mdb')
144 if s2 is not None:
145 repl.test_replication_topology([s1, s2])
146
147
148 def test_check_plugin_strings():
149 """
150 Check that lib389.utils check_plugin_strings is working properly
151
152 :id: 5194e88a-80c6-11ef-a2ee-482ae39447e5
153 :setup: None
154 :steps:
155 1. Call check_plugin_strings
156 2. Check that an installed rpm is detected
157 3. Check that a non installed rpm is not detected
158 :expectedresults:
159 1. Success
160 2. Success
161 3. Success
162 """
163 res = check_plugin_strings('libback-ldbm', ('ldbm_back_search', 'DummyString'))
164 log.info(f'check_plugin_strings returned {res}')
165 assert res['ldbm_back_search'] is True
166 assert res['DummyString'] is False