Allow BondEthernet to set MAC, and disallow interfaces to set their MAC if they are a bond member
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import config.interface as interface
|
import config.interface as interface
|
||||||
|
import config.mac as mac
|
||||||
|
|
||||||
def get_bondethernets(yaml):
|
def get_bondethernets(yaml):
|
||||||
""" Return a list of all bondethernets. """
|
""" Return a list of all bondethernets. """
|
||||||
@ -170,6 +171,9 @@ def validate_bondethernets(yaml):
|
|||||||
if not get_mode(yaml, bond_ifname) in ['xor','lacp'] and 'load-balance' in iface:
|
if not get_mode(yaml, bond_ifname) in ['xor','lacp'] and 'load-balance' in iface:
|
||||||
msgs.append("bondethernet %s can only have load-balance if in mode XOR or LACP" % (ifname))
|
msgs.append("bondethernet %s can only have load-balance if in mode XOR or LACP" % (ifname))
|
||||||
result = False
|
result = False
|
||||||
|
if 'mac' in iface and mac.is_multicast(iface['mac']):
|
||||||
|
msgs.append("bondethernet %s MAC address %s cannot be multicast" % (ifname, iface['mac']))
|
||||||
|
result = False
|
||||||
|
|
||||||
if not 'interfaces' in iface:
|
if not 'interfaces' in iface:
|
||||||
continue
|
continue
|
||||||
|
@ -422,6 +422,9 @@ def validate_interfaces(yaml):
|
|||||||
if ifname.startswith("BondEthernet") and (None,None) == bondethernet.get_by_name(yaml, ifname):
|
if ifname.startswith("BondEthernet") and (None,None) == bondethernet.get_by_name(yaml, ifname):
|
||||||
msgs.append("interface %s does not exist in bondethernets" % ifname)
|
msgs.append("interface %s does not exist in bondethernets" % ifname)
|
||||||
result = False
|
result = False
|
||||||
|
if ifname.startswith("BondEthernet") and 'mac' in iface:
|
||||||
|
msgs.append("interface %s is a member of bondethernet, cannot set MAC" % ifname)
|
||||||
|
result = False
|
||||||
if not 'state' in iface:
|
if not 'state' in iface:
|
||||||
iface['state'] = 'up'
|
iface['state'] = 'up'
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ loopback:
|
|||||||
---
|
---
|
||||||
bondethernet:
|
bondethernet:
|
||||||
description: str(exclude='\'"',len=64,required=False)
|
description: str(exclude='\'"',len=64,required=False)
|
||||||
|
mac: mac(required=False)
|
||||||
interfaces: list(str(matches='.*GigabitEthernet[0-9]+/[0-9]+/[0-9]+'),required=False)
|
interfaces: list(str(matches='.*GigabitEthernet[0-9]+/[0-9]+/[0-9]+'),required=False)
|
||||||
mode: enum('round-robin','active-backup','broadcast','lacp','xor',required=False)
|
mode: enum('round-robin','active-backup','broadcast','lacp','xor',required=False)
|
||||||
load-balance: enum('l2','l23','l34',required=False)
|
load-balance: enum('l2','l23','l34',required=False)
|
||||||
|
@ -5,6 +5,7 @@ test:
|
|||||||
---
|
---
|
||||||
bondethernets:
|
bondethernets:
|
||||||
BondEthernet0:
|
BondEthernet0:
|
||||||
|
mac: 00:01:02:03:04:05
|
||||||
description: "Infra: xsw0.lab.ipng.ch LACP"
|
description: "Infra: xsw0.lab.ipng.ch LACP"
|
||||||
interfaces: [ GigabitEthernet2/0/0, GigabitEthernet2/0/1 ]
|
interfaces: [ GigabitEthernet2/0/0, GigabitEthernet2/0/1 ]
|
||||||
|
|
||||||
@ -36,7 +37,6 @@ interfaces:
|
|||||||
|
|
||||||
BondEthernet0:
|
BondEthernet0:
|
||||||
description: "Bond, James Bond!"
|
description: "Bond, James Bond!"
|
||||||
mac: 00:01:02:03:04:05
|
|
||||||
lcp: "bond0"
|
lcp: "bond0"
|
||||||
sub-interfaces:
|
sub-interfaces:
|
||||||
200:
|
200:
|
||||||
|
31
unittest/yaml/error-bondethernet9.yaml
Normal file
31
unittest/yaml/error-bondethernet9.yaml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
test:
|
||||||
|
description: "BondEthernet MAC address can't be multicast, members cannot set MAC"
|
||||||
|
errors:
|
||||||
|
expected:
|
||||||
|
- "bondethernet .* MAC address .* cannot be multicast"
|
||||||
|
- "interface .* is a member of bondethernet, cannot set MAC"
|
||||||
|
count: 2
|
||||||
|
---
|
||||||
|
bondethernets:
|
||||||
|
BondEthernet0:
|
||||||
|
description: "Cool, local MACs are fine"
|
||||||
|
mac: 02:00:00:00:00:00
|
||||||
|
BondEthernet1:
|
||||||
|
description: "Cool, global unicast MACs are fine"
|
||||||
|
mac: 04:00:00:00:00:00
|
||||||
|
BondEthernet2:
|
||||||
|
description: "Not cool, multicast MACs"
|
||||||
|
mac: 01:00:00:00:00:00
|
||||||
|
BondEthernet3:
|
||||||
|
description: "Not cool, should not set MAC in the interfaces.BondEthernet3"
|
||||||
|
|
||||||
|
interfaces:
|
||||||
|
BondEthernet0:
|
||||||
|
description: "BE0"
|
||||||
|
BondEthernet1:
|
||||||
|
description: "BE1"
|
||||||
|
BondEthernet2:
|
||||||
|
description: "BE2"
|
||||||
|
BondEthernet3:
|
||||||
|
description: "BE3, not cool, must set in BondEthernet config"
|
||||||
|
mac: 02:00:00:00:00:01
|
Reference in New Issue
Block a user