foreman/test/unit/orchestration/tftp_test.rb @ 2fba6ad7
90b83222 | Ohad Levy | require 'test_helper'
|
|
class TFTPOrchestrationTest < ActiveSupport::TestCase
|
|||
c6cd4b70 | Dominic Cleal | setup :disable_orchestration
|
|
90b83222 | Ohad Levy | def test_host_should_have_tftp
|
|
e895706f | Paul Kelly | if unattended?
|
|
43c4bd72 | Marek Hulan | h = FactoryGirl.build(:host, :managed, :with_tftp_orchestration)
|
|
e895706f | Paul Kelly | assert h.tftp?
|
|
6285a614 | Ohad Levy | assert_not_nil h.tftp
|
|
e895706f | Paul Kelly | end
|
|
90b83222 | Ohad Levy | end
|
|
def test_host_should_not_have_tftp
|
|||
e895706f | Paul Kelly | if unattended?
|
|
e14b5758 | Greg Sutcliffe | h = FactoryGirl.create(:host)
|
|
6285a614 | Ohad Levy | assert_equal false, h.tftp?
|
|
assert_equal nil, h.tftp
|
|||
e895706f | Paul Kelly | end
|
|
90b83222 | Ohad Levy | end
|
|
5440d482 | Greg Sutcliffe | test 'unmanaged should not call methods after managed?' do
|
|
if unattended?
|
|||
h = FactoryGirl.create(:host)
|
|||
Nic::Managed.any_instance.expects(:provision?).never
|
|||
assert h.valid?
|
|||
assert_equal false, h.tftp?
|
|||
end
|
|||
end
|
|||
1a68aea8 | Greg Sutcliffe | def test_generate_pxe_template_for_build
|
|
e895706f | Paul Kelly | if unattended?
|
|
43c4bd72 | Marek Hulan | h = FactoryGirl.create(:host, :build => true,
|
|
:operatingsystem => operatingsystems(:redhat),
|
|||
:architecture => architectures(:x86_64)
|
|||
)
|
|||
8c618ae8 | Greg Sutcliffe | Setting[:unattended_url] = "http://ahost.com:3000"
|
|
b8c81182 | Paul Kelly | ||
017e1049 | Ohad Levy | template = h.send(:generate_pxe_template).split("~")
|
|
b8c81182 | Paul Kelly | expected = File.open(Pathname.new(__FILE__).parent + "pxe_template").readlines.map(&:strip)
|
|
assert_equal template,expected
|
|||
1a68aea8 | Greg Sutcliffe | assert h.build
|
|
end
|
|||
end
|
|||
def test_generate_pxe_template_for_localboot
|
|||
if unattended?
|
|||
e14b5758 | Greg Sutcliffe | h = FactoryGirl.create(:host)
|
|
1a68aea8 | Greg Sutcliffe | as_admin { h.update_attribute :operatingsystem, operatingsystems(:centos5_3) }
|
|
assert !h.build
|
|||
template = h.send(:generate_pxe_template).split("~")
|
|||
expected = File.open(Pathname.new(__FILE__).parent + "pxe_local_template").readlines.map(&:strip)
|
|||
assert_equal template,expected
|
|||
80e0157c | Paul Kelly | end
|
|
end
|
|||
2fba6ad7 | Ondrej Prazak | ||
def test_should_rebuild_tftp
|
|||
h = FactoryGirl.create(:host, :with_tftp_orchestration)
|
|||
Nic::Managed.any_instance.expects(:setTFTP).returns(true)
|
|||
assert h.interfaces.first.rebuild_tftp
|
|||
end
|
|||
def test_should_fail_rebuild_tftp_with_exception
|
|||
h = FactoryGirl.create(:host, :with_tftp_orchestration)
|
|||
Nic::Managed.any_instance.expects(:setTFTP).raises(StandardError, 'TFTP rebuild failed')
|
|||
refute h.interfaces.first.rebuild_tftp
|
|||
end
|
|||
def test_should_skip_rebuild_tftp
|
|||
nic = FactoryGirl.build(:nic_managed)
|
|||
nic.expects(:setTFTP).never
|
|||
assert nic.rebuild_tftp
|
|||
end
|
|||
90b83222 | Ohad Levy | end
|