1
0

test_offline_master.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import time
  2. import pytest
  3. @pytest.fixture(scope="module")
  4. def event_listener(salt_factories):
  5. return salt_factories.event_listener
  6. def test_minion_hangs_on_master_failure_50814(
  7. event_listener,
  8. salt_mm_master_1,
  9. salt_mm_master_2,
  10. salt_mm_minion_1,
  11. mm_master_2_salt_cli,
  12. ):
  13. """
  14. Check minion handling events for the alive master when another master is dead.
  15. The case being checked here is described in details in issue #50814.
  16. """
  17. # Let's make sure everything works with both masters online
  18. event_count = 3
  19. while event_count:
  20. check_event_start_time = time.time()
  21. stop_time = check_event_start_time + 30
  22. event_tag = "myco/foo/bar/{}".format(event_count)
  23. ret = mm_master_2_salt_cli.run(
  24. "event.send", event_tag, minion_tgt=salt_mm_minion_1.id
  25. )
  26. assert ret.exitcode == 0
  27. assert ret.json is True
  28. # Let's make sure we get the event back
  29. mm_master_1_event_match = mm_master_2_event_match = None
  30. while True:
  31. if time.time() > stop_time:
  32. pytest.fail(
  33. "Minion is not responding to the second master after the first "
  34. "one has gone. Check #50814 for details."
  35. )
  36. if (
  37. mm_master_1_event_match is not None
  38. and mm_master_2_event_match is not None
  39. ):
  40. # We got the right event back!
  41. break
  42. time.sleep(0.5)
  43. if mm_master_1_event_match is None:
  44. events = event_listener.get_events(
  45. [(salt_mm_master_1.id, event_tag)],
  46. after_time=check_event_start_time,
  47. )
  48. for event in events:
  49. # We got the event back!
  50. if event.tag == event_tag:
  51. mm_master_1_event_match = True
  52. break
  53. if mm_master_2_event_match is None:
  54. events = event_listener.get_events(
  55. [(salt_mm_master_2.id, event_tag)],
  56. after_time=check_event_start_time,
  57. )
  58. for event in events:
  59. # We got the event back!
  60. if event.tag == event_tag:
  61. mm_master_2_event_match = True
  62. break
  63. event_count -= 1
  64. time.sleep(0.5)
  65. # Now, let's try this one of the masters offline
  66. with salt_mm_master_1.stopped():
  67. assert salt_mm_master_1.is_running() is False
  68. # Sending one event would be okay. It would hang after the second with one of the masters offline
  69. event_count = 1
  70. while event_count <= 3:
  71. check_event_start_time = time.time()
  72. stop_time = check_event_start_time + 30
  73. event_tag = "myco/foo/bar/{}".format(event_count)
  74. ret = mm_master_2_salt_cli.run(
  75. "event.send", event_tag, minion_tgt=salt_mm_minion_1.id
  76. )
  77. assert ret.exitcode == 0
  78. assert ret.json is True
  79. # Let's make sure we get the event back
  80. event_match = None
  81. while True:
  82. if time.time() > stop_time:
  83. pytest.fail(
  84. "Minion is not responding to the second master(events sent: %s) after the first "
  85. "has gone offline. Check #50814 for details.",
  86. event_count,
  87. )
  88. if event_match is not None:
  89. # We got the right event back!
  90. break
  91. time.sleep(0.5)
  92. events = event_listener.get_events(
  93. [(salt_mm_master_2.id, event_tag)],
  94. after_time=check_event_start_time,
  95. )
  96. for event in events:
  97. # We got the event back!
  98. if event.tag == event_tag:
  99. event_match = True
  100. break
  101. event_count += 1
  102. time.sleep(0.5)