Debian Codegraph @

dirsrvtests/tests/suites/lib389/config_compare_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2019 William Brown <[email protected]>
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 os
10 import pytest
11
12 from contextlib import suppress
13 from test389.topologies import topology_i2
14 from lib389.config import Config
15 from lib389.dseldif import DSEldif
16 from lib389.cli_ctl.dblib import get_bdb_impl_status
17 from lib389._constants import BDB_IMPL_STATUS
18
19 pytestmark = pytest.mark.tier1
20
21 # set_db_type_and_state fixture parameters
22 db_types_and_states = [('bdb,stopped'), ('mdb,stopped'), ('bdb,started'), ('mdb,started')]
23
24
25 def test_config_compare(topology_i2):
26 """
27 Compare test between cn=config of two different Directory Server intance.
28
29 :id: 7b3e17d6-41ca-4926-bc3b-8173dd912a61
30
31 :setup: two isolated directory servers
32
33 :steps: 1. Compare if cn=config is the same
34
35 :expectedresults: 1. It should be the same (excluding unique id attrs)
36 """
37 st1_config = topology_i2.ins.get('standalone1').config
38 st2_config = topology_i2.ins.get('standalone2').config
39 # 'nsslapd-port' attribute is expected to be same in cn=config comparison,
40 # but they are different in our testing environment
41 # as we are using 2 DS instances running, both running simultaneously.
42 # Hence explicitly adding 'nsslapd-port' to compare_exclude.
43 st1_config._compare_exclude.append('nsslapd-port')
44 st2_config._compare_exclude.append('nsslapd-port')
45 st1_config._compare_exclude.append('nsslapd-secureport')
46 st2_config._compare_exclude.append('nsslapd-secureport')
47 st1_config._compare_exclude.append('nsslapd-ldapssotoken-secret')
48 st2_config._compare_exclude.append('nsslapd-ldapssotoken-secret')
49
50 assert Config.compare(st1_config, st2_config)
51
52 @pytest.fixture(scope="function", params=db_types_and_states)
53 def set_db_type_and_state(topology_i2, request):
54 """
55 Stop standalone1 instance and save its dse.ldif then restore things at teardown.
56 """
57 inst = topology_i2.ins.get('standalone1')
58 dbtype,state = request.param.split(',')
59 inst.stop()
60 becfgdn = 'cn=config,cn=ldbm database,cn=plugins,cn=config'
61 becfgattr = 'nsslapd-backend-implement'
62 save_dse_ldif = DSEldif(inst)
63 dse_ldif = DSEldif(inst)
64 dse_ldif.replace(becfgdn, becfgattr, dbtype)
65 if state == 'started':
66 inst.start()
67
68 def fin():
69 save_dse_ldif._update()
70 inst.start()
71
72 request.addfinalizer(fin)
73 return (dbtype,state)
74
75
76 @pytest.mark.skipif(get_bdb_impl_status() == BDB_IMPL_STATUS.READ_ONLY, reason="This test cannot run if bdb is read-only")
77 def test_get_db_lib(request, topology_i2, set_db_type_and_state):
78 """
79 Check that get_db_lib() returns the configured database type.
80
81 :id: 04205590-6c70-11ef-bfae-083a88554478
82
83 :setup: two isolated directory servers. standalone1 is set with
84 a specified db type and instance state.
85
86 :steps: 1. Clear get_db_lib cache
87 2. Check that inst.get_db_lib() returns the expected db type
88
89 :expectedresults: 1. Success
90 2. Success
91 """
92
93 inst = topology_i2.ins.get('standalone1')
94 dbtype,state = set_db_type_and_state
95
96 with suppress(AttributeError):
97 del inst._db_lib
98 assert inst.get_db_lib() == dbtype
99
100
101 if __name__ == '__main__':
102 # Run isolated
103 # -s for DEBUG mode
104 CURRENT_FILE = os.path.realpath(__file__)
105 pytest.main("-s %s" % CURRENT_FILE)