test_minion_blackout.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """
  2. Tests for minion blackout
  3. """
  4. import logging
  5. import pytest
  6. from tests.support.helpers import slowTest
  7. log = logging.getLogger(__name__)
  8. pytestmark = [
  9. pytest.mark.windows_whitelisted,
  10. ]
  11. @slowTest
  12. def test_blackout(salt_cli, blackout, salt_minion_1):
  13. """
  14. Test that basic minion blackout functionality works
  15. """
  16. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  17. assert ret.exitcode == 0
  18. assert ret.json is True
  19. with blackout.enter_blackout("minion_blackout: true"):
  20. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  21. assert ret.exitcode == 1
  22. assert "Minion in blackout mode." in ret.stdout
  23. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  24. assert ret.exitcode == 0
  25. assert ret.json is True
  26. @slowTest
  27. def test_blackout_whitelist(salt_cli, blackout, salt_minion_1):
  28. """
  29. Test that minion blackout whitelist works
  30. """
  31. blackout_contents = """
  32. minion_blackout: True
  33. minion_blackout_whitelist:
  34. - test.ping
  35. - test.fib
  36. """
  37. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  38. assert ret.exitcode == 0
  39. assert ret.json is True
  40. with blackout.enter_blackout(blackout_contents):
  41. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  42. assert ret.exitcode == 0
  43. assert ret.json is True
  44. ret = salt_cli.run("test.fib", "7", minion_tgt=salt_minion_1.id)
  45. assert ret.exitcode == 0
  46. assert ret.json[0] == 13
  47. @slowTest
  48. def test_blackout_nonwhitelist(salt_cli, blackout, salt_minion_1):
  49. """
  50. Test that minion refuses to run non-whitelisted functions during
  51. blackout whitelist
  52. """
  53. blackout_contents = """
  54. minion_blackout: True
  55. minion_blackout_whitelist:
  56. - test.ping
  57. - test.fib
  58. """
  59. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  60. assert ret.exitcode == 0
  61. assert ret.json is True
  62. with blackout.enter_blackout(blackout_contents):
  63. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  64. assert ret.exitcode == 0
  65. assert ret.json is True
  66. ret = salt_cli.run("state.apply", minion_tgt=salt_minion_1.id)
  67. assert ret.exitcode == 1
  68. assert "Minion in blackout mode." in ret.stdout
  69. ret = salt_cli.run(
  70. "cloud.query", "list_nodes_full", minion_tgt=salt_minion_1.id
  71. )
  72. assert ret.exitcode == 1
  73. assert "Minion in blackout mode." in ret.stdout
  74. ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
  75. assert ret.exitcode == 0
  76. assert ret.json is True