Fix the argument check for account-generator
Concurrency parameter for account-generator command was accepting negative values and zero. This patch makes sure that when the account-generator is passed a negative value or zero, it ends with an error. Closes-Bug: #1811349 Partially-Implements: blueprint tempest-cli-unit-test-coverage Change-Id: I4d7de89b2ad3ee91d113da3746fe393d8cce2aa2
This commit is contained in:
parent
257f3b009f
commit
58b0538670
@ -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.
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user