Don't print HTTP codes for non-HTTP errors
This changes: $ cinder rename asdf ERROR: Must supply either name or description. (HTTP 1) To: $ cinder rename asdf ERROR: Must supply either name or description. Affects rename, snapshot-rename, consisgroup-update, and consisgroup-create-from-src. (consisgroup-* previously printed HTTP 400.) Closes-Bug: #1549020 Closes-Bug: #1549026 Change-Id: Ia920b3b75b53170789b694cbdd49100bd6a72d21
This commit is contained in:
parent
f88e4da1d6
commit
c4c2c56042
cinderclient
@ -89,7 +89,10 @@ class ClientException(Exception):
|
||||
self.request_id = request_id
|
||||
|
||||
def __str__(self):
|
||||
formatted_string = "%s (HTTP %s)" % (self.message, self.code)
|
||||
formatted_string = "%s" % self.message
|
||||
if self.code >= 100:
|
||||
# HTTP codes start at 100.
|
||||
formatted_string += " (HTTP %s)" % self.code
|
||||
if self.request_id:
|
||||
formatted_string += " (Request-ID: %s)" % self.request_id
|
||||
|
||||
|
@ -488,6 +488,14 @@ class ShellTest(utils.TestCase):
|
||||
# Call rename with no arguments
|
||||
self.assertRaises(SystemExit, self.run_command, 'rename')
|
||||
|
||||
def test_rename_invalid_args(self):
|
||||
"""Ensure that error generated does not reference an HTTP code."""
|
||||
|
||||
self.assertRaisesRegexp(exceptions.ClientException,
|
||||
'(?!HTTP)',
|
||||
self.run_command,
|
||||
'rename volume-1234-abcd')
|
||||
|
||||
def test_rename_snapshot(self):
|
||||
# basic rename with positional arguments
|
||||
self.run_command('snapshot-rename 1234 new-name')
|
||||
@ -510,6 +518,11 @@ class ShellTest(utils.TestCase):
|
||||
# Call snapshot-rename with no arguments
|
||||
self.assertRaises(SystemExit, self.run_command, 'snapshot-rename')
|
||||
|
||||
def test_rename_snapshot_invalid_args(self):
|
||||
self.assertRaises(exceptions.ClientException,
|
||||
self.run_command,
|
||||
'snapshot-rename snapshot-1234')
|
||||
|
||||
def test_set_metadata_set(self):
|
||||
self.run_command('metadata 1234 set key1=val1 key2=val2')
|
||||
self.assert_called('POST', '/volumes/1234/metadata',
|
||||
@ -1081,8 +1094,8 @@ class ShellTest(utils.TestCase):
|
||||
self.assert_called('PUT', '/consistencygroups/1234',
|
||||
body=expected)
|
||||
|
||||
def test_consistencygroup_update_bad_request(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
def test_consistencygroup_update_invalid_args(self):
|
||||
self.assertRaises(exceptions.ClientException,
|
||||
self.run_command,
|
||||
'consisgroup-update 1234')
|
||||
|
||||
@ -1123,13 +1136,13 @@ class ShellTest(utils.TestCase):
|
||||
expected)
|
||||
|
||||
def test_consistencygroup_create_from_src_fail_no_snap_cg(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.assertRaises(exceptions.ClientException,
|
||||
self.run_command,
|
||||
'consisgroup-create-from-src '
|
||||
'--name cg')
|
||||
|
||||
def test_consistencygroup_create_from_src_fail_both_snap_cg(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.assertRaises(exceptions.ClientException,
|
||||
self.run_command,
|
||||
'consisgroup-create-from-src '
|
||||
'--name cg '
|
||||
|
@ -2352,11 +2352,11 @@ def do_consisgroup_create_from_src(cs, args):
|
||||
if not args.cgsnapshot and not args.source_cg:
|
||||
msg = ('Cannot create consistency group because neither '
|
||||
'cgsnapshot nor source CG is provided.')
|
||||
raise exceptions.BadRequest(code=400, message=msg)
|
||||
raise exceptions.ClientException(code=1, message=msg)
|
||||
if args.cgsnapshot and args.source_cg:
|
||||
msg = ('Cannot create consistency group because both '
|
||||
'cgsnapshot and source CG are provided.')
|
||||
raise exceptions.BadRequest(code=400, message=msg)
|
||||
raise exceptions.ClientException(code=1, message=msg)
|
||||
cgsnapshot = None
|
||||
if args.cgsnapshot:
|
||||
cgsnapshot = _find_cgsnapshot(cs, args.cgsnapshot)
|
||||
@ -2438,7 +2438,7 @@ def do_consisgroup_update(cs, args):
|
||||
if not kwargs:
|
||||
msg = ('At least one of the following args must be supplied: '
|
||||
'name, description, add-volumes, remove-volumes.')
|
||||
raise exceptions.BadRequest(code=400, message=msg)
|
||||
raise exceptions.ClientException(code=1, message=msg)
|
||||
|
||||
_find_consistencygroup(cs, args.consistencygroup).update(**kwargs)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user