From c102f9d8f1d318b31079443cb71932f28a976f8c Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Tue, 17 Jan 2017 12:19:48 -0500 Subject: [PATCH 1/2] Backport of PR #13363 for Euwe --- .../engine/miq_ae_engine.rb | 4 ++- .../engine/miq_ae_state_machine.rb | 1 + .../miq_ae_state_machine_retry_spec.rb | 35 +++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_engine.rb b/lib/miq_automation_engine/engine/miq_ae_engine.rb index fa09574687b..f15d5e1b886 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine.rb @@ -139,7 +139,9 @@ def self.deliver(*args) message = "Requeuing #{options.inspect} for object [#{object_name}] with state [#{options[:state]}] to Automate for delivery in [#{ae_retry_interval}] seconds" _log.info(message) - deliver_queue(options, :deliver_on => deliver_on) + queue_options = {:deliver_on => deliver_on} + queue_options[:server_guid] = MiqServer.my_guid if ws.root['ae_retry_server_affinity'] + deliver_queue(options, queue_options) else if ae_result.casecmp('error').zero? message = "Error delivering #{options[:attrs].inspect} for object [#{object_name}] with state [#{state}] to Automate: #{ws.root['ae_message']}" diff --git a/lib/miq_automation_engine/engine/miq_ae_state_machine.rb b/lib/miq_automation_engine/engine/miq_ae_state_machine.rb index b5a5948be27..45511f4ff5e 100644 --- a/lib/miq_automation_engine/engine/miq_ae_state_machine.rb +++ b/lib/miq_automation_engine/engine/miq_ae_state_machine.rb @@ -61,6 +61,7 @@ def process_state(f, message, args) @workspace.root['ae_state'] = f['name'] if @workspace.root['ae_state'].blank? @workspace.root['ae_result'] = 'ok' if @workspace.root['ae_result'].blank? @workspace.root['ae_next_state'] = '' + @workspace.root['ae_retry_server_affinity'] = false # Do not proceed further unless this state is runnable return unless state_runnable?(f) diff --git a/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb b/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb index aa2565c6a6f..6bde8b6c58f 100644 --- a/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb +++ b/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb @@ -11,7 +11,6 @@ @root_class = "TOP_OF_THE_WORLD" @root_instance = "EVEREST" @user = FactoryGirl.create(:user_with_group) - @miq_server = FactoryGirl.create(:miq_server) @automate_args = {:namespace => @namespace, :class_name => @root_class, :instance_name => @root_instance, @@ -19,8 +18,7 @@ :miq_group_id => @user.current_group_id, :tenant_id => @user.current_tenant.id, :automate_message => 'create'} - allow(MiqServer).to receive(:my_zone).and_return('default') - allow(MiqServer).to receive(:my_server).and_return(@miq_server) + EvmSpecHelper.create_guid_miq_server_zone clear_domain end @@ -34,6 +32,15 @@ def perpetual_retry_script RUBY end + alias_method :retry_script, :perpetual_retry_script + + def retry_server_affinity_script + <<-'RUBY' + $evm.root['ae_result'] = 'retry' + $evm.root['ae_retry_server_affinity'] = true + RUBY + end + def perpetual_restart_script_with_nextstate <<-'RUBY' $evm.root['ae_result'] = 'restart' @@ -238,4 +245,26 @@ def create_restart_model(script1, script2, script3) q = MiqQueue.where(:state => 'ready').first expect(q.args[0][:state]).to eql('state2') end + + it "retry with server affinity set" do + setup_model(retry_server_affinity_script) + send_ae_request_via_queue(@automate_args) + status, _message, ws = deliver_ae_request_from_queue + expect(status).not_to eq(MiqQueue::STATUS_ERROR) + expect(ws).not_to be_nil + expect(MiqQueue.count).to eq(2) + q = MiqQueue.where(:state => 'ready').first + expect(q[:server_guid]).to eql(MiqServer.my_guid) + end + + it "retry without server affinity set" do + setup_model(retry_script) + send_ae_request_via_queue(@automate_args) + status, _message, ws = deliver_ae_request_from_queue + expect(status).not_to eq(MiqQueue::STATUS_ERROR) + expect(ws).not_to be_nil + expect(MiqQueue.count).to eq(2) + q = MiqQueue.where(:state => 'ready').first + expect(q[:server_guid]).to be_nil + end end From d2a118ea4fe2497ac3f51f7d1bf19da0726280d0 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Tue, 17 Jan 2017 12:50:18 -0500 Subject: [PATCH 2/2] Fixed Rubocop warning --- .../unit/engine_validation/miq_ae_state_machine_retry_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb b/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb index 6bde8b6c58f..0cc58a31f58 100644 --- a/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb +++ b/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb @@ -256,7 +256,7 @@ def create_restart_model(script1, script2, script3) q = MiqQueue.where(:state => 'ready').first expect(q[:server_guid]).to eql(MiqServer.my_guid) end - + it "retry without server affinity set" do setup_model(retry_script) send_ae_request_via_queue(@automate_args)