Browse Source

Merge "Fix the argument check for account-generator"

changes/68/737668/1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
ecf2d6817b
3 changed files with 38 additions and 1 deletions
  1. +7
    -0
      releasenotes/notes/account-generator-accepts-positive-numbers-only-33a366a297494ef7.yaml
  2. +10
    -1
      tempest/cmd/account_generator.py
  3. +21
    -0
      tempest/tests/cmd/test_account_generator.py

+ 7
- 0
releasenotes/notes/account-generator-accepts-positive-numbers-only-33a366a297494ef7.yaml View File

@@ -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
tempest/cmd/account_generator.py 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')


+ 21
- 0
tempest/tests/cmd/test_account_generator.py View File

@@ -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…
Cancel
Save