Project

General

Profile

« Previous | Next » 

Revision f57d42f5

Added by Tristan Robert almost 6 years ago

Fixes #23859 - Fix vm_exists? method

Fix related tests

View differences:

app/models/concerns/orchestration/compute.rb
end
def vm_exists?
return true unless compute_object
!compute_object.persisted?
return false unless compute_object
compute_object.persisted?
end
end
test/models/host_test.rb
:compute_resource => compute_resources(:ec2),
:organization => nil,
:location => nil)
host.stubs(:vm_exists?).returns(true)
host.stubs(:vm_exists?).returns(false)
host.expects(:queue_compute_create)
assert host.valid?, host.errors.full_messages.to_sentence
assert_equal compute_attributes(:one).vm_attrs, host.compute_attributes
......
:compute_profile => compute_profiles(:two),
:organization => nil,
:location => nil)
host.stubs(:vm_exists?).returns(true)
host.stubs(:vm_exists?).returns(false)
host.expects(:queue_compute_create)
assert host.valid?, host.errors.full_messages.to_sentence
assert_equal compute_attributes(:three).vm_attrs, host.compute_attributes
......
end
test "should create host with compute profile when compute_attributes are empty" do
@host.stubs(:vm_exists?).returns(true)
@host.stubs(:vm_exists?).returns(false)
@host.compute_resource.expects(:create_vm).once.with do |vm_attrs|
vm_attrs['flavor_id'] == @compute_attrs.vm_attrs['flavor_id'] &&
vm_attrs['availability_zone'] == @compute_attrs.vm_attrs['availability_zone']
......
test "should create host with compute profile when compute_attributes are nil" do
@host.compute_attributes = nil
@host.stubs(:vm_exists?).returns(true)
@host.stubs(:vm_exists?).returns(false)
@host.compute_resource.expects(:create_vm).once.with do |vm_attrs|
vm_attrs['flavor_id'] == @compute_attrs.vm_attrs['flavor_id'] &&
vm_attrs['availability_zone'] == @compute_attrs.vm_attrs['availability_zone']
......
vm_attrs['flavor_id'].nil? &&
vm_attrs['availability_zone'].nil?
end
@host.stubs(:vm_exists?).returns(true)
@host.stubs(:vm_exists?).returns(false)
@host.valid?
@host.send(:setCompute)
test/models/orchestration/compute_test.rb
test 'should queue compute orchestration' do
host.compute_resource.stubs(:provided_attributes).returns({:mac => :mac})
host.stubs(:vm_exists?).returns(true)
host.stubs(:vm_exists?).returns(false)
assert_valid host
tasks = host.queue.all.map(&:name)
assert_includes tasks, "Set up compute instance #{host.provision_interface}"
......
test 'should queue ipam and dns orchestration' do
host.compute_resource.stubs(:provided_attributes).returns({:mac => :mac})
host.stubs(:vm_exists?).returns(true)
host.stubs(:vm_exists?).returns(false)
assert_valid host
tasks = host.queue.all.map(&:name)
assert_includes tasks, "Set up compute instance #{host.provision_interface}"

Also available in: Unified diff