diff --git a/app/models/service_ansible_playbook.rb b/app/models/service_ansible_playbook.rb index c82059d6122..d20f594ef4d 100644 --- a/app/models/service_ansible_playbook.rb +++ b/app/models/service_ansible_playbook.rb @@ -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) diff --git a/app/models/service_generic.rb b/app/models/service_generic.rb index 3d203611b35..5749bf10d67 100644 --- a/app/models/service_generic.rb +++ b/app/models/service_generic.rb @@ -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 diff --git a/lib/miq_automation_engine/service_models/miq_ae_service_service_generic.rb b/lib/miq_automation_engine/service_models/miq_ae_service_service_generic.rb index c789b033597..003b2eeb3ae 100644 --- a/lib/miq_automation_engine/service_models/miq_ae_service_service_generic.rb +++ b/lib/miq_automation_engine/service_models/miq_ae_service_service_generic.rb @@ -6,5 +6,6 @@ class MiqAeServiceServiceGeneric < MiqAeServiceService expose :refresh expose :check_refreshed expose :postprocess + expose :on_error end end diff --git a/spec/models/service_ansible_playbook_spec.rb b/spec/models/service_ansible_playbook_spec.rb index c6330c3b23d..e7faa647074 100644 --- a/spec/models/service_ansible_playbook_spec.rb +++ b/spec/models/service_ansible_playbook_spec.rb @@ -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) }