123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- """
- Tests for minion blackout
- """
- import logging
- import pytest
- from tests.support.helpers import slowTest
- log = logging.getLogger(__name__)
- pytestmark = [
- pytest.mark.windows_whitelisted,
- ]
- @slowTest
- def test_blackout(salt_cli, blackout, salt_minion_1):
- """
- Test that basic minion blackout functionality works
- """
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
- with blackout.enter_blackout("minion_blackout: true"):
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 1
- assert "Minion in blackout mode." in ret.stdout
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
- @slowTest
- def test_blackout_whitelist(salt_cli, blackout, salt_minion_1):
- """
- Test that minion blackout whitelist works
- """
- blackout_contents = """
- minion_blackout: True
- minion_blackout_whitelist:
- - test.ping
- - test.fib
- """
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
- with blackout.enter_blackout(blackout_contents):
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
- ret = salt_cli.run("test.fib", "7", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json[0] == 13
- @slowTest
- def test_blackout_nonwhitelist(salt_cli, blackout, salt_minion_1):
- """
- Test that minion refuses to run non-whitelisted functions during
- blackout whitelist
- """
- blackout_contents = """
- minion_blackout: True
- minion_blackout_whitelist:
- - test.ping
- - test.fib
- """
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
- with blackout.enter_blackout(blackout_contents):
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
- ret = salt_cli.run("state.apply", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 1
- assert "Minion in blackout mode." in ret.stdout
- ret = salt_cli.run(
- "cloud.query", "list_nodes_full", minion_tgt=salt_minion_1.id
- )
- assert ret.exitcode == 1
- assert "Minion in blackout mode." in ret.stdout
- ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
- assert ret.exitcode == 0
- assert ret.json is True
|