Project

General

Profile

Download (3.4 KB) Statistics
| Branch: | Tag: | Revision:
2f077f63 Ohad Levy
require 'test_helper'

class HostTest < ActiveSupport::TestCase
c22d6db2 Ohad Levy
test "should not save without a hostname" do
host = Host.new
assert !host.save
end

test "should fix mac address" do
host = Host.create :name => "myhost", :mac => "aabbccddeeff"
assert_equal "aa:bb:cc:dd:ee:ff", host.mac
end

test "should fix ip address if a leading zero is used" do
host = Host.create :name => "myhost", :mac => "aabbccddeeff", :ip => "123.01.02.03"
assert_equal "123.1.2.3", host.ip
2f077f63 Ohad Levy
end
410fb097 Ohad Levy
test "should add domain name to hostname" do
host = Host.create :name => "myhost", :mac => "aabbccddeeff", :ip => "123.01.02.03",
:domain => Domain.find_or_create_by_name("company.com")
assert_equal "myhost.company.com", host.name
end
bff742ab Ohad Levy
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,
ea4fd101 Ohad Levy
:architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition"
puts host.errors.full_messages
bff742ab Ohad Levy
assert host.valid?
end

363141af Ohad Levy
test "should import facts from yaml stream" do
e22af92d Ohad Levy
h=Host.new(:name => "sinn1636.lan")
ea4fd101 Ohad Levy
h.disk = "!" # workaround for now
363141af Ohad Levy
h.importFacts YAML::load(File.read(File.expand_path(File.dirname(__FILE__) + "/facts.yml")))
e22af92d Ohad Levy
assert h.valid?
end
ea4fd101 Ohad Levy
363141af Ohad Levy
test "should import facts from yaml of a new host" do
9aafc2cb Ohad Levy
assert Host.importHostAndFacts(File.read(File.expand_path(File.dirname(__FILE__) + "/facts.yml")))
363141af Ohad Levy
end
b09b4515 Ohad Levy
if SETTINGS[:unattended].nil? or SETTINGS[:unattended]
test "should not save if both ptable and disk are not defined" 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,
:architecture => Architecture.first, :environment => Environment.first
assert true unless SETTINGS[:attended]
assert !host.valid?
end
ea4fd101 Ohad Levy
end

test "should save if ptable is defined" 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,
:architecture => Architecture.first, :environment => Environment.first, :ptable => Ptable.first
assert host.valid?
end

test "should save if disk is defined" 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,
:architecture => Architecture.first, :environment => Environment.first, :disk => "aaa"
assert host.valid?
end

fa73f381 Ohad Levy
test "should import from external nodes output" do
# create a dummy node
fa7070ca Ohad Levy
Parameter.all.each {|x| x.destroy}
fa73f381 Ohad Levy
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
:domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first,
:architecture => Architecture.first, :environment => Environment.first, :disk => "aaa"

# dummy external node info
5f6b2196 Paul Kelly
nodeinfo = {"environment" => "global_puppetmaster", "parameters"=>{"puppetmaster"=>"puppet", "MYVAR"=>"value"}, "classes"=>["base","apache"]}
fa73f381 Ohad Levy
host.importNode nodeinfo

assert host.info == nodeinfo
end
2f077f63 Ohad Levy
end