Skip to content

Commit

Permalink
Increment the ae_state_retries when on_exit sets retry
Browse files Browse the repository at this point in the history
  • Loading branch information
mkanoor committed Jan 3, 2017
1 parent b27acf5 commit 098176a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/miq_automation_engine/engine/miq_ae_state_machine.rb
Expand Up @@ -96,8 +96,14 @@ def process_state(f, message, args)
end
end

state_in_retry = @workspace.root['ae_result'] == 'retry'
# Process on_exit method
process_state_step_with_error_handling(f, 'on_exit') { process_state_method(f, 'on_exit') }
process_state_step_with_error_handling(f, 'on_exit') do
process_state_method(f, 'on_exit')
if @workspace.root['ae_result'] == 'retry' and !state_in_retry
increment_state_retries
end
end
set_next_state(f, message)
end
end
Expand Down
Expand Up @@ -286,6 +286,30 @@ def update_value(instance, field, attribute, value)
expect(ws.root.attributes['step_on_error']).to be_nil
end

it "allow for retry to be set on on_exit method even if the state ends in retry" do
tweak_instance("/#{@domain}/#{@namespace}/#{@method_class}", @instance2,
'ae_result', 'value', "retry")
tweak_instance("/#{@domain}/#{@namespace}/#{@state_class}", @state_instance,
'state2', 'on_exit', "common_state_method(ae_result => 'retry')")
ws = MiqAeEngine.instantiate(@fqname, @user)
expect(ws.root.attributes['step_on_entry']).to match_array(%w(state1 state2))
expect(ws.root.attributes['states_executed']).to match_array([@instance1, @instance2])
expect(ws.root.attributes['step_on_exit']).to match_array(%w(state1 state2))
expect(ws.root.attributes['step_on_error']).to be_nil
expect(ws.root.attributes['ae_state_retries']).to eq(1)
end

it "allow for retry to be set on on_exit method" do
tweak_instance("/#{@domain}/#{@namespace}/#{@state_class}", @state_instance,
'state2', 'on_exit', "common_state_method(ae_result => 'retry')")
ws = MiqAeEngine.instantiate(@fqname, @user)
expect(ws.root.attributes['step_on_entry']).to match_array(%w(state1 state2))
expect(ws.root.attributes['states_executed']).to match_array([@instance1, @instance2])
expect(ws.root.attributes['step_on_exit']).to match_array(%w(state1 state2))
expect(ws.root.attributes['step_on_error']).to be_nil
expect(ws.root.attributes['ae_state_retries']).to eq(1)
end

it "non existent on_error method" do
# If the on_error is missing the whole state machine aborts
tweak_instance("/#{@domain}/#{@namespace}/#{@method_class}", @instance2,
Expand Down

0 comments on commit 098176a

Please sign in to comment.