[Solved] Switch provision auto approval to denied on error


#1

Hi All,

I have been trying to find a way to change the Request State for an auto approval service catalog request to denied, when one of the custom approval checks “errors”. The statemachine is / Service / Provisioning / StateMachines / ServiceProvisionRequestApproval, which has an custom update_serviceprovisionrequest_status method. This method updates the Last Message, with relevant “failure/error” info, eg the AD group membership check failed, but the request’s Request State remains Pending. I just want to switch that to Denied too.

I was thinking I would just add [$evm.root[‘miq_request’].denied] to update_serviceprovisionrequest_status’s error handling [if $evm.root[‘ae_result’] == “error”], so it updated Last Message and Request State. But it turns out its not quite that simple, tracing logs and trying to trace what happens when clicking the Deny button hasn’t been possible to give me a way to handle this.

Thanks


#2

I think the method you need is ‘deny’ rather than ‘denied’:

pemcg


#3

Hey @pemcg, thanks

not authorised…?

miq_request = $evm.root[‘miq_request’]

if $evm.root[‘ae_result’] == "error"
evm_owner_id = $evm.root[‘user_id’]. #requester
miq_request.deny(evm_owner_id,status)
$evm.create_notification(:level => “error”, :subject => $evm.root[‘miq_request’],
:message => “Service Provison Request Error: #{updated_message}”)
exit MIQ_ABORT
end

[----] E, [2017-10-23T17:46:27.142370 #2998:6a1828] ERROR – : MiqAeServiceModelBase.ar_method raised: :
[----] E, [2017-10-23T17:46:27.142536 #2998:6a1828] ERROR – : /var/www/miq/vmdb/app/models/miq_approval.rb:63:in user_validate' /var/www/miq/vmdb/app/models/miq_approval.rb:28:indeny’
/var/www/miq/vmdb/app/models/miq_request.rb:86:in deny' /var/www/miq/vmdb/app/models/mixins/inter_region_api_method_relay.rb:23:inblock (2 levels) in api_relay_method’
/var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:270:in public_send' /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:270:inblock in object_send’
/var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:289:in ar_method' /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:299:inar_method’
/var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:268:in object_send' /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:123:inblock (2 levels) in expose’
/opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:in perform_without_block' /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:inperform’
/opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:in block (2 levels) in main_loop' /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:inloop’
/opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in block in main_loop' [----] E, [2017-10-23T17:46:27.146898 #2998:3ff2d34] ERROR -- : <AEMethod update_serviceprovisionrequest_status> The following error occurred during method evaluation: [----] E, [2017-10-23T17:46:27.147951 #2998:3ff2d34] ERROR -- : <AEMethod update_serviceprovisionrequest_status> RuntimeError: not authorized [----] E, [2017-10-23T17:46:27.150238 #2998:3ff2d34] ERROR -- : <AEMethod update_serviceprovisionrequest_status> (druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/miq_approval.rb:63:inuser_validate’
(druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/miq_approval.rb:28:in deny' (druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/miq_request.rb:86:indeny’
(druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/mixins/inter_region_api_method_relay.rb:23:in block (2 levels) in api_relay_method' (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:270:inpublic_send’
(druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:270:in block in object_send' (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:289:inar_method’
(druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:299:in ar_method' (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:268:inobject_send’
(druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:123:in block (2 levels) in expose' (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:inperform_without_block’
(druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:in perform' (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:inblock (2 levels) in main_loop’
(druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in loop' (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:inblock in main_loop’
[----] E, [2017-10-23T17:46:27.158701 #2998:3ff2d34] ERROR – : Method STDERR: (druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/miq_approval.rb:63:in user_validate': not authorized (RuntimeError) [----] E, [2017-10-23T17:46:27.159726 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/miq_approval.rb:28:indeny’
[----] E, [2017-10-23T17:46:27.160826 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/miq_request.rb:86:in deny' [----] E, [2017-10-23T17:46:27.161852 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/app/models/mixins/inter_region_api_method_relay.rb:23:inblock (2 levels) in api_relay_method’
[----] E, [2017-10-23T17:46:27.162909 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:270:in public_send' [----] E, [2017-10-23T17:46:27.163951 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:270:inblock in object_send’
[----] E, [2017-10-23T17:46:27.164961 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:289:in ar_method' [----] E, [2017-10-23T17:46:27.165969 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:299:inar_method’
[----] E, [2017-10-23T17:46:27.166964 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:268:in object_send' [----] E, [2017-10-23T17:46:27.168106 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:123:inblock (2 levels) in expose’
[----] E, [2017-10-23T17:46:27.169109 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:in perform_without_block' [----] E, [2017-10-23T17:46:27.170118 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:inperform’
[----] E, [2017-10-23T17:46:27.171191 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:in block (2 levels) in main_loop' [----] E, [2017-10-23T17:46:27.172201 #2998:3ff2d34] ERROR -- : Method STDERR: from (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:inloop’
[----] E, [2017-10-23T17:46:27.173359 #2998:3ff2d34] ERROR – : Method STDERR: from (druby://127.0.0.1:39164) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in block in main_loop' [----] E, [2017-10-23T17:46:27.174402 #2998:3ff2d34] ERROR -- : Method STDERR: from <code: miq_request.deny(evm_owner_id,status)>:41:in'
[----] I, [2017-10-23T17:46:27.200773 #2998:69b130] INFO – : <AEMethod [/CPA/Service/Provisioning/StateMachines/ServiceProvisionRequestApproval/update_serviceprovisionrequest_status]> Ending
[----] E, [2017-10-23T17:46:27.201335 #2998:69b130] ERROR – : State= running on_error raised exception: <Method exited with rc=Unknown RC: [1]>


#4

Unless your requesting user has one of the admin roles, they won’t be able to approve or deny their own request.

pemcg


#5

@pemcg, sorted thanks! miq_request.deny(“admin”,status) works a treat.