diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-02-25 20:46:58 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-02-25 20:46:58 +0000 |
commit | 53fc06dd813bddc43ea6ed1ac44512f07c51e64f (patch) | |
tree | bc72a7788786a98024920069d1dde726a4c00aec | |
parent | fe66becd096e3d6b99e9cb58c25b78af6994fc1a (diff) | |
parent | c4c2c56042e7829aa9ee0c4b7fad93d039fb4841 (diff) | |
download | python-cinderclient-53fc06dd813bddc43ea6ed1ac44512f07c51e64f.tar.gz |
Merge "Don't print HTTP codes for non-HTTP errors"
-rw-r--r-- | cinderclient/exceptions.py | 5 | ||||
-rw-r--r-- | cinderclient/tests/unit/v2/test_shell.py | 21 | ||||
-rw-r--r-- | cinderclient/v2/shell.py | 6 |
3 files changed, 24 insertions, 8 deletions
diff --git a/cinderclient/exceptions.py b/cinderclient/exceptions.py index 3c79cee..dad3b18 100644 --- a/cinderclient/exceptions.py +++ b/cinderclient/exceptions.py @@ -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 diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 6399eb0..deddff0 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -496,6 +496,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') @@ -518,6 +526,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', @@ -1089,8 +1102,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') @@ -1131,13 +1144,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 ' diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index d1f78f4..7f83dbc 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -2368,11 +2368,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) @@ -2454,7 +2454,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) |