diff options
author | Petr Malik <pmalik@tesora.com> | 2015-08-06 12:01:41 -0400 |
---|---|---|
committer | Petr Malik <pmalik@tesora.com> | 2015-09-03 20:41:25 +0000 |
commit | 55af7dd364d8bece74d67c21e07cc5fe9dd898aa (patch) | |
tree | 36b0b3e0680f61c7ed8996666468b40435176726 | |
parent | 7ec45dba07f3815b2f4ce3a0dae5edffb0550f54 (diff) | |
download | python-troveclient-55af7dd364d8bece74d67c21e07cc5fe9dd898aa.tar.gz |
Use more appropriate exceptions for validation
Use ValidationError exception type for input validation errors.
Change-Id: I5ab58fd64f4745a2e558392bff649b05401ed57a
Closes-Bug: 1482279
-rw-r--r-- | troveclient/tests/test_v1_shell.py | 13 | ||||
-rw-r--r-- | troveclient/v1/shell.py | 12 | ||||
-rw-r--r-- | troveclient/v1/users.py | 5 |
3 files changed, 16 insertions, 14 deletions
diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py index 72a52a0..1290526 100644 --- a/troveclient/tests/test_v1_shell.py +++ b/troveclient/tests/test_v1_shell.py @@ -26,6 +26,7 @@ import troveclient.v1.shell class ShellFixture(fixtures.Fixture): + def setUp(self): super(ShellFixture, self).setUp() self.shell = troveclient.shell.OpenStackTroveShell() @@ -122,11 +123,11 @@ class ShellTest(utils.TestCase): def test_flavor_list_error(self): cmd = 'flavor-list --datastore_type mysql' - exepcted_error_msg = ('Specify both <datastore_type> and ' - '<datastore_version_id> to list datastore ' - 'version associated flavors') + exepcted_error_msg = ('Missing argument\(s\): ' + 'datastore_type, datastore_version_id') self.assertRaisesRegexp( - exceptions.CommandError, exepcted_error_msg, self.run_command, cmd) + exceptions.MissingArgs, exepcted_error_msg, self.run_command, + cmd) def test_flavor_show(self): self.run_command('flavor-show 1') @@ -182,7 +183,7 @@ class ShellTest(utils.TestCase): cmd = ('create test-member-1 1 --size 1 ' '--nic net-id=some-id,port-id=some-id') self.assertRaisesRegexp( - exceptions.CommandError, 'Invalid nic argument', + exceptions.ValidationError, 'Invalid nic argument', self.run_command, cmd) def test_cluster_create(self): @@ -229,7 +230,7 @@ class ShellTest(utils.TestCase): cmd = ('cluster-create test-clstr vertica 7.1 --instance volume=2 ' '--instance flavor=2,volume=1') self.assertRaisesRegexp( - exceptions.CommandError, 'flavor is required', + exceptions.ValidationError, 'flavor is required', self.run_command, cmd) def test_datastore_list(self): diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index 3dfa5f7..58e7c60 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -134,9 +134,8 @@ def do_flavor_list(cs, args): elif not args.datastore_type and not args.datastore_version_id: flavors = cs.flavors.list() else: - err_msg = ("Specify both <datastore_type> and <datastore_version_id>" - " to list datastore version associated flavors.") - raise exceptions.CommandError(err_msg) + raise exceptions.MissingArgs(['datastore_type', + 'datastore_version_id']) # Fallback to str_id where necessary. _flavors = [] @@ -387,7 +386,7 @@ def do_create(cs, args): "the form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr," "port-id=port-uuid>, with at minimum net-id or port-id " "(but not both) specified." % nic_str) - raise exceptions.CommandError(err_msg) + raise exceptions.ValidationError(err_msg) nics.append(nic_info) instance = cs.instances.create(args.name, @@ -440,12 +439,11 @@ def do_cluster_create(cs, args): instance_info[k] = v if not instance_info.get('flavorRef'): err_msg = ("flavor is required. %s." % INSTANCE_ERROR) - raise exceptions.CommandError(err_msg) + raise exceptions.ValidationError(err_msg) instances.append(instance_info) if len(instances) == 0: - err_msg = ("An instance must be specified. %s." % INSTANCE_ERROR) - raise exceptions.CommandError(err_msg) + raise exceptions.MissingArgs(['instance']) cluster = cs.clusters.create(args.name, args.datastore, diff --git a/troveclient/v1/users.py b/troveclient/v1/users.py index 6f01878..b5a50da 100644 --- a/troveclient/v1/users.py +++ b/troveclient/v1/users.py @@ -16,11 +16,13 @@ from troveclient import base from troveclient import common +from troveclient import exceptions from troveclient.v1 import databases class User(base.Resource): """A database user.""" + def __repr__(self): return "<User: %s>" % self.name @@ -67,7 +69,8 @@ class Users(base.ManagerWithFind): :rtype: :class:`User`. """ if not newuserattr: - raise Exception("No updates specified for user %s" % username) + raise exceptions.ValidationError("No updates specified for user %s" + % username) instance_id = base.getid(instance) user = common.quote_user_host(username, hostname) user_dict = {} |