mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
parent
02f79dc2b3
commit
8623c24335
5 changed files with 113 additions and 0 deletions
|
@ -93,6 +93,7 @@ TMP_STATE_TREE = os.path.join(SYS_TMP_DIR, 'salt-temp-state-tree')
|
|||
TMP_PRODENV_STATE_TREE = os.path.join(SYS_TMP_DIR, 'salt-temp-prodenv-state-tree')
|
||||
TMP_CONF_DIR = os.path.join(TMP, 'config')
|
||||
CONF_DIR = os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf')
|
||||
PILLAR_DIR = os.path.join(FILES, 'pillar')
|
||||
|
||||
RUNTIME_CONFIGS = {}
|
||||
|
||||
|
|
1
tests/integration/files/pillar/base/blackout.sls
Normal file
1
tests/integration/files/pillar/base/blackout.sls
Normal file
|
@ -0,0 +1 @@
|
|||
minion_blackout: False
|
|
@ -1,6 +1,8 @@
|
|||
base:
|
||||
'minion':
|
||||
- generic
|
||||
- blackout
|
||||
'sub_minion':
|
||||
- generic
|
||||
- blackout
|
||||
- sub
|
||||
|
|
1
tests/integration/minion/__init__.py
Normal file
1
tests/integration/minion/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
108
tests/integration/minion/blackout.py
Normal file
108
tests/integration/minion/blackout.py
Normal file
|
@ -0,0 +1,108 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Tests for minion blackout
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
from time import sleep
|
||||
import textwrap
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.helpers import destructiveTest, ensure_in_syspath
|
||||
|
||||
ensure_in_syspath('../')
|
||||
|
||||
# Import Salt libs
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
|
||||
BLACKOUT_PILLAR = os.path.join(integration.PILLAR_DIR, 'base', 'blackout.sls')
|
||||
|
||||
|
||||
@destructiveTest
|
||||
class MinionBlackoutTestCase(integration.ModuleCase):
|
||||
'''
|
||||
Test minion blackout functionality
|
||||
'''
|
||||
def begin_blackout(self, blackout_data='minion_blackout: True'):
|
||||
'''
|
||||
setup minion blackout mode
|
||||
'''
|
||||
salt.utils.fopen(BLACKOUT_PILLAR, 'w').write(blackout_data)
|
||||
self.run_function('saltutil.refresh_pillar')
|
||||
sleep(5) # wait for minion to enter blackout mode
|
||||
|
||||
def end_blackout(self):
|
||||
'''
|
||||
takedown minion blackout mode
|
||||
'''
|
||||
with salt.utils.fopen(BLACKOUT_PILLAR, 'w') as blackout_pillar:
|
||||
blackout_pillar.write(textwrap.dedent('''\
|
||||
minion_blackout: False
|
||||
'''))
|
||||
self.run_function('saltutil.refresh_pillar')
|
||||
sleep(5) # wait for minion to exit blackout mode
|
||||
|
||||
def test_blackout(self):
|
||||
'''
|
||||
Test that basic minion blackout functionality works
|
||||
'''
|
||||
try:
|
||||
self.begin_blackout()
|
||||
blackout_ret = self.run_function('test.ping')
|
||||
self.assertIn('Minion in blackout mode.', blackout_ret)
|
||||
finally:
|
||||
self.end_blackout()
|
||||
|
||||
ret = self.run_function('test.ping')
|
||||
self.assertEqual(ret, True)
|
||||
|
||||
def test_blackout_whitelist(self):
|
||||
'''
|
||||
Test that minion blackout whitelist works
|
||||
'''
|
||||
try:
|
||||
self.begin_blackout(textwrap.dedent('''\
|
||||
minion_blackout: True
|
||||
minion_blackout_whitelist:
|
||||
- test.ping
|
||||
- test.fib
|
||||
'''))
|
||||
|
||||
ping_ret = self.run_function('test.ping')
|
||||
self.assertEqual(ping_ret, True)
|
||||
|
||||
fib_ret = self.run_function('test.fib', [7])
|
||||
self.assertTrue(isinstance(fib_ret, list))
|
||||
self.assertEqual(fib_ret[0], 13)
|
||||
finally:
|
||||
self.end_blackout()
|
||||
|
||||
def test_blackout_nonwhitelist(self):
|
||||
'''
|
||||
Test that minion refuses to run non-whitelisted functions during
|
||||
blackout whitelist
|
||||
'''
|
||||
try:
|
||||
self.begin_blackout(textwrap.dedent('''\
|
||||
minion_blackout: True
|
||||
minion_blackout_whitelist:
|
||||
- test.ping
|
||||
- test.fib
|
||||
'''))
|
||||
|
||||
state_ret = self.run_function('state.apply')
|
||||
self.assertIn('Minion in blackout mode.', state_ret)
|
||||
|
||||
cloud_ret = self.run_function('cloud.query', ['list_nodes_full'])
|
||||
self.assertIn('Minion in blackout mode.', cloud_ret)
|
||||
finally:
|
||||
self.end_blackout()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(MinionBlackoutTestCase, needs_daemon=True)
|
Loading…
Add table
Reference in a new issue