]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
pybind/ceph_argparse: Fix UnboundLocalError if command doesn't validate
authorTim Serong <tserong@suse.com>
Wed, 11 Apr 2018 06:01:53 +0000 (16:01 +1000)
committerTim Serong <tserong@suse.com>
Wed, 11 Apr 2018 06:09:20 +0000 (16:09 +1000)
commitf8a8b7ef2bca2e9b90a2fcb28edfefa22e00766b
tree8cb3394796c39765f35af1589e823b8297ab3a8c
parentaaac83abb516f824f1caef470686b1bffeffa8b4
pybind/ceph_argparse: Fix UnboundLocalError if command doesn't validate

The error case in validate_command() where the command is found but the
command itself is somehow invalid raises an UnboundLocalError, because it
tries to refer to a variable named 'e', but it should be 'ex'.  For example:

  # ceph balancer mode
  Traceback (most recent call last):
    File "/usr/bin/ceph", line 1178, in <module>
      retval = main()
    File "/usr/bin/ceph", line 1109, in main
      verbose)
    File "/usr/bin/ceph", line 535, in new_style_command
      valid_dict = validate_command(sigdict, cmdargs, verbose)
    File "/usr/lib/python3.6/site-packages/ceph_argparse.py", line 1090, in validate_command
      print("Invalid command:", e, file=sys.stderr)
  UnboundLocalError: local variable 'e' referenced before assignment

Replacing 'e' with 'ex' gives the desired output:

  # ceph balancer mode
  Invalid command: missing required parameter mode(none|crush-compat|upmap)
  balancer mode none|crush-compat|upmap :  Set balancer mode
  Error EINVAL: invalid command

Signed-off-by: Tim Serong <tserong@suse.com>
src/pybind/ceph_argparse.py