From 93411beff0aca47041ef03eb636ea0e597ef8fed Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 25 May 2022 14:55:55 +0900 Subject: [PATCH] Require int value for --limit option Currently the value passed to the --limit option is not validated as part of argument parser and results in an ugly error. $ openstack stack list --limit a invalid literal for int() with base 10: 'a' $ This enables the validation in argument parser to require integer, which shows more clear error. $ openstack stack list --limit a openstack stack list: error: argument --limit: invalid int value: 'a' $ Change-Id: I17397bc202a08de63b715fa15d0f33754393c226 --- heatclient/osc/v1/software_config.py | 1 + heatclient/osc/v1/stack.py | 1 + heatclient/tests/unit/osc/v1/test_software_config.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/heatclient/osc/v1/software_config.py b/heatclient/osc/v1/software_config.py index 41eccd20..dcfa5d66 100644 --- a/heatclient/osc/v1/software_config.py +++ b/heatclient/osc/v1/software_config.py @@ -80,6 +80,7 @@ class ListConfig(command.Lister): parser.add_argument( '--limit', metavar='', + type=int, help=_('Limit the number of configs returned') ) parser.add_argument( diff --git a/heatclient/osc/v1/stack.py b/heatclient/osc/v1/stack.py index 583e18bb..e12ed55f 100644 --- a/heatclient/osc/v1/stack.py +++ b/heatclient/osc/v1/stack.py @@ -537,6 +537,7 @@ class ListStack(command.Lister): parser.add_argument( '--limit', metavar='', + type=int, help=_('The number of stacks returned') ) parser.add_argument( diff --git a/heatclient/tests/unit/osc/v1/test_software_config.py b/heatclient/tests/unit/osc/v1/test_software_config.py index f2afcb1c..3d544bdb 100644 --- a/heatclient/tests/unit/osc/v1/test_software_config.py +++ b/heatclient/tests/unit/osc/v1/test_software_config.py @@ -83,7 +83,7 @@ class TestListConfig(TestConfig): arglist = ['--limit', '3'] parsed_args = self.check_parser(self.cmd, arglist, []) self.cmd.take_action(parsed_args) - self.mock_client.software_configs.list.assert_called_with(limit='3') + self.mock_client.software_configs.list.assert_called_with(limit=3) def test_config_list_marker(self): arglist = ['--marker', 'id123']