Use more appropriate exceptions for validation
Use ValidationError exception type for input validation errors. Change-Id: I5ab58fd64f4745a2e558392bff649b05401ed57a Closes-Bug: 1482279
This commit is contained in:
parent
7ec45dba07
commit
55af7dd364
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in New Issue