Project

General

Profile

Bug #398 ยป 0001-fixes-bug-398-issue-with-adding-hosts-with-full-stop.patch

Matt Moran, 10/04/2010 02:05 PM

View differences:

app/models/host.rb
self.ip, self.sp_ip = helper
end
# ensure that host name is fqdn
# if they user inputed short name, the domain name will be appended
# this is done to ensure compatibility with puppet storeconfigs
# if the user added a domain, and the domain doesn't exist, we add it dynamically.
# add the hostname with the domain name if it hostname does not contain domain name
def normalize_hostname
# no hostname was given, since this is before validation we need to ignore it and let the validations to produce an error
unless name.empty?
if name.count(".") == 0
self.name = name + "." + domain.name unless domain.nil?
if name.match(domain.name)
self.name = name unless domain.nil?
else
self.domain = Domain.find_or_create_by_name name.split(".")[1..-1].join(".") if domain.nil?
self.name = name + "." + domain.name unless domain.nil?
end
end
end
test/unit/host_test.rb
assert_equal "myhost.company.com", host.name
end
test "should add hostname if it contains domain name" do
host = Host.create :name => "myhost.company.com", :mac => "aabbccddeeff", :ip => "123.01.02.03",
:domain => Domain.find_or_create_by_name("company.com")
assert_equal "myhost.company.com", host.name
end
test "should be able to save host" do
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
:domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first,
    (1-1/1)