Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1353966 - RFE - During substitution you can't call methods that take arguments
Summary: RFE - During substitution you can't call methods that take arguments
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Automate
Version: 5.5.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: GA
: 5.7.0
Assignee: mkanoor
QA Contact: Shveta
URL:
Whiteboard:
Depends On:
Blocks: 1372770
TreeView+ depends on / blocked
 
Reported: 2016-07-08 14:38 UTC by mkanoor
Modified: 2017-01-04 12:57 UTC (History)
8 users (show)

Fixed In Version: 5.7.0.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1372770 (view as bug list)
Environment:
Last Closed: 2017-01-04 12:57:05 UTC
Category: ---
Cloudforms Team: CFME Core


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:0012 normal SHIPPED_LIVE CFME 5.7.0 bug fixes and enhancement update 2017-01-04 17:50:36 UTC

Description mkanoor 2016-07-08 14:38:58 UTC
Description of problem:
When we call automate substitution we can only call methods that don't take any arguments. If you call a method that takes arguments, the substitution fails.


Version-Release number of selected component (if applicable):
5.5.6

How reproducible:
100%

Steps to Reproduce:
1. During provisioning, have the automate model that gets the requesters email
2. my_email = ${/#miq_request.get_option(:email)}
3. Make sure that you have the requesters email properly filled in

Actual results:
the get_option call fails

Expected results:
my_email should have the valid email address from the request


Additional info:

Comment 6 mkanoor 2016-10-03 19:59:17 UTC
${/#miq_request.get_option(:owner_email)}

Is this being tested with the miq_request object passed into Automation Request.
Also is the owner_email present in the request options hash.

Can you provide the automation log after the test is run.

Comment 7 Shveta 2016-11-08 03:40:25 UTC
Gave value for owner_email in below method

def requester_email_address
  owner_email = "sshveta@redhat.com"
  email = requester.email || owner_email || $evm.object['to_email_address']
  $evm.log(:info, "To email: #{email}")
  email
end
 

Got email.

Please check if this verification is good .

Comment 8 mkanoor 2016-11-08 14:55:36 UTC
Where is the substitution happening, is it defined in the model.
Also instead of using the || you should be just using the attribute that stores the substituted value.

e.g.

Say the requesters email address is requester@example.com

Change class schema to add a variable called test_email and also a method like check_method that you can call to check

test_email = ${/#miq_request.get_option(:email)}

check_method = /SomeNamespace/SomeClass/SomeInstance/SomeMethod

in the SomeMethod script you would put something like this


if $evm.object['test_email'] == 'requester@example.com'
  $evm.log(:info, "Test passed")
else
  raise "email test failed"
end

Comment 9 mkanoor 2016-11-09 22:22:20 UTC
I don't think the request option has :email key instead its called :owner_email.

So in the above script the substitution should look like

test_email = ${/#miq_request.get_option(:owner_email)}

Comment 10 Shveta 2016-11-15 20:01:22 UTC
Getting this in logs :
-===========================
[----] I, [2016-11-15T15:04:15.338977 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Following Relationship [miqaedb:/test/test/test#create]
[----] I, [2016-11-15T15:04:15.390099 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Updated namespace [miqaedb:/test/test/test#create  mfdomain/test]
[----] W, [2016-11-15T15:04:15.417890 #2769:5cb14c]  WARN -- : Q-task_id([miq_provision_7]) Error during substitution: undefined method `get_option' for nil:NilClass
[----] I, [2016-11-15T15:04:15.445892 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Updated namespace [test/test/print_value  mfdomain/test]
[----] I, [2016-11-15T15:04:15.457056 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Invoking [inline] method [/mfdomain/test/test/print_value] with inputs [{}]
[----] I, [2016-11-15T15:04:15.458583 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) <AEMethod [/mfdomain/test/test/print_value]> Starting 
[----] I, [2016-11-15T15:04:16.195202 #2769:4f72b24]  INFO -- : Q-task_id([miq_provision_7]) <AEMethod print_value> TESTTEST 
[----] I, [2016-11-15T15:04:16.227358 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) <AEMethod [/mfdomain/test/test/print_value]> Ending
[----] I, [2016-11-15T15:04:16.227588 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Method exited with rc=MIQ_OK
[----] I, [2016-11-15T15:04:16.229449 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Followed  Relationship [miqaedb:/test/test/test#create]
[----] I, [2016-11-15T15:04:16.229668 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Processed  State=[RegisterAD] with Result=[ok]
[----] I, [2016-11-15T15:04:16.229864 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Processed State =[RegisterAD]
[----] I, [2016-11-15T15:04:16.230194 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) In State=[RegisterAD], invoking [on_exit] method=[update_provision_status(status => 'Registered ActiveDirectory')]
[----] I, [2016-11-15T15:04:16.708983 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Updated namespace [Infrastructure/VM/Provisioning/StateMachines/VMProvision_vm/update_provision_status  ManageIQ/Infrastructure/VM/Provisioning/StateMachines]
[----] I, [2016-11-15T15:04:16.815388 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Invoking [inline] method [/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/VMProvision_VM/update_provision_status] with inputs [{"status"=>"Registered ActiveDirectory"}]
[----] I, [2016-11-15T15:04:16.816372 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) <AEMethod [/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/VMProvision_VM/update_provision_status]> Starting 
[----] I, [2016-11-15T15:04:18.068246 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) <AEMethod [/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/VMProvision_VM/update_provision_status]> Ending
[----] I, [2016-11-15T15:04:18.068408 #2769:5cb14c]  INFO -- : Q-task_id([miq_provision_7]) Method exited with rc=MIQ_OK

Comment 11 Shveta 2016-11-15 20:01:43 UTC
Please check appliance : https://10.8.199.47

Comment 12 mkanoor 2016-11-15 20:24:35 UTC
Hi,
How are you starting the Automation Request, is there an miq_request object being passed into Automate. It seems like there isn't an miq_request object in the workspace.

Comment 13 mkanoor 2016-11-18 19:04:57 UTC
Hello,
I tested this on your environment

I needed to make the following changes
(1) The logged in user didn't have an email address so I had to set it to a@b.com
(2) During the substitution we should be using miq_provision instead of miq_request
${/#miq_provision.get_option(:owner_email)}

With these 2 changes, I was able to run your test

<AEMethod print_value> TESTTEST a@b.com

[----] I, [2016-11-18T13:56:15.327123 #2795:11cd134]  INFO -- : Q-task_id([miq_provision_19]) Invoking [inline] method [/mfdomain/test/test/print_value] with inputs [{}]

[----] I, [2016-11-18T13:56:15.327822 #2795:11cd134]  INFO -- : Q-task_id([miq_provision_19]) <AEMethod [/mfdomain/test/test/print_value]> Starting

[----] I, [2016-11-18T13:56:15.975260 #2795:553fa20]  INFO -- : Q-task_id([miq_provision_19]) <AEMethod print_value> TESTTEST a@b.com

[----] I, [2016-11-18T13:56:15.997660 #2795:11cd134]  INFO -- : Q-task_id([miq_provision_19]) <AEMethod [/mfdomain/test/test/print_value]> Ending

Thanks,
Madhu

Comment 14 Shveta 2016-11-19 03:52:00 UTC
Verifying based on above comment.

5.7.0.11-rc1.20161115160629_46cf4f1

Comment 16 errata-xmlrpc 2017-01-04 12:57:05 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://rhn.redhat.com/errata/RHBA-2017-0012.html


Note You need to log in before you can comment on or make changes to this bug.