mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Make sure blackout tests clean up after themselves. Properly.
(cherry picked from commit 9ab0e98e2c
)
This commit is contained in:
parent
68a12d50d0
commit
b348ace640
1 changed files with 40 additions and 39 deletions
|
@ -6,7 +6,7 @@ Tests for minion blackout
|
|||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
from time import sleep
|
||||
import time
|
||||
import textwrap
|
||||
|
||||
# Import Salt Testing libs
|
||||
|
@ -18,32 +18,39 @@ from tests.support.helpers import flaky
|
|||
import salt.utils.files
|
||||
|
||||
|
||||
BLACKOUT_PILLAR = os.path.join(PILLAR_DIR, 'base', 'blackout.sls')
|
||||
|
||||
|
||||
class MinionBlackoutTestCase(ModuleCase):
|
||||
'''
|
||||
Test minion blackout functionality
|
||||
'''
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.blackout_pillar = os.path.join(PILLAR_DIR, 'base', 'blackout.sls')
|
||||
|
||||
def tearDown(self):
|
||||
self.end_blackout(sleep=False)
|
||||
# Be sure to also refresh the sub_minion pillar
|
||||
self.run_function('saltutil.refresh_pillar', minion_tgt='sub_minion')
|
||||
time.sleep(10) # wait for minion to exit blackout mode
|
||||
|
||||
def begin_blackout(self, blackout_data='minion_blackout: True'):
|
||||
'''
|
||||
setup minion blackout mode
|
||||
'''
|
||||
with salt.utils.files.fopen(BLACKOUT_PILLAR, 'w') as wfh:
|
||||
with salt.utils.files.fopen(self.blackout_pillar, 'w') as wfh:
|
||||
wfh.write(blackout_data)
|
||||
self.run_function('saltutil.refresh_pillar')
|
||||
sleep(10) # wait for minion to enter blackout mode
|
||||
time.sleep(10) # wait for minion to enter blackout mode
|
||||
|
||||
def end_blackout(self):
|
||||
def end_blackout(self, sleep=True):
|
||||
'''
|
||||
takedown minion blackout mode
|
||||
'''
|
||||
with salt.utils.files.fopen(BLACKOUT_PILLAR, 'w') as blackout_pillar:
|
||||
blackout_pillar.write(textwrap.dedent('''\
|
||||
minion_blackout: False
|
||||
'''))
|
||||
with salt.utils.files.fopen(self.blackout_pillar, 'w') as wfh:
|
||||
wfh.write('minion_blackout: False\n')
|
||||
self.run_function('saltutil.refresh_pillar')
|
||||
sleep(10) # wait for minion to exit blackout mode
|
||||
if sleep:
|
||||
time.sleep(10) # wait for minion to exit blackout mode
|
||||
|
||||
@flaky
|
||||
def test_blackout(self):
|
||||
|
@ -65,22 +72,19 @@ class MinionBlackoutTestCase(ModuleCase):
|
|||
'''
|
||||
Test that minion blackout whitelist works
|
||||
'''
|
||||
try:
|
||||
self.begin_blackout(textwrap.dedent('''\
|
||||
minion_blackout: True
|
||||
minion_blackout_whitelist:
|
||||
- test.ping
|
||||
- test.fib
|
||||
'''))
|
||||
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)
|
||||
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()
|
||||
fib_ret = self.run_function('test.fib', [7])
|
||||
self.assertTrue(isinstance(fib_ret, list))
|
||||
self.assertEqual(fib_ret[0], 13)
|
||||
|
||||
@flaky
|
||||
def test_blackout_nonwhitelist(self):
|
||||
|
@ -88,18 +92,15 @@ class MinionBlackoutTestCase(ModuleCase):
|
|||
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
|
||||
'''))
|
||||
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)
|
||||
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()
|
||||
cloud_ret = self.run_function('cloud.query', ['list_nodes_full'])
|
||||
self.assertIn('Minion in blackout mode.', cloud_ret)
|
||||
|
|
Loading…
Add table
Reference in a new issue