Skip to content

Commit

Permalink
Fixes #23859 - Fix vm_exists? method
Browse files Browse the repository at this point in the history
Fix related tests
  • Loading branch information
tristanrobert authored and mmoll committed Jun 10, 2018
1 parent 2a6bce4 commit f57d42f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/orchestration/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def match_macs_to_nics(fog_attr)
end

def vm_exists?
return true unless compute_object
!compute_object.persisted?
return false unless compute_object
compute_object.persisted?
end
end
10 changes: 5 additions & 5 deletions test/models/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ def to_managed!
: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
Expand All @@ -2404,7 +2404,7 @@ def to_managed!
: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
Expand Down Expand Up @@ -3465,7 +3465,7 @@ def to_managed!
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']
Expand All @@ -3477,7 +3477,7 @@ def to_managed!

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']
Expand All @@ -3503,7 +3503,7 @@ def to_managed!
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)
Expand Down
4 changes: 2 additions & 2 deletions test/models/orchestration/compute_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def expected_message(identifier)

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}"
Expand Down Expand Up @@ -258,7 +258,7 @@ def expected_message(identifier)

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}"
Expand Down

0 comments on commit f57d42f

Please sign in to comment.