-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Always stores any MAC addresses provided as lowercase to avoid issues with comparisons later on. ## Why is this needed boots is attempting to compare pxe booted systems using a lowercased MAC address, so if the user inputs the MAC addresses that are capitalized they will not match. Fixes: #278 ## How Has This Been Tested? Still in progress, will be testing against the Vagrant getting started guide, and manually changing the MAC used to be uppercased. ## How are existing users impacted? What migration steps/scripts do we need? This should not effect existing users (at least ones that have functioning environments), since existing hardware definitions using upper cased MAC addresses would be failing already. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
- Loading branch information
Showing
3 changed files
with
216 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package grpcserver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tinkerbell/tink/protos/hardware" | ||
) | ||
|
||
func Test_server_normalizeHardwareData(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
given *hardware.Hardware | ||
expected *hardware.Hardware | ||
}{ | ||
{ | ||
name: "Expect MAC to be normalized to lowercase", | ||
given: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:42:0E:D9:C7:53", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:42:0e:d9:c7:53", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Expect MAC to be normalized to lowercase, multiple interfaces", | ||
given: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:42:0E:D9:C7:53", | ||
}, | ||
}, | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:4F:0E:D9:C7:5E", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:42:0e:d9:c7:53", | ||
}, | ||
}, | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:4f:0e:d9:c7:5e", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Expect MAC to be normalized to lowercase, nultiple interfaces, mixed casing", | ||
given: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:42:0e:d9:c7:53", | ||
}, | ||
}, | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:4F:0E:D9:C7:5E", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:42:0e:d9:c7:53", | ||
}, | ||
}, | ||
{ | ||
Dhcp: &hardware.Hardware_DHCP{ | ||
Mac: "02:4f:0e:d9:c7:5e", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Handle nil DHCP", | ||
given: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
{ | ||
Dhcp: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Handle nil Interface", | ||
given: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
nil, | ||
}, | ||
}, | ||
}, | ||
expected: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: []*hardware.Hardware_Network_Interface{ | ||
nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Handle nil Interfaces", | ||
given: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: nil, | ||
}, | ||
}, | ||
expected: &hardware.Hardware{ | ||
Network: &hardware.Hardware_Network{ | ||
Interfaces: nil, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Handle nil Network", | ||
given: &hardware.Hardware{Network: nil}, | ||
expected: &hardware.Hardware{Network: nil}, | ||
}, | ||
{ | ||
name: "Handle nil Hardware", | ||
given: nil, | ||
expected: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.NotPanics(t, func() { normalizeHardwareData(tt.given) }) | ||
assert.Equal(t, tt.expected, tt.given) | ||
}) | ||
} | ||
} |