From 549251f5ae1bc40a475b68fa8e6183aafbe703d6 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 7 Mar 2021 11:01:45 +0100 Subject: T3357: Fix invoking TunnelIf() from op-mode As we can also use the TunnelIf() class from op-mode we must ensure that read-only access to the class works even if required configuration keys as "encapsulation" are not passed to the class on invokation. This fixes an isse where "show interfaces tunnel" returned: Traceback (most recent call last): File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 313, in args.vrrp File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 48, in handled_function function(*args, **kwargs) File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 222, in run_show_intf_brief for interface in filtered_interfaces(ifnames, iftypes, vif, vrrp): File "/usr/libexec/vyos/op_mode/show_interfaces.py", line 77, in filtered_interfaces interface = klass(ifname, create=False, debug=False) File "/usr/lib/python3/dist-packages/vyos/ifconfig/tunnel.py", line 99, in __init__ if self.iftype in ['gretap', 'ip6gretap']: AttributeError: 'TunnelIf' object has no attribute 'iftype' --- python/vyos/ifconfig/tunnel.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/python/vyos/ifconfig/tunnel.py b/python/vyos/ifconfig/tunnel.py index 439d88dbc..e5e1300b2 100644 --- a/python/vyos/ifconfig/tunnel.py +++ b/python/vyos/ifconfig/tunnel.py @@ -90,19 +90,21 @@ class TunnelIf(Interface): } def __init__(self, ifname, **kargs): - self.iftype = kargs['encapsulation'] - super().__init__(ifname, **kargs) - - # The gretap interface has the possibility to act as L2 bridge - if self.iftype in ['gretap', 'ip6gretap']: - # no multicast, ttl or tos for gretap - self.definition = { - **TunnelIf.definition, - **{ - 'bridgeable': True, - }, - } + # T3357: we do not have the 'encapsulation' in kargs when calling this + # class from op-mode like "show interfaces tunnel" + if 'encapsulation' in kargs: + self.iftype = kargs['encapsulation'] + # The gretap interface has the possibility to act as L2 bridge + if self.iftype in ['gretap', 'ip6gretap']: + # no multicast, ttl or tos for gretap + self.definition = { + **TunnelIf.definition, + **{ + 'bridgeable': True, + }, + } + super().__init__(ifname, **kargs) def _create(self): if self.config['encapsulation'] in ['ipip6', 'ip6ip6', 'ip6gre']: -- cgit v1.2.3