config_test.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 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. from lib389.tasks import *
  12. from lib389.topologies import topology_m2
  13. USER_DN = 'uid=test_user,%s' % DEFAULT_SUFFIX
  14. logging.getLogger(__name__).setLevel(logging.INFO)
  15. log = logging.getLogger(__name__)
  16. @pytest.fixture(scope="module")
  17. def big_file():
  18. TEMP_BIG_FILE = ''
  19. # 1024*1024=1048576
  20. # B for 1 MiB
  21. # Big for 3 MiB
  22. for x in range(1048576):
  23. TEMP_BIG_FILE += '+'
  24. return TEMP_BIG_FILE
  25. @pytest.fixture
  26. def test_user(topology_m2):
  27. """Add and remove test user"""
  28. try:
  29. topology_m2.ms["master1"].add_s(Entry((USER_DN, {
  30. 'uid': 'test_user',
  31. 'givenName': 'test_user',
  32. 'objectclass': ['top', 'person',
  33. 'organizationalPerson',
  34. 'inetorgperson'],
  35. 'cn': 'test_user',
  36. 'sn': 'test_user'})))
  37. time.sleep(1)
  38. except ldap.LDAPError as e:
  39. log.fatal('Failed to add user (%s): error (%s)' % (USER_DN,
  40. e.message['desc']))
  41. raise
  42. def fin():
  43. try:
  44. topology_m2.ms["master1"].delete_s(USER_DN)
  45. time.sleep(1)
  46. except ldap.LDAPError as e:
  47. log.fatal('Failed to delete user (%s): error (%s)' % (
  48. USER_DN,
  49. e.message['desc']))
  50. raise
  51. def test_maxbersize_repl(topology_m2, test_user, big_file):
  52. """maxbersize is ignored in the replicated operations.
  53. :Feature: Config
  54. :Setup: MMR with two masters, test user,
  55. 1 MiB big value for attribute
  56. :Steps: 1. Set 20KiB small maxbersize on master2
  57. 2. Add big value to master2
  58. 3. Add big value to master1
  59. :Assert: Adding the big value to master2 is failed,
  60. adding the big value to master1 is succeed,
  61. the big value is successfully replicated to master2
  62. """
  63. log.info("Set nsslapd-maxbersize: 20K to master2")
  64. try:
  65. topology_m2.ms["master2"].modify_s("cn=config", [(ldap.MOD_REPLACE,
  66. 'nsslapd-maxbersize', '20480')])
  67. except ldap.LDAPError as e:
  68. log.error('Failed to set nsslapd-maxbersize == 20480: error ' +
  69. e.message['desc'])
  70. raise
  71. topology_m2.ms["master2"].restart(20)
  72. log.info('Try to add attribute with a big value to master2 - expect to FAIL')
  73. with pytest.raises(ldap.SERVER_DOWN):
  74. topology_m2.ms["master2"].modify_s(USER_DN, [(ldap.MOD_REPLACE,
  75. 'jpegphoto', big_file)])
  76. topology_m2.ms["master2"].restart(20)
  77. topology_m2.ms["master1"].restart(20)
  78. log.info('Try to add attribute with a big value to master1 - expect to PASS')
  79. try:
  80. topology_m2.ms["master1"].modify_s(USER_DN, [(ldap.MOD_REPLACE,
  81. 'jpegphoto', big_file)])
  82. except ldap.SERVER_DOWN as e:
  83. log.fatal('Failed to add a big attribute, error: ' + e.message['desc'])
  84. raise
  85. time.sleep(1)
  86. log.info('Check if a big value was successfully added to master1')
  87. try:
  88. entries = topology_m2.ms["master1"].search_s(USER_DN, ldap.SCOPE_BASE,
  89. '(cn=*)',
  90. ['jpegphoto'])
  91. assert entries[0].data['jpegphoto']
  92. except ldap.LDAPError as e:
  93. log.fatal('Search failed, error: ' + e.message['desc'])
  94. raise
  95. log.info('Check if a big value was successfully replicated to master2')
  96. try:
  97. entries = topology_m2.ms["master2"].search_s(USER_DN, ldap.SCOPE_BASE,
  98. '(cn=*)',
  99. ['jpegphoto'])
  100. assert entries[0].data['jpegphoto']
  101. except ldap.LDAPError as e:
  102. log.fatal('Search failed, error: ' + e.message['desc'])
  103. raise
  104. log.info("Set nsslapd-maxbersize: 2097152 (default) to master2")
  105. try:
  106. topology_m2.ms["master2"].modify_s("cn=config", [(ldap.MOD_REPLACE,
  107. 'nsslapd-maxbersize', '2097152')])
  108. except ldap.LDAPError as e:
  109. log.error('Failed to set nsslapd-maxbersize == 2097152 error ' +
  110. e.message['desc'])
  111. raise
  112. def test_config_listen_backport_size(topology_m2):
  113. """We need to check that we can search on nsslapd-listen-backlog-size,
  114. and change its value: to a psoitive number and a negative number.
  115. Verify invalid value is rejected.
  116. """
  117. try:
  118. entry = topology_m2.ms["master1"].search_s(DN_CONFIG, ldap.SCOPE_BASE, 'objectclass=top',
  119. ['nsslapd-listen-backlog-size'])
  120. default_val = entry[0].data['nsslapd-listen-backlog-size'][0]
  121. assert default_val, 'Failed to get nsslapd-listen-backlog-size from config'
  122. except ldap.LDAPError as e:
  123. log.fatal('Failed to search config, error: ' + e.message('desc'))
  124. raise
  125. try:
  126. topology_m2.ms["master1"].modify_s(DN_CONFIG, [(ldap.MOD_REPLACE,
  127. 'nsslapd-listen-backlog-size',
  128. '256')])
  129. except ldap.LDAPError as e:
  130. log.fatal('Failed to modify config, error: ' + e.message('desc'))
  131. raise
  132. try:
  133. topology_m2.ms["master1"].modify_s(DN_CONFIG, [(ldap.MOD_REPLACE,
  134. 'nsslapd-listen-backlog-size',
  135. '-1')])
  136. except ldap.LDAPError as e:
  137. log.fatal('Failed to modify config(negative value), error: ' +
  138. e.message('desc'))
  139. raise
  140. with pytest.raises(ldap.LDAPError):
  141. topology_m2.ms["master1"].modify_s(DN_CONFIG, [(ldap.MOD_REPLACE,
  142. 'nsslapd-listen-backlog-size',
  143. 'ZZ')])
  144. log.fatal('Invalid value was successfully added')
  145. # Cleanup - undo what we've done
  146. try:
  147. topology_m2.ms["master1"].modify_s(DN_CONFIG, [(ldap.MOD_REPLACE,
  148. 'nsslapd-listen-backlog-size',
  149. default_val)])
  150. except ldap.LDAPError as e:
  151. log.fatal('Failed to reset config, error: ' + e.message('desc'))
  152. raise
  153. def test_config_deadlock_policy(topology_m2):
  154. """We need to check that nsslapd-db-deadlock-policy exists, that we can
  155. change the value, and invalid values are rejected
  156. """
  157. LDBM_DN = 'cn=config,cn=ldbm database,cn=plugins,cn=config'
  158. default_val = '9'
  159. try:
  160. entry = topology_m2.ms["master1"].search_s(LDBM_DN, ldap.SCOPE_BASE, 'objectclass=top',
  161. ['nsslapd-db-deadlock-policy'])
  162. val = entry[0].data['nsslapd-db-deadlock-policy'][0]
  163. assert val, 'Failed to get nsslapd-db-deadlock-policy from config'
  164. assert val == default_val, 'The wrong derfualt value was present'
  165. except ldap.LDAPError as e:
  166. log.fatal('Failed to search config, error: ' + e.message('desc'))
  167. raise
  168. # Try a range of valid values
  169. for val in ('0', '5', '9'):
  170. try:
  171. topology_m2.ms["master1"].modify_s(LDBM_DN, [(ldap.MOD_REPLACE,
  172. 'nsslapd-db-deadlock-policy',
  173. val)])
  174. except ldap.LDAPError as e:
  175. log.fatal('Failed to modify config: nsslapd-db-deadlock-policy to (%s), error: %s' %
  176. (val, e.message('desc')))
  177. raise
  178. # Try a range of invalid values
  179. for val in ('-1', '10'):
  180. with pytest.raises(ldap.LDAPError):
  181. topology_m2.ms["master1"].modify_s(LDBM_DN, [(ldap.MOD_REPLACE,
  182. 'nsslapd-db-deadlock-policy',
  183. val)])
  184. log.fatal('Able to add invalid value to nsslapd-db-deadlock-policy(%s)' % (val))
  185. # Cleanup - undo what we've done
  186. try:
  187. topology_m2.ms["master1"].modify_s(LDBM_DN, [(ldap.MOD_REPLACE,
  188. 'nsslapd-db-deadlock-policy',
  189. default_val)])
  190. except ldap.LDAPError as e:
  191. log.fatal('Failed to reset nsslapd-db-deadlock-policy to the default value(%s), error: %s' %
  192. (default_val, e.message('desc')))
  193. raise
  194. if __name__ == '__main__':
  195. # Run isolated
  196. # -s for DEBUG mode
  197. CURRENT_FILE = os.path.realpath(__file__)
  198. pytest.main("-s %s" % CURRENT_FILE)