diff --git a/lib/miq_environment.rb b/lib/miq_environment.rb index 32cb8e16ea3..d83b14270cd 100644 --- a/lib/miq_environment.rb +++ b/lib/miq_environment.rb @@ -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 diff --git a/spec/models/miq_server/environment_manager_spec.rb b/spec/models/miq_server/environment_manager_spec.rb index 231d0bce1d6..bc23e353419 100644 --- a/spec/models/miq_server/environment_manager_spec.rb +++ b/spec/models/miq_server/environment_manager_spec.rb @@ -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