Merge "Fix the argument check for account-generator"

This commit is contained in:
Zuul
2020-06-23 21:13:18 +00:00
committed by Gerrit Code Review
3 changed files with 38 additions and 1 deletions
@@ -0,0 +1,7 @@
---
fixes:
- |
Concurrency parameter for account-generator command was accepting
negative values and zero. The concurrency parameter now accepts only
positive numbers. When a negative value or zero is passed to the
program then the program ends and help is displayed.
+10 -1
View File
@@ -97,6 +97,7 @@ To see help on specific argument, please do: ``tempest account-generator
[OPTIONS] <accounts_file.yaml> -h``.
"""
import argparse
import os
import traceback
@@ -199,6 +200,14 @@ def dump_accounts(resources, identity_version, account_file):
LOG.info('%s generated successfully!', account_file)
def positive_int(number):
number = int(number)
if number <= 0:
raise argparse.ArgumentTypeError("Concurrency value should be a "
"positive number")
return number
def _parser_add_args(parser):
parser.add_argument('-c', '--config-file',
metavar='/etc/tempest.conf',
@@ -228,7 +237,7 @@ def _parser_add_args(parser):
help='Resources tag')
parser.add_argument('-r', '--concurrency',
default=1,
type=int,
type=positive_int,
required=False,
dest='concurrency',
help='Concurrency count')
@@ -337,3 +337,24 @@ class TestDumpAccountsV3(TestDumpAccountsV2):
def setUp(self):
self.mock_domains()
super(TestDumpAccountsV3, self).setUp()
class TestAccountGeneratorCliCheck(base.TestCase):
def setUp(self):
super(TestAccountGeneratorCliCheck, self).setUp()
self.account_generator = account_generator.TempestAccountGenerator(
app=mock.Mock(), app_args=mock.Mock())
self.parser = self.account_generator.get_parser("generator")
def test_account_generator_zero_concurrency(self):
error = self.assertRaises(
SystemExit, lambda: self.parser.parse_args(
['-r', '0', 'accounts_file.yaml']))
self.assertTrue(error.code != 0)
def test_account_generator_negative_concurrency(self):
error = self.assertRaises(
SystemExit, lambda: self.parser.parse_args(
['-r', '-1', 'accounts_file.yaml']))
self.assertTrue(error.code != 0)