Skip to content

Commit

Permalink
Merge pull request #14583 from tinaafitz/service_on_error
Browse files Browse the repository at this point in the history
Ansible Playbook Service add on_error method.
(cherry picked from commit d7f9fe0)
  • Loading branch information
gmcculloug authored and simaishi committed Apr 4, 2017
1 parent 25708ed commit d371a69
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/service_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def postprocess(action)
delete_inventory(action) unless use_default_inventory?(hosts)
end

def on_error(action)
_log.info("on_error called for service action: #{action}")
update_attributes(:retirement_state => 'error') if action == "Retirement"
postprocess(action)
end

private

def manageiq_extra_vars(action)
Expand Down
3 changes: 3 additions & 0 deletions app/models/service_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ def check_refreshed(_action)
# Execute after refresh is done. Do cleaning up or update linkage here
def postprocess(_action)
end

def on_error(_action)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ class MiqAeServiceServiceGeneric < MiqAeServiceService
expose :refresh
expose :check_refreshed
expose :postprocess
expose :on_error
end
end
15 changes: 15 additions & 0 deletions spec/models/service_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@
end
end

describe '#on_error' do
it 'handles retirement error' do
executed_service.update_attributes(:retirement_state => 'Retiring')
expect(executed_service).to receive(:postprocess)
executed_service.on_error(ResourceAction::RETIREMENT)
expect(executed_service.retirement_state).to eq('error')
end

it 'handles provisioning error' do
expect(executed_service).to receive(:postprocess)
executed_service.on_error(action)
expect(executed_service.retirement_state).to be_nil
end
end

describe '#job' do
before { service.add_resource!(tower_job, :name => action) }

Expand Down

0 comments on commit d371a69

Please sign in to comment.