Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybind/ceph_argparse: Fix UnboundLocalError if command doesn't validate #21342

Merged
merged 1 commit into from Apr 13, 2018

Conversation

tserong
Copy link
Contributor

@tserong tserong commented Apr 11, 2018

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

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>
@tserong tserong requested a review from tchaikov April 11, 2018 06:14
@tchaikov tchaikov merged commit abce646 into ceph:master Apr 13, 2018
@tserong tserong deleted the wip-argparse-fix-validate_command-error branch April 13, 2018 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants