From 7b76cc442e18fcaf836bfef3b8debcfbb76202a6 Mon Sep 17 00:00:00 2001 From: Alberto Bellotti Date: Mon, 25 Apr 2016 14:12:52 -0400 Subject: [PATCH] [api] VM power operations are not queued properly When queueing VM power or smartstate operations, the zone was not getting specified for the queue so in environments with providers in different zones, those providers were not getting the task to perform on those VMs. This fixes: #7998 https://bugzilla.redhat.com/show_bug.cgi?id=1326955 --- app/controllers/api_controller/action.rb | 2 ++ spec/requests/api/vms_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) 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)