Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store MAC as lowercase #279

Merged
merged 4 commits into from
Sep 16, 2020
Merged

Store MAC as lowercase #279

merged 4 commits into from
Sep 16, 2020

Conversation

detiber
Copy link
Contributor

@detiber detiber commented Sep 4, 2020

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

@codecov
Copy link

codecov bot commented Sep 4, 2020

Codecov Report

Merging #279 into master will increase coverage by 0.22%.
The diff coverage is 27.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #279      +/-   ##
==========================================
+ Coverage   24.01%   24.24%   +0.22%     
==========================================
  Files          15       15              
  Lines        1345     1353       +8     
==========================================
+ Hits          323      328       +5     
- Misses       1003     1006       +3     
  Partials       19       19              
Impacted Files Coverage Δ
grpc-server/hardware.go 2.40% <27.77%> (+2.40%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9de4dd5...48bcbe7. Read the comment docs.

grpc-server/hardware.go Outdated Show resolved Hide resolved
displague
displague previously approved these changes Sep 4, 2020
Copy link
Member

@displague displague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a nit-pic about potential nil, otherwise this looks good to me.

grpc-server/hardware.go Outdated Show resolved Hide resolved
if data != "" {
logger.With("MAC", interfaces[i].GetDhcp().GetMac()).Info(duplicateMAC)
for _, iface := range hw.GetNetwork().GetInterfaces() {
mac := iface.GetDhcp().GetMac()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it would make sense to add a test for the empty string here prior to calling s.db.GetByMAC().

Would we expect that to be an error condition or would we allow a hardware definition without a mac address?

Copy link
Member

@displague displague Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was questioning similar, whether we should transform the input at all, or just let validate/push throw an error if the hardware mac was not "valid" (lowercase, non-empty).

That said, I don't know if hardware addresses can be treated as optional.

Copy link
Member

@displague displague Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that transforming the data means that any stateful tools (terraform, k8s controllers, salt, etc) that read back the lowercase value will need to be aware of the transform and copy that logic themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative I thought of was to make the comparisons case-insensitive, but with it being stored embedded inside of a stored json blob that seemed a bit more error prone.


func normalizeHardwareData(hw *hardware.Hardware) {
// Ensure MAC is stored as lowercase
for _, iface := range hw.GetNetwork().GetInterfaces() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched things to use the generated proto getters rather than nil checks, since they already include the nil checks and it also eliminates the use of slice indexing.

grpc-server/hardware.go Outdated Show resolved Hide resolved
grpc-server/hardware.go Outdated Show resolved Hide resolved
gianarb
gianarb previously approved these changes Sep 9, 2020
Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks

Signed-off-by: Jason DeTiberus <[email protected]>
@displague displague added the ready-to-merge Signal to Mergify to merge the PR. label Sep 16, 2020
@mergify mergify bot merged commit 966682b into tinkerbell:master Sep 16, 2020
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

force / store mac lowercase
4 participants