Currently, RegisterWithArgChecks validates only required arguments, so invalid arguments might be passed through if the arguments are registered as optionals. This patch fixes to enable validation for optional arguments.
Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com> --- ryu/services/protocols/bgp/api/base.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ryu/services/protocols/bgp/api/base.py b/ryu/services/protocols/bgp/api/base.py index 525723d..9624e7b 100644 --- a/ryu/services/protocols/bgp/api/base.py +++ b/ryu/services/protocols/bgp/api/base.py @@ -152,6 +152,8 @@ class RegisterWithArgChecks(object): 2) no extra/un-known arguments are passed 3) checks if validator for required arguments is available 4) validates required arguments + 5) if validator for optional arguments is registered, + validates optional arguments. Raises exception if no validator can be found for required args. """ # Check if we are missing arguments. @@ -182,8 +184,8 @@ class RegisterWithArgChecks(object): # Validate required value. validator = get_validator(req_arg) if not validator: - raise ValueError('No validator registered for function %s' - ' and arg. %s' % (func, req_arg)) + raise ValueError('No validator registered for function=%s' + ' and arg=%s' % (func, req_arg)) validator(req_value) req_values.append(req_value) @@ -191,6 +193,12 @@ class RegisterWithArgChecks(object): opt_items = {} for opt_arg, opt_value in kwargs.items(): if opt_arg in self._opt_args: + # Validate optional value. + # Note: If no validator registered for optional value, + # skips validation. + validator = get_validator(opt_arg) + if validator: + validator(opt_value) opt_items[opt_arg] = opt_value # Call actual function -- 2.7.4 ------------------------------------------------------------------------------ _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel