python-openstackclient/openstackclient/tests/unit/volume
Stephen Finucane c08d6e0391 parseactions: Use ArgumentError, not ArgumentTypeError
If you use the former, you get a pretty error message when there's a
failure. If you use the latter, you get an ugly traceback when used with
the '--debug' flag.

Without this change:

  $ openstack flavor create ... --property '' foo
  ...
  Traceback (most recent call last):
    File "/tmp/venv/lib/python3.11/site-packages/cliff/app.py", line 402, in run_subcommand
      parsed_args = cmd_parser.parse_args(sub_argv)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/argparse.py", line 1862, in parse_args
      args, argv = self.parse_known_args(args, namespace)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/argparse.py", line 1895, in parse_known_args
      namespace, args = self._parse_known_args(args, namespace)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/argparse.py", line 2107, in _parse_known_args
      start_index = consume_optional(start_index)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/argparse.py", line 2047, in consume_optional
      take_action(action, args, option_string)
    File "/usr/lib64/python3.11/argparse.py", line 1971, in take_action
      action(self, namespace, argument_values, option_string)
    File "/tmp/venv/lib/python3.11/site-packages/osc_lib/cli/parseractions.py", line 45, in __call__
      raise argparse.ArgumentTypeError(msg % str(values))
  argparse.ArgumentTypeError: Expected 'key=value' type, but got:
  clean_up CreateFlavor: Expected 'key=value' type, but got:

With this change:

  $ openstack flavor create ... --property '' foo
  ...
  usage: openstack flavor create [-h] [-f {json,shell,table,value,yaml}] [-c COLUMN]
                                 [--noindent] [--prefix PREFIX] [--max-width <integer>]
                                 [--fit-width] [--print-empty] [--id <id>]
                                 [--ram <size-mb>] [--disk <size-gb>]
                                 [--ephemeral <size-gb>] [--swap <size-mb>]
                                 [--vcpus <vcpus>] [--rxtx-factor <factor>]
                                 [--public | --private] [--property <key=value>]
                                 [--project <project>] [--description <description>]
                                 [--project-domain <project-domain>]
                                 <flavor-name>
  openstack flavor create: error: argument --property: Expected 'key=value' type, but got:
  clean_up CreateFlavor:

Change-Id: I9e78b35ad9d016d7a33655141ec579397c5344c0
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-11-15 11:33:19 +00:00
..
v1 parseactions: Use ArgumentError, not ArgumentTypeError 2023-11-15 11:33:19 +00:00
v2 parseactions: Use ArgumentError, not ArgumentTypeError 2023-11-15 11:33:19 +00:00
v3 Migrate resource filter commands to SDK 2023-10-30 12:06:14 +05:30
__init__.py move unit tests to new "unit" test module 2016-09-08 15:19:50 -07:00
test_find_resource.py Blacken openstackclient.volume 2023-05-10 10:51:30 +01:00