Merge "[Admin-Util] Fix bad input handling"
This commit is contained in:
commit
2607643ddb
|
@ -42,8 +42,12 @@ def parse_multi_keyval_opt(opt_list):
|
||||||
|
|
||||||
result = dict()
|
result = dict()
|
||||||
for opt_value in opt_list:
|
for opt_value in opt_list:
|
||||||
key, value = opt_value.split('=')
|
try:
|
||||||
result[key] = value
|
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
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,9 +69,7 @@ class AbstractTestAdminUtils(base.BaseTestCase):
|
||||||
resources.get_plugin_dir(plugin_name))
|
resources.get_plugin_dir(plugin_name))
|
||||||
|
|
||||||
def _test_resource(self, res_name, op, **kwargs):
|
def _test_resource(self, res_name, op, **kwargs):
|
||||||
# Must call the internal notify_loop in order to get the errors
|
errors = self._test_resource_with_errors(res_name, op, **kwargs)
|
||||||
errors = registry._get_callback_manager()._notify_loop(
|
|
||||||
res_name, op, 'nsxadmin', **kwargs)
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
msg = (_("admin util %(res)s/%(op)s failed with message: "
|
msg = (_("admin util %(res)s/%(op)s failed with message: "
|
||||||
"%(err)s") % {'res': res_name,
|
"%(err)s") % {'res': res_name,
|
||||||
|
@ -79,6 +77,11 @@ class AbstractTestAdminUtils(base.BaseTestCase):
|
||||||
'err': errors[0]})
|
'err': errors[0]})
|
||||||
self.fail(msg=msg)
|
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):
|
def _test_resources(self, res_dict):
|
||||||
for res in res_dict.keys():
|
for res in res_dict.keys():
|
||||||
res_name = res_dict[res].name
|
res_name = res_dict[res].name
|
||||||
|
@ -108,6 +111,12 @@ class TestNsxvAdminUtils(AbstractTestAdminUtils,
|
||||||
args = {'property': ["xxx=yyy"]}
|
args = {'property': ["xxx=yyy"]}
|
||||||
self._test_resource('networks', 'list', **args)
|
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,
|
class TestNsxv3AdminUtils(AbstractTestAdminUtils,
|
||||||
test_v3_plugin.NsxV3PluginTestCaseMixin):
|
test_v3_plugin.NsxV3PluginTestCaseMixin):
|
||||||
|
|
Loading…
Reference in New Issue