-
Notifications
You must be signed in to change notification settings - Fork 453
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
Fix failures under Ruby 2.7 #1412
Conversation
I'm not sure about the code duplication for parsing the hex netmasks. Should this be extracted and if so where should I put it? |
I would probably rename |
lib/ohai/plugins/darwin/network.rb
Outdated
@@ -50,6 +50,14 @@ def parse_media(media_string) | |||
media | |||
end | |||
|
|||
def darwin_parse_netmask(netmask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you toss a YARD comment on these explaining what the arg and return is for anyone that needs to touch it in the future. Also thanks for keeping the names unique so we avoid collisions in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tas50 I"m pretty sure there these are the same, and thus should not have different names and should not be in different places, no?
it would probably be nice to extract this. Short of that the unique names avoid the problems we had with def collisions in the past. |
I like the idea of moving it into a renamed I'll give that a go. |
I found another existing method I'll extract and patch that instead. |
lib/ohai/plugins/darwin/network.rb
Outdated
@@ -50,6 +50,14 @@ def parse_media(media_string) | |||
media | |||
end | |||
|
|||
def darwin_parse_netmask(netmask) | |||
if netmask =~ /^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/ | |||
return [$1, $2, $3, $4].map { |hex| hex.to_i(16) } * "." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. join
is a much clearer than array-repetition-bizarre-side-use-if-it-isnt-a-number syntax :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree.
The scanf line was using ... * "."
and I just didn't change it when I was editing to remove the scanf.
The new helper from AIX is completely different so ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh the unittests for hext_to_dec_netmask
are still over in the aix plugin specs, you need to move that...
What should I do about the test of the It's no longer specific to AIX so should I create a new |
This is going to be extracted into a helper for use on other platforms Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
This is in preparation for adding a helper method to the mixin for converting ipv4 hex strings to dotted decimal Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
I created a Is there something else that needs to be updated so it will run the new spec file? I tried grepping around for the I did notice that |
@KrisShannon - I believe the reason those aren't working is because they don't end in |
Doh! Of course... |
Don't feel bad, at least you noticed yours wasn't running. Whoever wrote |
Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
The 'scanf' library is gone in Ruby 2.7 A helper for parsing hex netmasks was already written for aix so use it instead. Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
Ok. Final push I hope. Test file is renamed and buildkite has run it succesfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
Someone should probably file a separate PR to fix that dmi_decode spec you noticed. :)
@tas50 - shall we merge this and then mine?
Oh, @KrisShannon you already opened a PR for that too! Sorry I missed that. Hadn't had coffee yet. :) <3 Thanks! |
Thanks @KrisShannon. You saved us some work next April when we ship with ruby 2.7 |
Ruby 2.7 removes the scanf library which is used in the network plugins for darwin and solaris to parse the hex netmask into a dotted decimal
Replaced the scanf library with simple regex and to_i(16) calls
Related Issue
Pull #1410 added ruby 2.7 to the testing matrix which is now causing failures
Types of changes
Checklist: