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
  • Loading branch information
carbonin authored Jan 31, 2018
2 parents 5709538 + 287f25d commit 27e646c
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 @@ -51,6 +51,11 @@ def self.active_miq_servers
where(:status => STATUSES_ACTIVE)
end

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

def starting_server_record
self.started_on = self.last_heartbeat = Time.now.utc
self.stopped_on = ""
Expand Down Expand Up @@ -176,7 +181,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
@@ -1,6 +1,13 @@
describe MiqServer do
include_examples ".seed called multiple times"

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 27e646c

Please sign in to comment.