Project

General

Profile

Download (3.76 KB) Statistics
| Branch: | Tag: | Revision:
90b83222 Ohad Levy
require 'test_helper'

class OrchestrationTest < ActiveSupport::TestCase
def test_host_should_have_queue
h = Host.new
assert_respond_to h, :queue
end
d1eb00f3 Greg Sutcliffe
43c4bd72 Marek Hulan
setup do
@host = FactoryGirl.create(:host)
@nic = FactoryGirl.create(:nic_managed, :host => @host, :ip => '192.168.0.2')
end

d1eb00f3 Greg Sutcliffe
test "test host can call protected queue methods" do
class Host::Test < Host::Base
include Orchestration
def test_execute(method)
execute({:action => [self, method]})
end
abd8f1d1 Daniel Lobato
d1eb00f3 Greg Sutcliffe
protected
abd8f1d1 Daniel Lobato
4f7a4d0b David Davis
def setTest; true; end
d1eb00f3 Greg Sutcliffe
end
h = Host::Test.new
assert h.test_execute(:setTest)
assert_raise Foreman::Exception do
h.test_execute(:noSuchTest)
end
end

43c4bd72 Marek Hulan
test "orchestration can clone object with type attribute" do
@nic.ip = '192.168.0.1'
@nic.type = 'Nic::Bootable'
clone = @nic.send :setup_object_clone, @nic
refute_equal @nic.object_id, clone.object_id
refute_equal @nic.updated_at, clone.updated_at
assert_equal '192.168.0.2', clone.ip
assert_equal 'Nic::Managed', clone.type
end

test "orchestration can clone object and execute block if given before old attributes are assigned" do
@nic.ip = '192.168.0.1'
2d8b4fef Daniel Lobato
clone = @nic.send(:setup_object_clone, @nic) { |c| c.mac, c.ip = 'AA:AA:AA:AA:AA:AA', 'override this' }
43c4bd72 Marek Hulan
refute_equal @nic.object_id, clone.object_id
assert_equal 'AA:AA:AA:AA:AA:AA', clone.mac
assert_equal '192.168.0.2', clone.ip
end

test "orchestration can clone object with belongs_to associations by updating association id" do
# in rails 2 we had to reload associations, this tests prevents regressions after we dropped it in rails 3
@host2 = FactoryGirl.create(:host)
@nic.host_id = @host2.id
clone = @nic.send(:setup_object_clone, @nic)
refute_equal @nic.object_id, clone.object_id
assert_equal @host, clone.host
assert_equal @host2, @nic.host
end
0f5c60f2 Marek Hulan
test '#valid? does not trigger cloning in !unattended mode' do
original, SETTINGS[:unattended] = SETTINGS[:unattended], false
@nic.expects(:setup_clone).never
@nic.valid?
SETTINGS[:unattended] = original
end
2fba6ad7 Ondrej Prazak
context "when subscribing orchestration methods to nic" do
setup do
module Orchestration::TestModule
extend ActiveSupport::Concern

included do
register_rebuild(:rebuild_test, N_('TEST'))
end

def rebuild_test
end
end
@nic.class.send :include, Orchestration::TestModule
end

test "register_rebuild can register methods" do
assert @nic.class.respond_to? :register_rebuild
assert @nic.class.ancestors.include? Orchestration::TestModule
end

test "we can retrieve registered methods" do
assert @nic.class.rebuild_methods.keys.include? :rebuild_test
end
end

context "when subscribing orchestration methods to host" do
setup do
module Orchestration::HostTest
extend ActiveSupport::Concern

included do
register_rebuild(:rebuild_host, N_('HOST'))
end

def rebuild_host
end
end
@host.class.send :include, Orchestration::HostTest
end

test "register_rebuild can register methods" do
assert @host.class.respond_to? :register_rebuild
assert @host.class.ancestors.include? Orchestration::HostTest
end

test "we can retrieve registered methods" do
assert @host.class.rebuild_methods.keys.include? :rebuild_host
end

test "we cannot override already subscribed methods" do
module Orchestration::HostTest2
extend ActiveSupport::Concern

included do
register_rebuild(:rebuild_host, N_('HOST'))
end

def rebuild_host
end
end
assert_raises(RuntimeError) { @host.class.send :include, Orchestration::HostTest2 }
end
end
90b83222 Ohad Levy
end