test_event.py 3.0 KB

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