From 5ab45752ce5a7dbbb16f357f8d405fb272eab512 Mon Sep 17 00:00:00 2001 From: oc Date: Mon, 5 Nov 2018 21:10:25 +0800 Subject: api: fix regression that match set option has no default value The commit 000589f3c "api: Implement UpdatePolicy()" introduced a regression: if match-set-options is not defined in config file, gobgpd starts with error: failed to get policy info: not found... This fix set match-set-options to default when needed. --- tools/pyang_plugins/bgpyang2golang.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index 62497f09..01ee9c3b 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -546,14 +546,6 @@ def emit_enum(prefix, name, stmt, substmts, fd): print(' %s: %d,' % (enum_name, i), file=fd) print('}\n', file=fd) - print('func (v %s) ToInt() int {' % type_name, file=fd) - print('i, ok := %sToIntMap[v]' % type_name, file=fd) - print('if !ok {', file=fd) - print('return -1', file=fd) - print('}', file=fd) - print('return i', file=fd) - print('}', file=fd) - print('var IntTo%sMap = map[int]%s {' % (type_name, type_name), file=fd) for i, sub in enumerate(substmts): enum_name = '%s_%s' % (const_prefix, convert_const_prefix(sub.arg)) @@ -580,6 +572,19 @@ def emit_enum(prefix, name, stmt, substmts, fd): print(' return v', file=fd) print('}', file=fd) + print('func (v %s) ToInt() int {' % type_name, file=fd) + print('_v := v.DefaultAsNeeded()') + print('i, ok := %sToIntMap[_v]' % type_name, file=fd) + + else: + print('func (v %s) ToInt() int {' % type_name, file=fd) + print('i, ok := %sToIntMap[v]' % type_name, file=fd) + print('if !ok {', file=fd) + print('return -1', file=fd) + print('}', file=fd) + print('return i', file=fd) + print('}', file=fd) + def emit_typedef(ctx, mod, fd): prefix = mod.i_prefix -- cgit v1.2.3