1
0
mirror of https://github.com/rancher/os.git synced 2025-09-03 15:54:24 +00:00

Fixed a regression bug where wildcard MAC matching would match bond and vlan interface.

This commit is contained in:
Morten Møller Riis
2019-04-08 10:41:23 +02:00
committed by niusmallnan
parent 2249a897f1
commit 6126091822
2 changed files with 35 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ import (
type mockLink struct {
attrs netlink.LinkAttrs
t string
}
func (l mockLink) Attrs() *netlink.LinkAttrs {
@@ -16,33 +17,57 @@ func (l mockLink) Attrs() *netlink.LinkAttrs {
}
func (l mockLink) Type() string {
return "fake"
return l.t
}
func TestFindMatch(t *testing.T) {
testCases := []struct {
match string
mac string
t string
name string
bond string
expected bool
}{
{
"mac:aa:bb:cc:dd:ee:ff",
"aa:bb:cc:dd:ee:ff",
"fake",
"eth0",
"bond0",
true,
},
{
"mac:aa:bb:cc:*",
"aa:bb:cc:12:34:56",
"fake",
"eth0",
"bond0",
true,
},
{
"mac:aa:bb:cc:*",
"11:bb:cc:dd:ee:ff",
"fake",
"eth0",
"bond0",
false,
},
{
"mac:aa:bb:cc:dd:ee:ff",
"aa:bb:cc:dd:ee:11",
"fake",
"eth0",
"bond0",
false,
},
// This is a bond eg. bond0
{
"mac:aa:bb:*",
"aa:bb:cc:dd:ee:11",
"bond",
"bond0",
"bond0",
false,
},
}
@@ -50,14 +75,15 @@ func TestFindMatch(t *testing.T) {
for i, tt := range testCases {
netCfg := NetworkConfig{
Interfaces: map[string]InterfaceConfig{
"eth0": InterfaceConfig{
tt.name: InterfaceConfig{
Match: tt.match,
Bond: tt.bond,
},
},
}
linkAttrs := netlink.NewLinkAttrs()
linkAttrs.Name = "eth0"
linkAttrs.Name = tt.name
linkAttrs.HardwareAddr, _ = net.ParseMAC(tt.mac)
link := mockLink{attrs: linkAttrs}
@@ -67,4 +93,5 @@ func TestFindMatch(t *testing.T) {
t.Errorf("Test case %d failed: mac: '%s' match '%s' expected: '%v' got: '%v'", i, tt.mac, tt.match, tt.expected, match)
}
}
}