test_event.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.case import MultimasterModuleCase, MultiMasterTestShellCase
  6. from tests.support.helpers import skip_if_not_root, destructiveTest
  7. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  8. from tests.support.unit import skipIf
  9. import salt.modules.iptables
  10. HAS_IPTABLES = salt.modules.iptables.__virtual__()
  11. if isinstance(HAS_IPTABLES, tuple):
  12. HAS_IPTABLES = HAS_IPTABLES[0]
  13. @destructiveTest
  14. @skip_if_not_root
  15. @skipIf(not HAS_IPTABLES, 'iptables command is not available')
  16. class TestHandleEvents(MultimasterModuleCase, MultiMasterTestShellCase, AdaptedConfigurationTestCaseMixin):
  17. '''
  18. Validate the events handling in multimaster environment
  19. '''
  20. def test_minion_hangs_on_master_failure_50814(self):
  21. '''
  22. Check minion handling events for the alive master when another master is dead.
  23. The case being checked here is described in details in issue #50814.
  24. '''
  25. disconnect_master_rule = '-i lo -p tcp --dport {0} -j DROP'.format(
  26. self.mm_master_opts['ret_port'])
  27. # Disconnect the master.
  28. res = self.run_function(
  29. 'iptables.append',
  30. ('filter', 'INPUT', disconnect_master_rule),
  31. master_tgt='mm-sub-master',
  32. )
  33. # Workaround slow beacons.list_available response
  34. if not res:
  35. res = self.run_function(
  36. 'iptables.append',
  37. ('filter', 'INPUT', disconnect_master_rule),
  38. master_tgt='mm-sub-master',
  39. )
  40. self.assertTrue(res)
  41. try:
  42. # Send an event. This would return okay.
  43. res = self.run_function(
  44. 'event.send',
  45. ('myco/foo/bar',),
  46. master_tgt='mm-sub-master',
  47. )
  48. self.assertTrue(res)
  49. # Send one more event. Minion was hanging on this. This is fixed by #53417
  50. res = self.run_function(
  51. 'event.send',
  52. ('myco/foo/bar',),
  53. master_tgt='mm-sub-master',
  54. timeout=60,
  55. )
  56. self.assertTrue(res, 'Minion is not responding to the second master after the first '
  57. 'one has gone. Check #50814 for details.')
  58. finally:
  59. # Remove the firewall rule taking master online back.
  60. # Since minion could be not responsive now use `salt-call --local` for this.
  61. res = self.run_call(
  62. "iptables.delete filter INPUT rule='{0}'".format(disconnect_master_rule),
  63. local=True,
  64. timeout=30)
  65. self.assertEqual(res, ['local:'])
  66. # Ensure the master is back.
  67. res = self.run_function(
  68. 'event.send',
  69. ('myco/foo/bar',),
  70. master_tgt='mm-master',
  71. )
  72. self.assertTrue(res)