mirror of
https://github.com/ceph/ceph
synced 2025-01-04 02:02:36 +00:00
Merge pull request #46337 from rishabh-d-dave/missing-arg-exit-code
cephfs-shell: fixes related to Cmd2ArgparseError Reviewed-by: Venky Shankar <vshankar@redhat.com>
This commit is contained in:
commit
4cbb268803
@ -361,6 +361,9 @@ class TestGetAndPut(TestCephFSShell):
|
||||
log.info("o_hash:{}".format(o_hash))
|
||||
assert (s_hash == o_hash)
|
||||
|
||||
# cleanup
|
||||
self.mount_a.run_shell("rm dump4", cwd=None, check_status=False)
|
||||
|
||||
def test_get_without_target_name(self):
|
||||
"""
|
||||
Test that get should fail when there is no target name
|
||||
@ -394,6 +397,9 @@ class TestGetAndPut(TestCephFSShell):
|
||||
# test that dump7 exists
|
||||
self.mount_a.run_shell("cat ./dump7", cwd=None)
|
||||
|
||||
# cleanup
|
||||
self.mount_a.run_shell(args='rm dump7', cwd=None, check_status=False)
|
||||
|
||||
def test_get_to_console(self):
|
||||
"""
|
||||
Test that get passes with target name
|
||||
|
@ -16,10 +16,19 @@ import shlex
|
||||
import stat
|
||||
import errno
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
from cmd2 import Cmd
|
||||
from cmd2 import __version__ as cmd2_version
|
||||
from cmd2.exceptions import Cmd2ArgparseError
|
||||
from distutils.version import LooseVersion
|
||||
# XXX: In cmd2 versions < 1.0.1, we'll get SystemExit(2) instead of
|
||||
# Cmd2ArgparseError
|
||||
if LooseVersion(cmd2_version) >= LooseVersion("1.0.1"):
|
||||
from cmd2.exceptions import Cmd2ArgparseError
|
||||
else:
|
||||
# HACK: so that we don't have check for version everywhere
|
||||
# Cmd2ArgparseError is used.
|
||||
class Cmd2ArgparseError:
|
||||
pass
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
raise RuntimeError("cephfs-shell is only compatible with python3")
|
||||
@ -471,10 +480,15 @@ class CephFSShell(Cmd):
|
||||
if isinstance(e, Cmd2ArgparseError):
|
||||
# NOTE: In case of Cmd2ArgparseError the error message is
|
||||
# already printed beforehand (plus Cmd2ArgparseError
|
||||
# instances have empty message)
|
||||
pass
|
||||
# instances have empty error message), so let's just set the
|
||||
# exit code.
|
||||
set_exit_code_msg(msg=None)
|
||||
else:
|
||||
set_exit_code_msg(msg=f'{type(e).__name__}: {e}')
|
||||
# In cmd2 versions < 1.1.0 we'll get SystemExit(2) instead of
|
||||
# Cmd2ArgparseError
|
||||
except SystemExit:
|
||||
raise
|
||||
|
||||
class path_to_bytes(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
|
Loading…
Reference in New Issue
Block a user