1
0

config_test.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 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 os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools, tasks
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. from lib389.tasks import *
  20. logging.getLogger(__name__).setLevel(logging.DEBUG)
  21. log = logging.getLogger(__name__)
  22. installation1_prefix = None
  23. class TopologyStandalone(object):
  24. def __init__(self, standalone):
  25. standalone.open()
  26. self.standalone = standalone
  27. @pytest.fixture(scope="module")
  28. def topology(request):
  29. global installation1_prefix
  30. if installation1_prefix:
  31. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  32. # Creating standalone instance ...
  33. standalone = DirSrv(verbose=False)
  34. args_instance[SER_HOST] = HOST_STANDALONE
  35. args_instance[SER_PORT] = PORT_STANDALONE
  36. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  37. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  38. args_standalone = args_instance.copy()
  39. standalone.allocate(args_standalone)
  40. instance_standalone = standalone.exists()
  41. if instance_standalone:
  42. standalone.delete()
  43. standalone.create()
  44. standalone.open()
  45. # Clear out the tmp dir
  46. standalone.clearTmpDir(__file__)
  47. return TopologyStandalone(standalone)
  48. def test_config_init(topology):
  49. '''
  50. Initialization function
  51. '''
  52. return
  53. def test_config_listen_backport_size(topology):
  54. '''
  55. We need to check that we can search on nsslapd-listen-backlog-size,
  56. and change its value: to a psoitive number and a negative number.
  57. Verify invalid value is rejected.
  58. '''
  59. log.info('Running test_config_listen_backport_size...')
  60. try:
  61. entry = topology.standalone.search_s(DN_CONFIG, ldap.SCOPE_BASE, 'objectclass=top',
  62. ['nsslapd-listen-backlog-size'])
  63. default_val = entry[0].getValue('nsslapd-listen-backlog-size')
  64. if not default_val:
  65. log.fatal('test_config_listen_backport_size: Failed to get nsslapd-listen-backlog-size from config')
  66. assert False
  67. except ldap.LDAPError as e:
  68. log.fatal('test_config_listen_backport_size: Failed to search config, error: ' + e.message('desc'))
  69. assert False
  70. try:
  71. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-listen-backlog-size', '256')])
  72. except ldap.LDAPError as e:
  73. log.fatal('test_config_listen_backport_size: Failed to modify config, error: ' + e.message('desc'))
  74. assert False
  75. try:
  76. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-listen-backlog-size', '-1')])
  77. except ldap.LDAPError as e:
  78. log.fatal('test_config_listen_backport_size: Failed to modify config(negative value), error: ' +
  79. e.message('desc'))
  80. assert False
  81. try:
  82. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-listen-backlog-size', 'ZZ')])
  83. log.fatal('test_config_listen_backport_size: Invalid value was successfully added')
  84. assert False
  85. except ldap.LDAPError as e:
  86. pass
  87. #
  88. # Cleanup - undo what we've done
  89. #
  90. try:
  91. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-listen-backlog-size', default_val)])
  92. except ldap.LDAPError as e:
  93. log.fatal('test_config_listen_backport_size: Failed to reset config, error: ' + e.message('desc'))
  94. assert False
  95. log.info('test_config_listen_backport_size: PASSED')
  96. def test_config_deadlock_policy(topology):
  97. '''
  98. We need to check that nsslapd-db-deadlock-policy exists, that we can
  99. change the value, and invalid values are rejected
  100. '''
  101. log.info('Running test_config_deadlock_policy...')
  102. LDBM_DN = 'cn=config,cn=ldbm database,cn=plugins,cn=config'
  103. default_val = '9'
  104. try:
  105. entry = topology.standalone.search_s(LDBM_DN, ldap.SCOPE_BASE, 'objectclass=top',
  106. ['nsslapd-db-deadlock-policy'])
  107. val = entry[0].getValue('nsslapd-db-deadlock-policy')
  108. if not val:
  109. log.fatal('test_config_deadlock_policy: Failed to get nsslapd-db-deadlock-policy from config')
  110. assert False
  111. if val != default_val:
  112. log.fatal('test_config_deadlock_policy: The wrong derfualt value was present: (%s) but expected (%s)' %
  113. (val, default_val))
  114. assert False
  115. except ldap.LDAPError as e:
  116. log.fatal('test_config_deadlock_policy: Failed to search config, error: ' + e.message('desc'))
  117. assert False
  118. # Try a range of valid values
  119. for val in ('0', '5', '9'):
  120. try:
  121. topology.standalone.modify_s(LDBM_DN, [(ldap.MOD_REPLACE, 'nsslapd-db-deadlock-policy', val)])
  122. except ldap.LDAPError as e:
  123. log.fatal('test_config_deadlock_policy: Failed to modify config: nsslapd-db-deadlock-policy to (%s), error: %s' %
  124. (val, e.message('desc')))
  125. assert False
  126. # Try a range of invalid values
  127. for val in ('-1', '10'):
  128. try:
  129. topology.standalone.modify_s(LDBM_DN, [(ldap.MOD_REPLACE, 'nsslapd-db-deadlock-policy', val)])
  130. log.fatal('test_config_deadlock_policy: Able to add invalid value to nsslapd-db-deadlock-policy(%s)' % (val))
  131. assert False
  132. except ldap.LDAPError as e:
  133. pass
  134. #
  135. # Cleanup - undo what we've done
  136. #
  137. try:
  138. topology.standalone.modify_s(LDBM_DN, [(ldap.MOD_REPLACE, 'nsslapd-db-deadlock-policy', default_val)])
  139. except ldap.LDAPError as e:
  140. log.fatal('test_config_deadlock_policy: Failed to reset nsslapd-db-deadlock-policy to the default value(%s), error: %s' %
  141. (default_val, e.message('desc')))
  142. log.info('test_config_deadlock_policy: PASSED')
  143. def test_config_final(topology):
  144. topology.standalone.delete()
  145. log.info('Testcase PASSED')
  146. def run_isolated():
  147. '''
  148. This test suite is designed to test all things cn=config Like, the core cn=config settings,
  149. or the ldbm database settings, etc. This suite shoud not test individual plugins - there
  150. should be individual suites for each plugin.
  151. '''
  152. global installation1_prefix
  153. installation1_prefix = None
  154. topo = topology(True)
  155. test_config_init(topo)
  156. test_config_listen_backport_size(topo)
  157. test_config_deadlock_policy(topo)
  158. test_config_final(topo)
  159. if __name__ == '__main__':
  160. run_isolated()