Project

General

Profile

« Previous | Next » 

Revision 014c9ab5

Added by Greg Sutcliffe about 10 years ago

Fixes #4680 - Don't append periods to unqualified unmanaged hosts

View differences:

app/models/host/managed.rb
# we should guarantee the fqdn is always fully qualified
def fqdn
return name if name.blank?
return name if name.blank? || ( !SETTINGS[:unattended] && domain.nil? )
name.include?('.') ? name : "#{name}.#{domain}"
end
......
self.name = fqdn
end
# A managed host we should know the domain for; and the shortname shouldn't include a period
errors.add(:name, _("must not include periods")) if managed? and shortname.include? "."
# This only applies for unattended=true, as otherwise the name field includes the domain
errors.add(:name, _("must not include periods")) if ( managed? && shortname.include?(".") && SETTINGS[:unattended] )
end
def assign_hostgroup_attributes attrs = []
test/unit/host_test.rb
assert_equal "my.host.company.com", host.name
end
context "when unattended is false" do
def setup
SETTINGS[:unattended] = false
end
def teardown
SETTINGS[:unattended] = true
end
test "should be able to save hosts with full domain" do
host = Host.create :name => "myhost.foo", :mac => "aabbccddeeff", :ip => "123.01.02.03"
assert_equal "myhost.foo", host.fqdn
end
test "should be able to save hosts with no domain" do
host = Host.create :name => "myhost", :mac => "aabbccddeeff", :ip => "123.01.02.03"
assert_equal "myhost", host.fqdn
end
end
test "should be able to save host" do
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "2.3.4.3",

Also available in: Unified diff