Skip to content

Commit

Permalink
Merge pull request #22916 from agrare/fix_socket_gethostbyname_deprec…
Browse files Browse the repository at this point in the history
…ation_warning

Fix Socket.gethostbyname deprecation warning
  • Loading branch information
Fryguy authored Mar 6, 2024
2 parents 77eda94 + ee3babf commit 9ed10de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/miq_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def self.arch
# Return the fully qualified hostname for the local host.
#
def self.fully_qualified_domain_name
Socket.gethostbyname(Socket.gethostname).first
hostname = Socket.gethostname
addrinfo = Addrinfo.getaddrinfo(hostname, nil, nil, :STREAM).first
fqdn, _port = addrinfo.getnameinfo
fqdn
end

# Return the local IP v4 address of the local host
Expand Down
4 changes: 2 additions & 2 deletions spec/models/miq_server/environment_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
RSpec.describe "Server Environment Management" do
context ".get_network_information" do
let(:mac_address) { 'a:1:b:2:c:3:d:4' }
let(:hostname) { "localhost.localdomain" }
let(:hostname) { "localhost" }
let(:ip_address) { "10.1.2.3" }

before do
require "uuidtools"
allow(UUIDTools::UUID).to receive(:mac_address).and_return(mac_address)
allow(Socket).to receive(:gethostname).and_return("localhost")
allow(Socket).to receive(:gethostbyname).with("localhost").and_return([hostname])
allow(Addrinfo).to receive(:getaddrinfo).with("localhost", nil, nil, :STREAM).and_return([Addrinfo.tcp("localhost", nil)])
allow(Socket).to receive(:ip_address_list).and_return([Addrinfo.ip(ip_address)])
end

Expand Down

0 comments on commit 9ed10de

Please sign in to comment.