Project

General

Profile

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
444 444
    self.ip, self.sp_ip = helper
445 445
  end
446 446

  
447
  # ensure that host name is fqdn
448
  # if they user inputed short name, the domain name will be appended
449
  # this is done to ensure compatibility with puppet storeconfigs
450
  # if the user added a domain, and the domain doesn't exist, we add it dynamically.
447
  # add the hostname with the domain name if it hostname does not contain domain name
451 448
  def normalize_hostname
452 449
    # no hostname was given, since this is before validation we need to ignore it and let the validations to produce an error
453 450
    unless name.empty?
454
      if name.count(".") == 0
455
        self.name = name + "." + domain.name unless domain.nil?
451
      if name.match(domain.name)
452
        self.name = name unless domain.nil?
456 453
      else
457
        self.domain = Domain.find_or_create_by_name name.split(".")[1..-1].join(".") if domain.nil?
454
        self.name = name + "." + domain.name unless domain.nil?
458 455
      end
459 456
    end
460 457
  end
test/unit/host_test.rb
22 22
    assert_equal "myhost.company.com", host.name
23 23
  end
24 24

  
25
  test "should add hostname if it contains domain name" do
26
    host = Host.create :name => "myhost.company.com", :mac => "aabbccddeeff", :ip => "123.01.02.03",
27
      :domain => Domain.find_or_create_by_name("company.com")
28
    assert_equal "myhost.company.com", host.name
29
  end
30
  
25 31
  test "should be able to save host" do
26 32
    host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
27 33
      :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first,
28
-