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

[EUWE] Automate Retry with Server Affinity #13543

Merged
merged 2 commits into from
Jan 17, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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