Merge pull request #52624 from tanlingyun2005/2019.2.1

fix TypeError: argument of type int is not iterable
This commit is contained in:
Megan Wilhite 2019-04-29 09:15:41 -04:00 committed by GitHub
commit 9a1ed78cca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -85,7 +85,7 @@ class Batch(object):
'''
partition = lambda x: float(x) / 100.0 * len(self.minions)
try:
if '%' in self.opts['batch']:
if isinstance(self.opts['batch'], six.string_types) and '%' in self.opts['batch']:
res = partition(float(self.opts['batch'].strip('%')))
if res < 1:
return int(math.ceil(res))

View file

@ -35,14 +35,22 @@ class BatchTestCase(TestCase):
# get_bnum tests
def test_get_bnum(self):
def test_get_bnum_str(self):
'''
Tests passing batch value as a number
Tests passing batch value as a number(str)
'''
self.batch.opts = {'batch': '2', 'timeout': 5}
self.batch.minions = ['foo', 'bar']
self.assertEqual(Batch.get_bnum(self.batch), 2)
def test_get_bnum_int(self):
'''
Tests passing batch value as a number(int)
'''
self.batch.opts = {'batch': 2, 'timeout': 5}
self.batch.minions = ['foo', 'bar']
self.assertEqual(Batch.get_bnum(self.batch), 2)
def test_get_bnum_percentage(self):
'''
Tests passing batch value as percentage