diff --git a/vmware_nsx/shell/admin/plugins/common/utils.py b/vmware_nsx/shell/admin/plugins/common/utils.py index 947a1f33ab..f021d7934f 100644 --- a/vmware_nsx/shell/admin/plugins/common/utils.py +++ b/vmware_nsx/shell/admin/plugins/common/utils.py @@ -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 diff --git a/vmware_nsx/tests/unit/shell/test_admin_utils.py b/vmware_nsx/tests/unit/shell/test_admin_utils.py index 0c610d63ba..dcebf44b8e 100644 --- a/vmware_nsx/tests/unit/shell/test_admin_utils.py +++ b/vmware_nsx/tests/unit/shell/test_admin_utils.py @@ -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):