dynamic_plugins_test.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. '''
  10. Created on Dec 09, 2014
  11. @author: mreynolds
  12. '''
  13. import logging
  14. import ldap.sasl
  15. import pytest
  16. from lib389.tasks import *
  17. from lib389.replica import ReplicationManager
  18. from lib389.config import LDBMConfig
  19. from lib389._constants import *
  20. from lib389.topologies import topology_m2
  21. from ..plugins import acceptance_test
  22. from . import stress_tests
  23. pytestmark = pytest.mark.tier1
  24. log = logging.getLogger(__name__)
  25. def check_replicas(topology_m2):
  26. """Check that replication is in sync and working"""
  27. m1 = topology_m2.ms["master1"]
  28. m2 = topology_m2.ms["master2"]
  29. log.info('Checking if replication is in sync...')
  30. repl = ReplicationManager(DEFAULT_SUFFIX)
  31. repl.test_replication_topology(topology_m2)
  32. #
  33. # Verify the databases are identical. There should not be any "user, entry, employee" entries
  34. #
  35. log.info('Checking if the data is the same between the replicas...')
  36. # Check the master
  37. try:
  38. entries = m1.search_s(DEFAULT_SUFFIX,
  39. ldap.SCOPE_SUBTREE,
  40. "(|(uid=person*)(uid=entry*)(uid=employee*))")
  41. if len(entries) > 0:
  42. log.error('Master database has incorrect data set!\n')
  43. assert False
  44. except ldap.LDAPError as e:
  45. log.fatal('Unable to search db on master: ' + e.message['desc'])
  46. assert False
  47. # Check the consumer
  48. try:
  49. entries = m2.search_s(DEFAULT_SUFFIX,
  50. ldap.SCOPE_SUBTREE,
  51. "(|(uid=person*)(uid=entry*)(uid=employee*))")
  52. if len(entries) > 0:
  53. log.error('Consumer database in not consistent with master database')
  54. assert False
  55. except ldap.LDAPError as e:
  56. log.fatal('Unable to search db on consumer: ' + e.message['desc'])
  57. assert False
  58. log.info('Data is consistent across the replicas.\n')
  59. def test_acceptance(topology_m2):
  60. """Exercise each plugin and its main features, while
  61. changing the configuration without restarting the server.
  62. :id: 96136538-0151-4b09-9933-0e0cbf2c786c
  63. :setup: 2 Master Instances
  64. :steps:
  65. 1. Pause all replication
  66. 2. Set nsslapd-dynamic-plugins to on
  67. 3. Try to update LDBM config entry
  68. 4. Go through all plugin basic functionality
  69. 5. Resume replication
  70. 6. Go through all plugin basic functionality again
  71. 7. Check that data in sync and replication is working
  72. :expectedresults:
  73. 1. Success
  74. 2. Success
  75. 3. Success
  76. 4. Success
  77. 5. Success
  78. 6. Success
  79. 7. Success
  80. """
  81. m1 = topology_m2.ms["master1"]
  82. msg = ' (no replication)'
  83. replication_run = False
  84. # First part of the test should be without replication
  85. topology_m2.pause_all_replicas()
  86. # First enable dynamic plugins
  87. m1.config.replace('nsslapd-dynamic-plugins', 'on')
  88. # Test that critical plugins can be updated even though the change might not be applied
  89. ldbm_config = LDBMConfig(m1)
  90. ldbm_config.replace('description', 'test')
  91. while True:
  92. # First run the tests with replication disabled, then rerun them with replication set up
  93. ############################################################################
  94. # Test plugin functionality
  95. ############################################################################
  96. log.info('####################################################################')
  97. log.info('Testing Dynamic Plugins Functionality' + msg + '...')
  98. log.info('####################################################################\n')
  99. acceptance_test.check_all_plugins(topology_m2)
  100. log.info('####################################################################')
  101. log.info('Successfully Tested Dynamic Plugins Functionality' + msg + '.')
  102. log.info('####################################################################\n')
  103. if replication_run:
  104. # We're done.
  105. break
  106. else:
  107. log.info('Resume replication and run everything one more time')
  108. topology_m2.resume_all_replicas()
  109. replication_run = True
  110. msg = ' (replication enabled)'
  111. time.sleep(1)
  112. ############################################################################
  113. # Check replication, and data are in sync
  114. ############################################################################
  115. check_replicas(topology_m2)
  116. def test_memory_corruption(topology_m2):
  117. """Check the plugins for memory corruption issues while
  118. dynamic plugins option is enabled
  119. :id: 96136538-0151-4b09-9933-0e0cbf2c7862
  120. :setup: 2 Master Instances
  121. :steps:
  122. 1. Pause all replication
  123. 2. Set nsslapd-dynamic-plugins to on
  124. 3. Try to update LDBM config entry
  125. 4. Restart the plugin many times in a linked list fashion
  126. restarting previous and preprevious plugins in the list of all plugins
  127. 5. Run the functional test
  128. 6. Repeat 4 and 5 steps for all plugins
  129. 7. Resume replication
  130. 8. Go through 4-6 steps once more
  131. 9. Check that data in sync and replication is working
  132. :expectedresults:
  133. 1. Success
  134. 2. Success
  135. 3. Success
  136. 4. Success
  137. 5. Success
  138. 6. Success
  139. 7. Success
  140. 8. Success
  141. 9. Success
  142. """
  143. m1 = topology_m2.ms["master1"]
  144. msg = ' (no replication)'
  145. replication_run = False
  146. # First part of the test should be without replication
  147. topology_m2.pause_all_replicas()
  148. # First enable dynamic plugins
  149. m1.config.replace('nsslapd-dynamic-plugins', 'on')
  150. # Test that critical plugins can be updated even though the change might not be applied
  151. ldbm_config = LDBMConfig(m1)
  152. ldbm_config.replace('description', 'test')
  153. while True:
  154. # First run the tests with replication disabled, then rerun them with replication set up
  155. ############################################################################
  156. # Test the stability by exercising the internal lists, callabcks, and task handlers
  157. ############################################################################
  158. log.info('####################################################################')
  159. log.info('Testing Dynamic Plugins for Memory Corruption' + msg + '...')
  160. log.info('####################################################################\n')
  161. prev_plugin_test = None
  162. prev_prev_plugin_test = None
  163. for plugin_test in acceptance_test.func_tests:
  164. #
  165. # Restart the plugin several times (and prev plugins) - work that linked list
  166. #
  167. plugin_test(topology_m2, "restart")
  168. if prev_prev_plugin_test:
  169. prev_prev_plugin_test(topology_m2, "restart")
  170. plugin_test(topology_m2, "restart")
  171. if prev_plugin_test:
  172. prev_plugin_test(topology_m2, "restart")
  173. plugin_test(topology_m2, "restart")
  174. # Now run the functional test
  175. plugin_test(topology_m2, "dynamic")
  176. # Set the previous tests
  177. if prev_plugin_test:
  178. prev_prev_plugin_test = prev_plugin_test
  179. prev_plugin_test = plugin_test
  180. log.info('####################################################################')
  181. log.info('Successfully Tested Dynamic Plugins for Memory Corruption' + msg + '.')
  182. log.info('####################################################################\n')
  183. if replication_run:
  184. # We're done.
  185. break
  186. else:
  187. log.info('Resume replication and run everything one more time')
  188. topology_m2.resume_all_replicas()
  189. replication_run = True
  190. msg = ' (replication enabled)'
  191. time.sleep(1)
  192. ############################################################################
  193. # Check replication, and data are in sync
  194. ############################################################################
  195. check_replicas(topology_m2)
  196. def test_stress(topology_m2):
  197. """Test plugins while under a big load. Perform the test 5 times
  198. :id: 96136538-0151-4b09-9933-0e0cbf2c7863
  199. :setup: 2 Master Instances
  200. :steps:
  201. 1. Pause all replication
  202. 2. Set nsslapd-dynamic-plugins to on
  203. 3. Try to update LDBM config entry
  204. 4. Do one run through all tests
  205. 5. Enable Referential integrity and MemberOf plugins
  206. 6. Launch three new threads to add a bunch of users
  207. 7. While we are adding users restart the MemberOf and
  208. Linked Attributes plugins many times
  209. 8. Wait for the 'adding' threads to complete
  210. 9. Now launch three threads to delete the users
  211. 10. Restart both the MemberOf, Referential integrity and
  212. Linked Attributes plugins during these deletes
  213. 11. Wait for the 'deleting' threads to complete
  214. 12. Now make sure both the MemberOf and Referential integrity plugins still work correctly
  215. 13. Cleanup the stress tests (delete the group entry)
  216. 14. Perform 4-13 steps five times
  217. 15. Resume replication
  218. 16. Go through 4-14 steps once more
  219. 17. Check that data in sync and replication is working
  220. :expectedresults:
  221. 1. Success
  222. 2. Success
  223. 3. Success
  224. 4. Success
  225. 5. Success
  226. 6. Success
  227. 7. Success
  228. 8. Success
  229. 9. Success
  230. 10. Success
  231. 11. Success
  232. 12. Success
  233. 13. Success
  234. 14. Success
  235. 15. Success
  236. 16. Success
  237. 17. Success
  238. """
  239. m1 = topology_m2.ms["master1"]
  240. msg = ' (no replication)'
  241. replication_run = False
  242. stress_max_runs = 5
  243. # First part of the test should be without replication
  244. topology_m2.pause_all_replicas()
  245. # First enable dynamic plugins
  246. m1.config.replace('nsslapd-dynamic-plugins', 'on')
  247. # Test that critical plugins can be updated even though the change might not be applied
  248. ldbm_config = LDBMConfig(m1)
  249. ldbm_config.replace('description', 'test')
  250. while True:
  251. # First run the tests with replication disabled, then rerun them with replication set up
  252. log.info('Do one run through all tests ' + msg + '...')
  253. acceptance_test.check_all_plugins(topology_m2)
  254. log.info('####################################################################')
  255. log.info('Stressing Dynamic Plugins' + msg + '...')
  256. log.info('####################################################################\n')
  257. stress_tests.configureMO(m1)
  258. stress_tests.configureRI(m1)
  259. stress_count = 0
  260. while stress_count < stress_max_runs:
  261. log.info('####################################################################')
  262. log.info('Running stress test' + msg + '. Run (%d/%d)...' % (stress_count + 1, stress_max_runs))
  263. log.info('####################################################################\n')
  264. # Launch three new threads to add a bunch of users
  265. add_users = stress_tests.AddUsers(m1, 'employee', True)
  266. add_users.start()
  267. add_users2 = stress_tests.AddUsers(m1, 'entry', True)
  268. add_users2.start()
  269. add_users3 = stress_tests.AddUsers(m1, 'person', True)
  270. add_users3.start()
  271. time.sleep(1)
  272. # While we are adding users restart the MO plugin and an idle plugin
  273. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  274. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  275. time.sleep(1)
  276. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  277. time.sleep(1)
  278. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  279. m1.plugins.disable(name=PLUGIN_LINKED_ATTRS)
  280. m1.plugins.enable(name=PLUGIN_LINKED_ATTRS)
  281. time.sleep(1)
  282. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  283. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  284. time.sleep(2)
  285. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  286. time.sleep(1)
  287. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  288. m1.plugins.disable(name=PLUGIN_LINKED_ATTRS)
  289. m1.plugins.enable(name=PLUGIN_LINKED_ATTRS)
  290. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  291. time.sleep(1)
  292. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  293. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  294. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  295. # Wait for the 'adding' threads to complete
  296. add_users.join()
  297. add_users2.join()
  298. add_users3.join()
  299. # Now launch three threads to delete the users
  300. del_users = stress_tests.DelUsers(m1, 'employee')
  301. del_users.start()
  302. del_users2 = stress_tests.DelUsers(m1, 'entry')
  303. del_users2.start()
  304. del_users3 = stress_tests.DelUsers(m1, 'person')
  305. del_users3.start()
  306. time.sleep(1)
  307. # Restart both the MO, RI plugins during these deletes, and an idle plugin
  308. m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY)
  309. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  310. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  311. m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  312. time.sleep(1)
  313. m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY)
  314. time.sleep(1)
  315. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  316. time.sleep(1)
  317. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  318. time.sleep(1)
  319. m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  320. m1.plugins.disable(name=PLUGIN_LINKED_ATTRS)
  321. m1.plugins.enable(name=PLUGIN_LINKED_ATTRS)
  322. m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY)
  323. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  324. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  325. m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  326. time.sleep(2)
  327. m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY)
  328. time.sleep(1)
  329. m1.plugins.disable(name=PLUGIN_MEMBER_OF)
  330. time.sleep(1)
  331. m1.plugins.enable(name=PLUGIN_MEMBER_OF)
  332. time.sleep(1)
  333. m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  334. m1.plugins.disable(name=PLUGIN_LINKED_ATTRS)
  335. m1.plugins.enable(name=PLUGIN_LINKED_ATTRS)
  336. # Wait for the 'deleting' threads to complete
  337. del_users.join()
  338. del_users2.join()
  339. del_users3.join()
  340. # Now make sure both the MO and RI plugins still work correctly
  341. acceptance_test.func_tests[8](topology_m2, "dynamic") # RI plugin
  342. acceptance_test.func_tests[5](topology_m2, "dynamic") # MO plugin
  343. # Cleanup the stress tests
  344. stress_tests.cleanup(m1)
  345. stress_count += 1
  346. log.info('####################################################################')
  347. log.info('Successfully Stressed Dynamic Plugins' + msg +
  348. '. Completed (%d/%d)' % (stress_count, stress_max_runs))
  349. log.info('####################################################################\n')
  350. if replication_run:
  351. # We're done.
  352. break
  353. else:
  354. log.info('Resume replication and run everything one more time')
  355. topology_m2.resume_all_replicas()
  356. replication_run = True
  357. msg = ' (replication enabled)'
  358. time.sleep(1)
  359. ############################################################################
  360. # Check replication, and data are in sync
  361. ############################################################################
  362. check_replicas(topology_m2)
  363. if __name__ == '__main__':
  364. # Run isolated
  365. # -s for DEBUG mode
  366. CURRENT_FILE = os.path.realpath(__file__)
  367. pytest.main("-s %s" % CURRENT_FILE)