Bug 1215990

Summary: [RFE] Allow the on_entry and on_error methods of a state machine to be able to advance (bump) state to allow processing to continue
Product: Red Hat CloudForms Management Engine Reporter: Peter McGowan <pmcgowan>
Component: AutomateAssignee: mkanoor
Status: CLOSED ERRATA QA Contact: Milan Falešník <mfalesni>
Severity: medium Docs Contact:
Priority: medium    
Version: 5.3.0CC: dajohnso, jhardy, mfeifer, mkanoor, obarenbo, snansi, tfitzger
Target Milestone: GAKeywords: FutureFeature
Target Release: 5.5.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: 5.5.0.1 Doc Type: Enhancement
Doc Text:
The new version of CloudForms Management Engine enhances the Automate engine to allow the on_entry and on_error methods of a state machine to advance to the next state under valid conditions. For on_entry methods, it checks if the method is required to run. For on_error methods, it handles and recovers from errors.
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-12-08 13:06:21 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Peter McGowan 2015-04-28 10:15:36 UTC
Description of problem:

It would be useful for the on_entry and on_error methods in a state machine to be able to advance the ae_state of the state machine. 

For an on_entry method, this would be useful if the method checked pre-conditions for the running of the main state method, and determined that the method was not required to run. (e.g. if a VM is already powered off, don't run the shutdown_vm main method)

For the on_error method, it would be useful to be able to handle and recover from an error, and continue the state machine processing. (e.g. if vm.shutdown_guest times out because the guest agent isn't installed, perform a vm.stop and continue the state machine)

Comment 2 Oleg Barenboim 2015-05-06 19:31:07 UTC
https://github.com/ManageIQ/manageiq/pull/2860

Comment 3 CFME Bot 2015-06-26 17:31:27 UTC
New commit detected on manageiq/master:
https://github.com/ManageIQ/manageiq/commit/7d2bf40a3753547d026af62a955a58dec2686672

commit 7d2bf40a3753547d026af62a955a58dec2686672
Author:     Madhu Kanoor <mkanoor>
AuthorDate: Fri Jun 19 15:54:14 2015 -0400
Commit:     Madhu Kanoor <mkanoor>
CommitDate: Fri Jun 26 09:53:06 2015 -0400

    Refactoring of Automate Engine code
    
    Separated State Machine specific code into a separate module
    Moved the state machine spec into engine_validation directory
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1215990

 .../miq_automation_engine/engine/miq_ae_object.rb  | 123 +-------------------
 .../engine/miq_ae_state_machine.rb                 | 124 +++++++++++++++++++++
 .../miq_ae_state_machine_retry_spec.rb             | 105 +++++++++++++++++
 .../miq_ae_state_machine_retry_spec.rb             | 105 -----------------
 4 files changed, 231 insertions(+), 226 deletions(-)
 create mode 100644 vmdb/lib/miq_automation_engine/engine/miq_ae_state_machine.rb
 create mode 100644 vmdb/spec/automation/unit/engine_validation/miq_ae_state_machine_retry_spec.rb
 delete mode 100644 vmdb/spec/lib/miq_automation_engine/miq_ae_state_machine_retry_spec.rb

Comment 4 CFME Bot 2015-06-26 17:31:33 UTC
New commit detected on manageiq/master:
https://github.com/ManageIQ/manageiq/commit/8afedec1ae688f6de9e88bde88f0d25fa29acd2b

commit 8afedec1ae688f6de9e88bde88f0d25fa29acd2b
Author:     Madhu Kanoor <mkanoor>
AuthorDate: Mon Jun 22 11:37:23 2015 -0400
Commit:     Madhu Kanoor <mkanoor>
CommitDate: Fri Jun 26 09:53:30 2015 -0400

    Automate State Machine enhancements
    
        (1) Optionally allow for methods to set the next state to execute
            using a new attribute in the root object called 'ae_next_state'
            e.g. $evm.root['ae_next_state'] = state_name
        (2) Allow for a state to be skipped by setting the method result
            attribute 'ae_result' to be skip in the root object.
            e.g. $evm.root['ae_result'] = 'skip'
            The next state in the instance is used when you use skip. You
            dont have to know the state name like with
            $evm.root['ae_next_state']
        (3) Allow for continuation of a state machine in case of errors
            by setting the method result attribute 'ae_result' to continue
            int the root object.
            e.g. $evm.root['ae_result'] = 'continue'
    
        https://bugzilla.redhat.com/show_bug.cgi?id=1215990

 .../engine/miq_ae_state_machine.rb                 |  55 +++-
 .../miq_ae_state_machine_retry_spec.rb             |  97 +++++--
 .../miq_ae_state_machine_steps_spec.rb             | 311 +++++++++++++++++++++
 vmdb/spec/support/automation_spec_helper.rb        |  15 +
 4 files changed, 438 insertions(+), 40 deletions(-)
 create mode 100644 vmdb/spec/automation/unit/engine_validation/miq_ae_state_machine_steps_spec.rb

Comment 5 CFME Bot 2015-06-26 17:31:38 UTC
New commit detected on manageiq/master:
https://github.com/ManageIQ/manageiq/commit/ddcbfcbb260fb88c610eaee94cc1d2e2d6c12fe4

commit ddcbfcbb260fb88c610eaee94cc1d2e2d6c12fe4
Author:     Madhu Kanoor <mkanoor>
AuthorDate: Tue Jun 23 16:16:58 2015 -0400
Commit:     Madhu Kanoor <mkanoor>
CommitDate: Fri Jun 26 09:53:50 2015 -0400

    PR review changes
    
    Use Timecop in spec
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1215990

 .../engine/miq_ae_state_machine.rb                   |  9 +++++----
 .../miq_ae_state_machine_retry_spec.rb               | 20 ++++++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)

Comment 6 Milan Falešník 2015-12-03 09:36:21 UTC
Verified in 5.5.0.13. I will include the exported AE things I used.

Comment 9 errata-xmlrpc 2015-12-08 13:06:21 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2015:2551