diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2016-08-22 17:21:39 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-08-25 13:33:59 +0900 |
commit | d5ed7c27b7d891111824d902ab7f59eea955f5a7 (patch) | |
tree | 390b49488a02ee567e4f862898dcc278cff6d402 | |
parent | c8b8a34f3dc7e5b108783b1b17a402e518868989 (diff) |
BGPSpeaker: Enable validation for optional arguments
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.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/services/protocols/bgp/api/base.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ryu/services/protocols/bgp/api/base.py b/ryu/services/protocols/bgp/api/base.py index 525723d9..9624e7be 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 |