diff --git a/app/controllers/api_controller/action.rb b/app/controllers/api_controller/action.rb index 6ccc1180725..eab74b0615f 100644 --- a/app/controllers/api_controller/action.rb +++ b/app/controllers/api_controller/action.rb @@ -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 diff --git a/spec/requests/api/vms_spec.rb b/spec/requests/api/vms_spec.rb index c60762b60a2..812cf201360 100644 --- a/spec/requests/api/vms_spec.rb +++ b/spec/requests/api/vms_spec.rb @@ -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 + it "starts multiple vms" do api_basic_authorize action_identifier(:vms, :start) update_raw_power_state("poweredOff", vm1, vm2)