State Machine processing question

Hi,

I am trying to insert a state into the retirement statemachine and i want it to retry that state until it passes and then continue with the retirement process but it seems that the whole state machine gets processed and then that state retries until i either ok or error the state. How do i get the state to stop processing until that state is done? I have tried many different things with the state machine but i can’t figure out how to hold up the process in a retry loop.

The state machine will pause for the duration that you specify with the ae_retry_interval value, and then your retrying state should be run again. It’s up to this state to determine whether to continue issuing retries, or to continue, for example:

case some_test_condition
when "pending", "active"
  $evm.log(:info, "Request still active, waiting for 15 seconds...")
  $evm.root['ae_retry_interval'] = '15.seconds'
  $evm.root['ae_result']         = 'retry'
when "finished"
  $evm.log(:info, "Request complete!")
  $evm.root['ae_result'] = 'ok'
else
  $evm.log(:info, "Not sure what happened")
  $evm.root['ae_result'] = 'error'
end

pemcg

Hi @pemcg,

Thanks for the reply. So I have that code in my method and the ae_result does get set to retry. but the state goes to on exit and proceeds to the next state.so i see these messages in the log.

Processed State=[CheckProceed] with Result=[retry]
In State=[CheckProceed], invoking [on_exit] method=[update_service_retirement_status(status => ‘Started Retirement’,status_state => ‘on_exit’)]

I want it to retry the CheckProceed state until it has a Result=[ok]

I currently have the method i am running in the value field and then i have a check on entry just like the service retire default statemachine. is there something i’m missing on my statemachine.

Thanks,

on_entry and on_exit (or or_error) are still methods that each state’s processing will go through. Even if the main method has issued a retry, that state’s on_exit method will still be run. The next state in the state machine shouldn’t be run however.

pemcg

Hi @pemcg,

Ok so then maybe i’m not following the service retirement process correctly. So i have my retire entry point set to the default and i want to keep my retire in a pending state while i run some checks and only allow it to proceed if it passes my checks. I thought i should be able to do this in the ServiceRetirementRequestApproval state machine but even if i set that state to deny it still processes my retire. so i thought i could add a state to the default service retire state at the start which would do my check even though at this point the service retire is in an active state i don’t want it to start deleting the vm’s until i pass my check so i added the above CheckProceed state and i do see that state retry but the vm retires have already started. I also see my retire request get instantly approved before it even gets to the ServiceRetirementRequestApproval state machine and i can’t find anywhere what is approving that request. I am guessing there is alot of backend processes happening that are not visible from the manageiq domain. Can you let me know where i’m going wrong as i am having a real hard time following all the processes that happen during a service retire.

Thanks,

I believe that there are some subtleties in the retirement request process around things like retirement date, but I haven’t studied it closely. @tinaafitz wrote a great article describing the process here, she may be able to shed some more light on your problem.

Is the service a ‘traditional’ VM provisioning service or an (embedded or Tower) Ansible service?

pemcg

Hi @pemcg and @tinaafitz,

I have read Tina’s article and that is where I though modifying the ServiceRetirementRequestApproval would accomplish what i wanted to do but it didn’t work as i was expecting. here is what i see in my log when i start a service retire. You can see that the vm_retire_task gets initiated right after the ServiceRetireRequest_starting instance finishes and i don’t see it start my service retirement state machine for a few seconds.

