[Admin-Util] Fix bad input handling
Raise a better error when failing to parse the command arguments Change-Id: I64fe123445bc22cd204fb0b62f31b9d913ed1ca7
This commit is contained in:
parent
84ec8fe9ad
commit
30fd656749
@ -42,8 +42,12 @@ def parse_multi_keyval_opt(opt_list):
|
||||
|
||||
result = dict()
|
||||
for opt_value in opt_list:
|
||||
key, value = opt_value.split('=')
|
||||
result[key] = value
|
||||
try:
|
||||
key, value = opt_value.split('=')
|
||||
result[key] = value
|
||||
except ValueError:
|
||||
raise ValueError("Illegal argument [%s]: input should have the "
|
||||
"format of '--property key=value'" % opt_value)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -69,9 +69,7 @@ class AbstractTestAdminUtils(base.BaseTestCase):
|
||||
resources.get_plugin_dir(plugin_name))
|
||||
|
||||
def _test_resource(self, res_name, op, **kwargs):
|
||||
# Must call the internal notify_loop in order to get the errors
|
||||
errors = registry._get_callback_manager()._notify_loop(
|
||||
res_name, op, 'nsxadmin', **kwargs)
|
||||
errors = self._test_resource_with_errors(res_name, op, **kwargs)
|
||||
if len(errors) > 0:
|
||||
msg = (_("admin util %(res)s/%(op)s failed with message: "
|
||||
"%(err)s") % {'res': res_name,
|
||||
@ -79,6 +77,11 @@ class AbstractTestAdminUtils(base.BaseTestCase):
|
||||
'err': errors[0]})
|
||||
self.fail(msg=msg)
|
||||
|
||||
def _test_resource_with_errors(self, res_name, op, **kwargs):
|
||||
# Must call the internal notify_loop in order to get the errors
|
||||
return registry._get_callback_manager()._notify_loop(
|
||||
res_name, op, 'nsxadmin', **kwargs)
|
||||
|
||||
def _test_resources(self, res_dict):
|
||||
for res in res_dict.keys():
|
||||
res_name = res_dict[res].name
|
||||
@ -108,6 +111,12 @@ class TestNsxvAdminUtils(AbstractTestAdminUtils,
|
||||
args = {'property': ["xxx=yyy"]}
|
||||
self._test_resource('networks', 'list', **args)
|
||||
|
||||
def test_bad_args(self):
|
||||
args = {'property': ["xxx"]}
|
||||
errors = self._test_resource_with_errors(
|
||||
'networks', 'nsx-update', **args)
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
|
||||
class TestNsxv3AdminUtils(AbstractTestAdminUtils,
|
||||
test_v3_plugin.NsxV3PluginTestCaseMixin):
|
||||
|
Loading…
x
Reference in New Issue
Block a user