Skip to content

Commit

Permalink
Merge pull request ManageIQ#16913 from bdunne/server_hostname
Browse files Browse the repository at this point in the history
Only store the hostname if the hostname is valid
(cherry picked from commit 27e646c)

https://bugzilla.redhat.com/show_bug.cgi?id=1550732
  • Loading branch information
carbonin authored and d-m-u committed Jun 6, 2018
1 parent fa1c34b commit 358452c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def self.active_miq_servers
where(:status => STATUSES_ACTIVE)
end

def hostname
h = super
h if h.to_s.hostname?
end

def self.atStartup
starting_roles = ::Settings.server.role

Expand Down Expand Up @@ -195,7 +200,7 @@ def self.start
server_hash[:ipaddress] = config_hash[:host] = ipaddr
end

unless hostname.blank?
if hostname.present? && hostname.hostname?
hostname = nil if hostname =~ /.*localhost.*/
server_hash[:hostname] = config_hash[:hostname] = hostname
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/miq_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
described_class.invoke_at_startups
end

context "#hostname" do
it("with a valid hostname") { expect(MiqServer.new(:hostname => "test").hostname).to eq("test") }
it("with a valid fqdn") { expect(MiqServer.new(:hostname => "test.example.com").hostname).to eq("test.example.com") }
it("with an invalid hostname") { expect(MiqServer.new(:hostname => "test_host").hostname).to be_nil }
it("without a hostname") { expect(MiqServer.new.hostname).to be_nil }
end

context ".my_guid" do
let(:guid_file) { Rails.root.join("GUID") }

Expand Down

0 comments on commit 358452c

Please sign in to comment.