2014-07-09 21:41:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Nicole Thomas <nicole@saltstack.com>
|
2014-07-09 21:41:18 +00:00
|
|
|
'''
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
2014-07-09 21:41:18 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ShellCase
|
2016-07-22 20:19:15 +00:00
|
|
|
|
2014-07-09 21:41:18 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class BatchTest(ShellCase):
|
2014-07-09 21:41:18 +00:00
|
|
|
'''
|
|
|
|
Integration tests for the salt.cli.batch module
|
|
|
|
'''
|
|
|
|
|
|
|
|
def test_batch_run(self):
|
|
|
|
'''
|
|
|
|
Tests executing a simple batch command to help catch regressions
|
|
|
|
'''
|
2016-08-02 18:32:03 +00:00
|
|
|
ret = 'Executing run on [\'sub_minion\']'
|
2016-07-22 20:19:15 +00:00
|
|
|
cmd = self.run_salt('\'*\' test.echo \'batch testing\' -b 50%')
|
2016-08-02 18:38:35 +00:00
|
|
|
self.assertIn(ret, cmd)
|
2014-07-10 04:31:54 +00:00
|
|
|
|
2016-06-15 19:41:00 +00:00
|
|
|
def test_batch_run_number(self):
|
|
|
|
'''
|
|
|
|
Tests executing a simple batch command using a number division instead of
|
|
|
|
a percentage with full batch CLI call.
|
|
|
|
'''
|
2017-03-16 17:00:38 +00:00
|
|
|
ret = "Executing run on ['minion', 'sub_minion']"
|
2016-07-22 20:19:15 +00:00
|
|
|
cmd = self.run_salt('\'*\' test.ping --batch-size 2')
|
2016-08-02 18:32:03 +00:00
|
|
|
self.assertIn(ret, cmd)
|
2016-06-15 19:41:00 +00:00
|
|
|
|
|
|
|
def test_batch_run_grains_targeting(self):
|
|
|
|
'''
|
|
|
|
Tests executing a batch command using a percentage divisor as well as grains
|
|
|
|
targeting.
|
|
|
|
'''
|
|
|
|
os_grain = ''
|
2016-08-02 18:32:03 +00:00
|
|
|
sub_min_ret = "Executing run on ['sub_minion']"
|
|
|
|
min_ret = "Executing run on ['minion']"
|
2016-06-15 19:41:00 +00:00
|
|
|
|
|
|
|
for item in self.run_salt('minion grains.get os'):
|
|
|
|
if item != 'minion':
|
|
|
|
os_grain = item
|
|
|
|
|
|
|
|
os_grain = os_grain.strip()
|
2016-07-22 20:19:15 +00:00
|
|
|
cmd = self.run_salt('-G \'os:{0}\' -b 25% test.ping'.format(os_grain))
|
2016-08-02 18:32:03 +00:00
|
|
|
self.assertIn(sub_min_ret, cmd)
|
|
|
|
self.assertIn(min_ret, cmd)
|
2016-06-15 19:41:00 +00:00
|
|
|
|
2016-11-11 01:03:29 +00:00
|
|
|
def test_batch_exit_code(self):
|
|
|
|
'''
|
|
|
|
Test that a failed state returns a non-zero exit code in batch mode
|
|
|
|
'''
|
|
|
|
cmd = self.run_salt(' "*" state.single test.fail_without_changes name=test_me -b 25%', with_retcode=True)
|
|
|
|
self.assertEqual(cmd[-1], 2)
|