MiqAeEvent.build_evm_event >> event=<“request_created”> inputs=<{“EventStream::event_stream”=>12000000311376, :event_stream_id=>12000000311376}>
MiqAeEvent.build_evm_event >> event=<“request_approved”> inputs=<{“EventStream::event_stream”=>12000000311377, :event_stream_id=>12000000311377}>
Q-task_id([r12000000002625_service_retire_request_12000000002625]) MiqAeEvent.build_evm_event >> event=<“request_starting”> inputs=<{“EventStream::event_stream”=>12000000311378, :event_stream_id=>12000000311378}>
Q-task_id([r12000000002625_service_retire_request_12000000002625]) User [---------] with current group ID [12000000000021] name [-------]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Instantiating [/System/Process/Event?EventStream%3A%3Aevent_stream=12000000311378&MiqRequest%3A%3Amiq_request=12000000002625&MiqServer%3A%3Amiq_server=12000000000001&ServiceRetireRequest%3A%3Aservice_retire_request=12000000002625&User%3A%3Auser=12000000000004&event_stream_id=12000000311378&event_type=request_starting&object_name=Event&vmdb_object_type=service_retire_request]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [/System/Process/Event?EventStream%3A%3Aevent_stream=12000000311378&MiqRequest%3A%3Amiq_request=12000000002625&MiqServer%3A%3Amiq_server=12000000000001&ServiceRetireRequest%3A%3Aservice_retire_request=12000000002625&User%3A%3Auser=12000000000004&event_stream_id=12000000311378&event_type=request_starting&object_name=Event&vmdb_object_type=service_retire_request ManageIQ/System]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Following Relationship [miqaedb:/System/Event/RequestEvent/Request/request_starting#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [miqaedb:/System/Event/RequestEvent/Request/request_starting#create ManageIQ/System/Event/RequestEvent]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Following Relationship [miqaedb:/System/Policy/request_starting#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [miqaedb:/System/Policy/request_starting#create Broadcom/System]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [System/Policy/get_request_type ManageIQ/System]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Invoking [inline] method [/ManageIQ/System/Policy/get_request_type] with inputs [{}]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) <AEMethod [/ManageIQ/System/Policy/get_request_type]> Starting
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Request Type:
Q-task_id([r12000000002625_service_retire_request_12000000002625]) <AEMethod [/ManageIQ/System/Policy/get_request_type]> Ending
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Method exited with rc=MIQ_OK
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Following Relationship [miqaedb:/System/Process/parse_provider_category#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [miqaedb:/System/Process/parse_provider_category#create ManageIQ/System]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [System/Process/parse_provider_category ManageIQ/System]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Invoking [builtin] method [/ManageIQ/System/Process/parse_provider_category] with inputs [{}]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Setting provider_category to:
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Followed Relationship [miqaedb:/System/Process/parse_provider_category#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Following Relationship [miqaedb:/System/Policy/ServiceRetireRequest_starting#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Updated namespace [miqaedb:/System/Policy/ServiceRetireRequest_starting#create ManageIQ/System]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Instance [/ManageIQ/System/Policy/ServiceRetireRequest_starting] not found in MiqAeDatastore - trying [.missing]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Followed Relationship [miqaedb:/System/Policy/ServiceRetireRequest_starting#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Followed Relationship [miqaedb:/System/Policy/request_starting#create]
Q-task_id([r12000000002625_service_retire_request_12000000002625]) Followed Relationship [miqaedb:/System/Event/RequestEvent/Request/request_starting#create]
User [-----------] with current group ID [12000000000021] name [-----------]
User [-----------] with current group ID [12000000000021] name [-----------]
Instantiating [/System/Process/Event?EventStream%3A%3Aevent_stream=12000000311377&MiqRequest%3A%3Amiq_request=12000000002625&MiqServer%3A%3Amiq_server=12000000000001&ServiceRetireRequest%3A%3Aservice_retire_request=12000000002625&User%3A%3Auser=12000000000004&event_stream_id=12000000311377&event_type=request_approved&object_name=Event&vmdb_object_type=service_retire_request]
Updated namespace [/System/Process/Event?EventStream%3A%3Aevent_stream=12000000311377&MiqRequest%3A%3Amiq_request=12000000002625&MiqServer%3A%3Amiq_server=12000000000001&ServiceRetireRequest%3A%3Aservice_retire_request=12000000002625&User%3A%3Auser=12000000000004&event_stream_id=12000000311377&event_type=request_approved&object_name=Event&vmdb_object_type=service_retire_request ManageIQ/System]
Instantiating [/System/Process/Event?EventStream%3A%3Aevent_stream=12000000311376&MiqRequest%3A%3Amiq_request=12000000002625&MiqServer%3A%3Amiq_server=12000000000001&ServiceRetireRequest%3A%3Aservice_retire_request=12000000002625&User%3A%3Auser=12000000000004&event_stream_id=12000000311376&event_type=request_created&object_name=Event&vmdb_object_type=service_retire_request]
Following Relationship [miqaedb:/System/Event/RequestEvent/Request/request_approved#create]
Updated namespace [miqaedb:/System/Event/RequestEvent/Request/request_approved#create ManageIQ/System/Event/RequestEvent]
Following Relationship [miqaedb:/System/Policy/request_approved#create]
Updated namespace [miqaedb:/System/Policy/request_approved#create ManageIQ/System]
Updated namespace [/System/Process/Event?EventStream%3A%3Aevent_stream=12000000311376&MiqRequest%3A%3Amiq_request=12000000002625&MiqServer%3A%3Amiq_server=12000000000001&ServiceRetireRequest%3A%3Aservice_retire_request=12000000002625&User%3A%3Auser=12000000000004&event_stream_id=12000000311376&event_type=request_created&object_name=Event&vmdb_object_type=service_retire_request ManageIQ/System]
Following Relationship [miqaedb:/System/Process/parse_provider_category#create]
Updated namespace [miqaedb:/System/Process/parse_provider_category#create ManageIQ/System]
Updated namespace [System/Process/parse_provider_category ManageIQ/System]
Invoking [builtin] method [/ManageIQ/System/Process/parse_provider_category] with inputs [{}]
Setting provider_category to:
Followed Relationship [miqaedb:/System/Process/parse_provider_category#create]
Following Relationship [miqaedb:/System/Policy/ServiceRetireRequest_Approved#create]
Updated namespace [miqaedb:/System/Policy/ServiceRetireRequest_Approved#create ManageIQ/System]
Instance [/ManageIQ/System/Policy/ServiceRetireRequest_Approved] not found in MiqAeDatastore - trying [.missing]
Followed Relationship [miqaedb:/System/Policy/ServiceRetireRequest_Approved#create]
Followed Relationship [miqaedb:/System/Policy/request_approved#create]
Followed Relationship [miqaedb:/System/Event/RequestEvent/Request/request_approved#create]
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) User [-----------] with current group ID [12000000000021] name [-----------]
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) Instantiating [/System/Process/AUTOMATION?MiqServer%3A%3Amiq_server=12000000000001&User%3A%3Auser=12000000000004&VmOrTemplate%3A%3Avm=12000000008073&VmRetireTask%3A%3Avm_retire_task=12000000004446&object_name=AUTOMATION&request=vm_retire&vmdb_object_type=vm_retire_task]
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) Updated namespace [/System/Process/AUTOMATION?MiqServer%3A%3Amiq_server=12000000000001&User%3A%3Auser=12000000000004&VmOrTemplate%3A%3Avm=12000000008073&VmRetireTask%3A%3Avm_retire_task=12000000004446&object_name=AUTOMATION&request=vm_retire&vmdb_object_type=vm_retire_task ManageIQ/System]
Following Relationship [miqaedb:/System/Event/RequestEvent/Request/request_created#create]
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) Updated namespace [System/Process/parse_provider_category ManageIQ/System]
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) Invoking [builtin] method [/ManageIQ/System/Process/parse_provider_category] with inputs [{}]
Updated namespace [miqaedb:/System/Event/RequestEvent/Request/request_created#create ManageIQ/System/Event/RequestEvent]
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) Setting provider_category to: cloud
Q-task_id([r12000000002625_vm_retire_task_12000000004446]) Setting prepend_namespace to: Openstack

Thanks @pemcg :slight_smile:

Hi @Opereira,

It looks like your request is getting approved.

The approval type is Auto in the OOTB default for the ServiceRetirementRequestApproval class.

If you don’t want the Service object to be retired, you need to modify the Service Retirement Approval state machine to:

  1. Copy the ManageIQ Domain ServiceRetirementRequestApproval class to a writable enabled domain.

  2. Change the “default” instance approval_type from auto to manual.

  3. Modify the method to deny the Request.

  4. Modify the Service object retire_on value.
    (Extend or remove the retires_on value)

I hope this helps. :slight_smile:

Hi @tinaafitz,

Thanks for the reply, I have done as specified but the request gets approved and starts processing before it even runs this state machine. By the time the Validate method runs the vm already started retirement. We are on hammer 7 by the way so not sure if that makes a difference. I even see these messages in the logs but the process still continues.

[----] I, [2020-10-21T13:51:34.518313 #12227:41362e0] INFO – : Checking for auto_approval
[----] I, [2020-10-21T13:51:34.519579 #12227:41362e0] INFO – : Not Auto-Approved
[----] I, [2020-10-21T13:51:34.545027 #12227:3aaf48] INFO – : <AEMethod [/Broadcom/Service/Retirement/StateMachines/ServiceRetirementRequestApproval/approve_request]> Ending
[----] E, [2020-10-21T13:51:34.545514 #12227:3aaf48] ERROR – : State= running on_entry raised exception:
[----] W, [2020-10-21T13:51:34.545615 #12227:3aaf48] WARN – : Error in State=[ApproveRequest]
[----] I, [2020-10-21T13:51:34.545735 #12227:3aaf48] INFO – : In State=[ApproveRequest], invoking [on_error] method=[pending_request]