diff --git a/config/bondethernet.py b/config/bondethernet.py index 8cb43aa..28b2da6 100644 --- a/config/bondethernet.py +++ b/config/bondethernet.py @@ -13,6 +13,7 @@ # import logging import config.interface as interface +import config.mac as mac def get_bondethernets(yaml): """ 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: msgs.append("bondethernet %s can only have load-balance if in mode XOR or LACP" % (ifname)) 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: continue diff --git a/config/interface.py b/config/interface.py index de8b35f..2d6ade4 100644 --- a/config/interface.py +++ b/config/interface.py @@ -422,6 +422,9 @@ def validate_interfaces(yaml): if ifname.startswith("BondEthernet") and (None,None) == bondethernet.get_by_name(yaml, ifname): msgs.append("interface %s does not exist in bondethernets" % ifname) 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: iface['state'] = 'up' diff --git a/schema.yaml b/schema.yaml index 0732ecc..e323988 100644 --- a/schema.yaml +++ b/schema.yaml @@ -36,6 +36,7 @@ loopback: --- bondethernet: description: str(exclude='\'"',len=64,required=False) + mac: mac(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) load-balance: enum('l2','l23','l34',required=False) diff --git a/unittest/yaml/correct-example1.yaml b/unittest/yaml/correct-example1.yaml index 93273a5..41b8057 100644 --- a/unittest/yaml/correct-example1.yaml +++ b/unittest/yaml/correct-example1.yaml @@ -5,6 +5,7 @@ test: --- bondethernets: BondEthernet0: + mac: 00:01:02:03:04:05 description: "Infra: xsw0.lab.ipng.ch LACP" interfaces: [ GigabitEthernet2/0/0, GigabitEthernet2/0/1 ] @@ -36,7 +37,6 @@ interfaces: BondEthernet0: description: "Bond, James Bond!" - mac: 00:01:02:03:04:05 lcp: "bond0" sub-interfaces: 200: diff --git a/unittest/yaml/error-bondethernet9.yaml b/unittest/yaml/error-bondethernet9.yaml new file mode 100644 index 0000000..6108c2c --- /dev/null +++ b/unittest/yaml/error-bondethernet9.yaml @@ -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