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

Fix failures under Ruby 2.7 #1412

Merged
merged 4 commits into from
Nov 23, 2019
Merged

Fix failures under Ruby 2.7 #1412

merged 4 commits into from
Nov 23, 2019

Conversation

KrisShannon
Copy link
Contributor

@KrisShannon KrisShannon commented Nov 22, 2019

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@KrisShannon
Copy link
Contributor Author

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?

@jaymzh
Copy link
Collaborator

jaymzh commented Nov 22, 2019

I would probably rename mixin/network_constants.rb to mixin/network_helper.rb (ala http_helper), rename the module accordingly, and then add your method in there. Seem sane @tas50

@@ -50,6 +50,14 @@ def parse_media(media_string)
media
end

def darwin_parse_netmask(netmask)
Copy link
Contributor

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.

Copy link
Collaborator

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?

@tas50
Copy link
Contributor

tas50 commented Nov 22, 2019

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.

@KrisShannon
Copy link
Contributor Author

I like the idea of moving it into a renamed mixin/network_helper.rb

I'll give that a go.

@KrisShannon
Copy link
Contributor Author

I found another existing method hex_to_dec_netmask in plugins/aix/network.rb

I'll extract and patch that instead.

@@ -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) } * "."
Copy link
Collaborator

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 :)

Copy link
Contributor Author

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 ¯_(ツ)_/¯

Copy link
Collaborator

@jaymzh jaymzh left a 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...

@KrisShannon
Copy link
Contributor Author

What should I do about the test of the hex_to_dec_netmask helper in spec/unit/plugins/aix/network_spec.rb?

It's no longer specific to AIX so should I create a new spec/unit/mixin/network_helper.rb and move the test across to it?

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>
@KrisShannon
Copy link
Contributor Author

I created a spec/unit/mixin/network_helper.rb and moved the aix plugin test across to it but it doesn't look like it got executed by rspec on buildkite.

Is there something else that needs to be updated so it will run the new spec file? I tried grepping around for the command_spec and the azure_metadata_spec which are bring run but I couldn't find anything.

I did notice that spec/unit/mixin/dmi_decode.rb also doesn't seem to be running.

@jaymzh
Copy link
Collaborator

jaymzh commented Nov 22, 2019

@KrisShannon - I believe the reason those aren't working is because they don't end in _spec.rb

@KrisShannon
Copy link
Contributor Author

Doh! Of course...

@jaymzh
Copy link
Collaborator

jaymzh commented Nov 22, 2019

Don't feel bad, at least you noticed yours wasn't running. Whoever wrote dmi_decode.rb never noticed it didn't run. :) We all miss stuff. :)

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>
@KrisShannon
Copy link
Contributor Author

Ok. Final push I hope.

Test file is renamed and buildkite has run it succesfully

Copy link
Collaborator

@jaymzh jaymzh left a 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?

@jaymzh
Copy link
Collaborator

jaymzh commented Nov 22, 2019

Oh, @KrisShannon you already opened a PR for that too! Sorry I missed that. Hadn't had coffee yet. :) <3 Thanks!

@tas50 tas50 merged commit 48c85ea into chef:master Nov 23, 2019
@tas50
Copy link
Contributor

tas50 commented Nov 23, 2019

Thanks @KrisShannon. You saved us some work next April when we ship with ruby 2.7

@jaymzh
Copy link
Collaborator

jaymzh commented Nov 23, 2019

@tas50 - now that you merged this you can merge #1267 :)

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.

None yet

3 participants