test_event.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import salt.modules.iptables
  4. from tests.support.case import MultimasterModuleCase, MultiMasterTestShellCase
  5. from tests.support.helpers import destructiveTest, skip_if_not_root, slowTest
  6. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  7. from tests.support.unit import skipIf
  8. HAS_IPTABLES = salt.modules.iptables.__virtual__()
  9. if isinstance(HAS_IPTABLES, tuple):
  10. HAS_IPTABLES = HAS_IPTABLES[0]
  11. @destructiveTest
  12. @skip_if_not_root
  13. @skipIf(not HAS_IPTABLES, "iptables command is not available")
  14. class TestHandleEvents(
  15. MultimasterModuleCase, MultiMasterTestShellCase, AdaptedConfigurationTestCaseMixin
  16. ):
  17. """
  18. Validate the events handling in multimaster environment
  19. """
  20. @slowTest
  21. def test_minion_hangs_on_master_failure_50814(self):
  22. """
  23. Check minion handling events for the alive master when another master is dead.
  24. The case being checked here is described in details in issue #50814.
  25. """
  26. disconnect_master_rule = "-i lo -p tcp --dport {0} -j DROP".format(
  27. self.mm_master_opts["ret_port"]
  28. )
  29. # Disconnect the master.
  30. res = self.run_function(
  31. "iptables.append",
  32. ("filter", "INPUT", disconnect_master_rule),
  33. master_tgt="mm-sub-master",
  34. )
  35. # Workaround slow beacons.list_available response
  36. if not res:
  37. res = self.run_function(
  38. "iptables.append",
  39. ("filter", "INPUT", disconnect_master_rule),
  40. master_tgt="mm-sub-master",
  41. )
  42. self.assertTrue(res)
  43. try:
  44. # Send an event. This would return okay.
  45. res = self.run_function(
  46. "event.send", ("myco/foo/bar",), 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", ("myco/foo/bar",), master_tgt="mm-sub-master", timeout=60,
  52. )
  53. self.assertTrue(
  54. res,
  55. "Minion is not responding to the second master after the first "
  56. "one has gone. Check #50814 for details.",
  57. )
  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(
  63. disconnect_master_rule
  64. ),
  65. local=True,
  66. timeout=30,
  67. )
  68. self.assertEqual(res, ["local:"])
  69. # Ensure the master is back.
  70. res = self.run_function(
  71. "event.send", ("myco/foo/bar",), master_tgt="mm-master",
  72. )
  73. self.assertTrue(res)