Merge "[Admin-Util] Fix bad input handling"

This commit is contained in:
Jenkins 2016-07-05 06:54:43 +00:00 committed by Gerrit Code Review
commit 2607643ddb
2 changed files with 18 additions and 5 deletions

View File

@ -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

View File

@ -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):