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

[api] VM power operations are not queued properly #8225

Merged
merged 1 commit into from Apr 25, 2016
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
2 changes: 2 additions & 0 deletions app/controllers/api_controller/action.rb
Expand Up @@ -26,6 +26,8 @@ def queue_object_action(object, summary, options)
:role => options[:role] || nil,
}

queue_options[:zone] = object.my_zone if %w(ems_operations smartstate).include?(options[:role])

MiqTask.generic_action_with_callback(task_options, queue_options)
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/requests/api/vms_spec.rb
Expand Up @@ -177,6 +177,19 @@ def update_raw_power_state(state, *vms)
expect_single_action_result(:success => true, :message => "starting", :href => :vm_url, :task => true)
end

it "starting a vm queues it properly" do
api_basic_authorize action_identifier(:vms, :start)
update_raw_power_state("poweredOff", vm)

run_post(vm_url, gen_request(:start))

expect_single_action_result(:success => true, :message => "starting", :href => :vm_url, :task => true)
expect(MiqQueue.where(:class_name => vm.class.name,
:instance_id => vm.id,
:method_name => "start",
:zone => zone.name).count).to eq(1)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abellotti Do you think we need to test the case where the request comes in to an appliance in one zone but should be queued in a different zone? Not really sure how necessary that test is because in either case the message should be queued to the zone of the object and this test does that. So I'll leave it up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless we're testing the my_zone method, I don't think it's necessary, without the fix, this test fails (zone is not added in the queue). here the zone obtained is from the vm/instance my_zone (which is the my_zone of the vm's ems), and in the test case, the api_zone of the ems in the api test env.

it "starts multiple vms" do
api_basic_authorize action_identifier(:vms, :start)
update_raw_power_state("poweredOff", vm1, vm2)
Expand Down