From 8971c325c08c6b2c9ac8ef1ef1c22613455e2d16 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Tue, 5 Apr 2022 16:08:51 +0000 Subject: [PATCH] Allow bondethernet members list to be empty, and omitted from the YAML config --- config/bondethernet.py | 3 +++ intest/hippo1.yaml | 6 ++++++ schema.yaml | 2 +- unittest/yaml/correct-bondethernet.yaml | 9 ++++++++- vpp/vppapi.py | 5 ++++- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config/bondethernet.py b/config/bondethernet.py index f842236..8cb43aa 100644 --- a/config/bondethernet.py +++ b/config/bondethernet.py @@ -171,6 +171,9 @@ def validate_bondethernets(yaml): msgs.append("bondethernet %s can only have load-balance if in mode XOR or LACP" % (ifname)) result = False + if not 'interfaces' in iface: + continue + for member in iface['interfaces']: if (None, None) == interface.get_by_name(yaml, member): msgs.append("bondethernet %s member %s does not exist" % (ifname, member)) diff --git a/intest/hippo1.yaml b/intest/hippo1.yaml index 8599d53..1bdfa0c 100644 --- a/intest/hippo1.yaml +++ b/intest/hippo1.yaml @@ -1,6 +1,8 @@ bondethernets: BondEthernet0: interfaces: [ GigabitEthernet3/0/0, GigabitEthernet3/0/1 ] + BondEthernet1: + mode: xor interfaces: GigabitEthernet3/0/0: @@ -59,6 +61,10 @@ interfaces: encapsulation: dot1ad: 501 exact-match: False + + BondEthernet1: + mtu: 1500 + vxlan_tunnel1: mtu: 2000 diff --git a/schema.yaml b/schema.yaml index 58aaf1f..ca10af5 100644 --- a/schema.yaml +++ b/schema.yaml @@ -34,7 +34,7 @@ loopback: --- bondethernet: description: str(exclude='\'"',len=64,required=False) - interfaces: list(str(matches='.*GigabitEthernet[0-9]+/[0-9]+/[0-9]+')) + interfaces: list(str(matches='.*GigabitEthernet[0-9]+/[0-9]+/[0-9]+'),required=False) mode: enum('round-robin','active-backup','broadcast','lacp','xor',required=False) load-balance: enum('l2','l23','l34',required=False) --- diff --git a/unittest/yaml/correct-bondethernet.yaml b/unittest/yaml/correct-bondethernet.yaml index b999fda..f86eac5 100644 --- a/unittest/yaml/correct-bondethernet.yaml +++ b/unittest/yaml/correct-bondethernet.yaml @@ -1,5 +1,5 @@ test: - description: "An example of well formed bondethernet" + description: "An example of well formed bondethernets" errors: count: 0 --- @@ -8,6 +8,10 @@ bondethernets: interfaces: [ GigabitEthernet1/0/0, GigabitEthernet1/0/1 ] BondEthernet1: interfaces: [ GigabitEthernet2/0/0, GigabitEthernet2/0/1 ] + mode: xor + load-balance: l2 + BondEthernet2: + mode: round-robin interfaces: GigabitEthernet1/0/0: @@ -35,3 +39,6 @@ interfaces: mtu: 2000 lcp: "be1.2000" addresses: [ 192.0.2.9/29, 2001:db8:1::1/64 ] + + BondEthernet2: + mtu: 1500 diff --git a/vpp/vppapi.py b/vpp/vppapi.py index 69ae98d..5802b3f 100644 --- a/vpp/vppapi.py +++ b/vpp/vppapi.py @@ -275,7 +275,10 @@ class VPPApiDumper(VPPApi): for idx, iface in self.cache['bondethernets'].items(): bond = {"description": ""} if iface.sw_if_index in self.cache['bondethernet_members']: - bond['interfaces'] = [self.cache['interfaces'][x].interface_name for x in self.cache['bondethernet_members'][iface.sw_if_index]] + members = [self.cache['interfaces'][x].interface_name for x in self.cache['bondethernet_members'][iface.sw_if_index]] + if len(members) > 0: + bond['interfaces'] = members + mode = bondethernet.int_to_mode(iface.mode) bond['mode'] = mode if mode in ['xor', 'lacp']: