-
Notifications
You must be signed in to change notification settings - Fork 898
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 MiqEnvironment.local_ip_address to not prefer loopback #20992
Merged
Fryguy
merged 4 commits into
ManageIQ:master
from
agrare:fix_miq_environment_local_ip_address
Feb 1, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
88593d3
Fix MiqEnvironment.local_ip_address to not prefer loopback
agrare 0cc1dde
Sort the ip addresses to ensure reliable returns
agrare 2b3e5c0
Stub Socket.ip_address_list and .gethostbyname
agrare 16f8263
Test the same address is returned
agrare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
require 'socket' | ||
|
||
RSpec.describe "Server Environment Management" do | ||
let(:mac_address) { 'a:1:b:2:c:3:d:4' } | ||
let(:hostname) { Socket.gethostname } | ||
let(:loopback) { '127.0.0.1' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were only used in this context so I just moved them down |
||
|
||
context ".get_network_information" do | ||
it "when in non-production mode" do | ||
let(:mac_address) { 'a:1:b:2:c:3:d:4' } | ||
let(:hostname) { "localhost.localdomain" } | ||
let(:ip_address) { "10.1.2.3" } | ||
|
||
before do | ||
require "uuidtools" | ||
allow(UUIDTools::UUID).to receive(:mac_address).and_return(mac_address) | ||
expect(MiqServer.get_network_information).to eq([loopback, hostname, mac_address]) | ||
allow(Socket).to receive(:gethostname).and_return("localhost") | ||
allow(Socket).to receive(:gethostbyname).with("localhost").and_return([hostname]) | ||
allow(Socket).to receive(:ip_address_list).and_return([Addrinfo.ip(ip_address)]) | ||
end | ||
|
||
it "when in non-production mode" do | ||
expect(MiqServer.get_network_information).to eq([ip_address, hostname, mac_address]) | ||
end | ||
end | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For funsies, I think a sort would work too?
Only thing I'm not sure about is if there are multiple private ips, I'm not sure if this is deterministic
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 good point about the return order from
Socket
not being guaranteedThere 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.
Alright now we're sorting by the ip_address and added a spec test with multiple private_ips returned by
Socket.ip_address_list
in different orders.