Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #23859 - Fix queue orchestration compute #5675

Merged
merged 2 commits into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/concerns/orchestration/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def vm_name
def queue_compute
return log_orchestration_errors unless compute? && errors.empty?
# Create a new VM if it doesn't already exist or update an existing vm
vm_exists? ? queue_compute_create : queue_compute_update
vm_exists? ? queue_compute_update : queue_compute_create
end

def queue_compute_create
Expand Down 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