Schema field "collect" doesn't expose the value


#1

Hi all,

From automate book I realize when I set collect in schema can expose variable , then other method can reach the variable.
In my understand when I set collect /vara = method_var, then use$evm.object['method_var'] = something
I can reach method_var use $evm.root['vara'], but in my automate it doesn’t work.

In my automate I create a generic service and launch a vm after vm create finished add vm to this service.

I want to get the miq_provision object to find the vm status and add to service, after I execute create_provision_request at pre2, it return provision vm miq_request, but I need to wait until provision task start then I can get the status, so I wait at pre3, but I cannot get the collect from pre2.

state machine schema

script in pre 2 :

#request provision vm 
...
request = $evm.execute('create_provision_request', *args)
$evm.object['vm_miq_request'] = request
...

script in pre3

# if task nil retry after 1 min
miq_request = $evm.root['vm_miq_request']
provision_task = miq_request.miq_request_tasks[0]

if provision_task.nil?
    $evm.root['ae_result'] = 'retry'
    $evm.root['ae_retry_interval'] = '1.minute'
  else
    $evm.root['ae_result'] = 'ok'
    $evm.object['provision'] = provision_task
end

please help me solve this problem.

Thanks


#2

After I try multiple time,
The collect variable expose first time but after retry the variable is gone, then error happened.

#first run
[----] I, [2017-09-08T18:08:11.344352 #14138:3fcec2c]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> 
[----] I, [2017-09-08T18:08:11.344969 #14138:3fcec2c]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> Begin $evm.object.attributes
[----] I, [2017-09-08T18:08:11.346256 #14138:3fcec2c]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> End $evm.object.attributes
[----] I, [2017-09-08T18:08:11.346705 #14138:3fcec2c]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> 
[----] I, [2017-09-08T18:08:11.347202 #14138:3fcec2c]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> pre3 start
[----] I, [2017-09-08T18:08:11.349033 #14138:3fcec2c]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> miq_request = #<MiqAeMethodService::MiqAeServiceMiqProvis
ionRequest:0x00000009a82060>
[----] I, [2017-09-08T18:08:11.373745 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod [/CustomProvider/Service/Provisioning/StateMachines/Methods/wait_for_miq_provision
]> Ending
[----] I, [2017-09-08T18:08:11.373830 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) Method exited with rc=MIQ_OK
[----] I, [2017-09-08T18:08:11.374393 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) Followed  Relationship [miqaedb:/Service/Provisioning/StateMachines/Methods/Wait_for_miq_pro
vision#create]
[----] I, [2017-09-08T18:08:11.374526 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) Processed  State=[pre3] with Result=[retry]
[----] I, [2017-09-08T18:08:11.374717 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) In State=[pre3], invoking [on_exit] method=[update_serviceprovision_status(status => ' expos
e miq_request')]
[----] I, [2017-09-08T18:08:11.378031 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) Updated namespace [Service/Provisioning/StateMachines/ServiceProvision_Template/update_servi
ceprovision_status  ManageIQ/Service/Provisioning/StateMachines]
[----] I, [2017-09-08T18:08:11.520602 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) Invoking [inline] method [/ManageIQ/Service/Provisioning/StateMachines/ServiceProvision_Temp
late/update_serviceprovision_status] with inputs [{"status"=>" expose miq_request"}]
[----] I, [2017-09-08T18:08:11.521345 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod [/ManageIQ/Service/Provisioning/StateMachines/ServiceProvision_Template/update_ser
viceprovision_status]> Starting 
[----] I, [2017-09-08T18:08:12.123236 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod [/ManageIQ/Service/Provisioning/StateMachines/ServiceProvision_Template/update_ser
viceprovision_status]> Ending
[----] I, [2017-09-08T18:08:12.123328 #14138:625138]  INFO -- : Q-task_id([service_template_provision_task_151]) Method exited with rc=MIQ_OK

#retry
[----] I, [2017-09-08T18:09:25.029363 #15304:4baffa0]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> 
[----] I, [2017-09-08T18:09:25.029967 #15304:4baffa0]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> pre3 start
[----] I, [2017-09-08T18:09:25.032605 #15304:4baffa0]  INFO -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> miq_request = 
[----] E, [2017-09-08T18:09:25.033246 #15304:4baffa0] ERROR -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision> The following error occurred during method evaluation:
[----] E, [2017-09-08T18:09:25.035272 #15304:4baffa0] ERROR -- : Q-task_id([service_template_provision_task_151]) <AEMethod wait_for_miq_provision>   NoMethodError: undefined method `miq_request_tasks' for nil:NilClass