Set State Varibales in Rails console

#1

Hi everybody,
I am currently working on a helper script regarding state variables and thought it might be useful for other folks, too
The Code currently lives here:

Problem
The main problem with state vars is, that they are not stored on the request or task object, making it not obvious how to manipulate them while the task is running. If a bug caused the automate code to mess up it’s state variables, we have to manually edit the code in prod and try to fix them.

Script
The script basically allows you to do a $evm.set_state_var() and $evm.get_state_var() for any given Q-Task_id (e.g. r1234_automation_task_1234), along with some minor improvements.

  • The script directly edits the MiqQueue object in the database and could break the automation task if the code is buggy, though it should only edit the state vars.
  • The script need to run in the rails context on the appliance using /var/www/miq/vmdb/bin/rails runner /path/to/script

CLI Reference
TASK_ID refers to the Q-Task_id shown in the automate logs, if there are more than one instantiations with the same Q-Task_id, you can use the show-command to figure out the index of the correct one

$ /var/www/miq/vmdb/bin/rails runner aio.rb help
** CFME 5.10.1.2, codename: Hammer
Commands:
    aio.rb help [COMMAND]                      # Describe available commands or one specific com...
    aio.rb list                                # List currently active requests
    aio.rb set TASK_ID KEY JSON_VALUE          # Set (Overwrite) a state variable
    aio.rb show TASK_ID [all][STATE_VAR, ...]  # Show Information about a given Task (e.g. r1234...

Options:
  [--index=N]  # Select the correct StateMachine id there are multiple with the same TASK_ID
               # Default: 0

The show-command prints only the names of the state variables by default, as the value might be a huge dump of data. You need to specify which state_vars you want to see or use “all” to get everything

The set-command sets (and overwrites) a state variable. The value string is parsed as JSON and allows to set complex state variables