Skip to content

Commit

Permalink
Merge pull request #13543 from mkanoor/pr_13363_for_euwe
Browse files Browse the repository at this point in the history
[EUWE] Automate Retry with Server Affinity
  • Loading branch information
simaishi authored Jan 17, 2017
2 parents 3d2204b + d2a118e commit c9f1f7a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/miq_automation_engine/engine/miq_ae_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']}"
Expand Down
1 change: 1 addition & 0 deletions lib/miq_automation_engine/engine/miq_ae_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
@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,
:user_id => @user.id,
: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

Expand All @@ -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'
Expand Down Expand Up @@ -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

0 comments on commit c9f1f7a

Please sign in to comment.