Bug 1447793

Summary: The create_service_provision_request call on a service_template doesn't return a MiqRequest object
Product: Red Hat CloudForms Management Engine Reporter: mkanoor
Component: AutomateAssignee: mkanoor
Status: CLOSED CURRENTRELEASE QA Contact: Shveta <sshveta>
Severity: high Docs Contact:
Priority: high    
Version: 5.8.0CC: cpelland, dajohnso, gmccullo, jhardy, kmorey, mkanoor, obarenbo, simaishi, sshveta, tfitzger
Target Milestone: GAKeywords: TestOnly
Target Release: 5.9.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: service:provision
Fixed In Version: 5.9.0.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1448506 (view as bug list) Environment:
Last Closed: 2018-03-06 15:57:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: CFME Core Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1448506    

Description mkanoor 2017-05-03 20:29:24 UTC
Description of problem:
In 5.8 we had added a new method to a service template called create_service_provision_request which allows us to order a service_template. This method returns a Hash of error and MiqRequest, instead of just returning the MiqRequest 

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

How reproducible:
100%

Steps to Reproduce:
1. Create a Service Template (Catalog Item)
2. Order the service template from an Automate Method using
   # Get the Service Template Object
   service_template = $evm.vmdb('ServiceTemplate').where(:name => $evm.root['service_template_name']).first
   # Order the Service Template
   result = $evm.create_service_provision_request(service_template)
   $evm.log(:info, "The Request ID is #{result.id}")

Actual results:
   Method fails with an error because it gets back a hash instead of the request object


Expected results:
   The call should return the MiqRequest object and the above method should work without any errors.

Additional info:
   The use case here is that an automate method can order the service template and wait for the service provisioning to end in a state machine.

Comment 3 CFME Bot 2017-05-05 12:36:43 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/40fd359c3391213cb1b60dded29b2547a803eefa

commit 40fd359c3391213cb1b60dded29b2547a803eefa
Author:     Madhu Kanoor <mkanoor>
AuthorDate: Wed May 3 17:54:43 2017 -0400
Commit:     Madhu Kanoor <mkanoor>
CommitDate: Wed May 3 17:54:43 2017 -0400

    provision_request returns a miq_request object
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1447793
    
    If there are no errors we return the miq_request object
    else we raise an exception with the errors

 app/models/service_template.rb       |  4 +++-
 spec/models/service_template_spec.rb | 37 +++++++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 12 deletions(-)

Comment 5 Shveta 2017-11-01 05:33:43 UTC
I am getting error 
[----] I, [2017-11-01T01:24:16.909157 #13261:1add6d4]  INFO -- : <AEMethod [/new_domain/System/Request/InspectMe]> Starting 
[----] E, [2017-11-01T01:24:18.181081 #13261:4da0c9c] ERROR -- : <AEMethod inspectme> The following error occurred during method evaluation:
[----] E, [2017-11-01T01:24:18.181780 #13261:4da0c9c] ERROR -- : <AEMethod inspectme>   NoMethodError: undefined method `create_service_provision_request' for #<MiqAeMethodService::MiqAeService:0x0000000d8d7860>
[----] E, [2017-11-01T01:24:18.182682 #13261:4da0c9c] ERROR -- : <AEMethod inspectme>   (druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:in `perform_without_block'
(druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:in `perform'
(druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:in `block (2 levels) in main_loop'
(druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `loop'
(druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `block in main_loop'
[----] E, [2017-11-01T01:24:18.187189 #13261:4da0c9c] ERROR -- : Method STDERR: (druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:in `perform_without_block': undefined method `create_service_provision_request' for #<MiqAeMethodService::MiqAeService:0x0000000d8d7860> (NoMethodError)
[----] E, [2017-11-01T01:24:18.187798 #13261:4da0c9c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:in `perform'
[----] E, [2017-11-01T01:24:18.188300 #13261:4da0c9c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:in `block (2 levels) in main_loop'
[----] E, [2017-11-01T01:24:18.188939 #13261:4da0c9c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `loop'
[----] E, [2017-11-01T01:24:18.189503 #13261:4da0c9c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:45110) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `block in main_loop'
[----] E, [2017-11-01T01:24:18.190018 #13261:4da0c9c] ERROR -- : Method STDERR: 	from /new_domain/System/Request/InspectMe:4:in `<main>'
[----] I, [2017-11-01T01:24:18.224448 #13261:1add6d4]  INFO -- : <AEMethod [/new_domain/System/Request/InspectMe]> Ending
[----] E, [2017-11-01T01:24:18.225157 #13261:1add6d4] ERROR -- : Aborting instantiation (unknown method return code) because [Method exited with rc=Unknown RC: [1]]
[----] E, [2017-11-01T01:24:18



Has the method name changed?

Comment 6 mkanoor 2017-11-13 19:25:04 UTC
The method is still there except it has been moved under $evm.execute('create_service_provision_request', service_template, options)

by this PR

https://github.com/ManageIQ/manageiq-automation_engine/pull/34

and BZ https://bugzilla.redhat.com/show_bug.cgi?id=1457754

Please update your test script to do something like

https://github.com/ManageIQ/manageiq-content/blob/master/content/automate/ManageIQ/System/Request.class/__methods__/order_ansible_playbook.rb#L19

Comment 7 Dave Johnson 2017-11-15 14:57:33 UTC
Shveta, can you review comment 6

Comment 8 Shveta 2017-11-16 00:42:10 UTC
Hi Madhu , 

Can you please check the appliance once :https://10.8.198.177/
Service template name is azure_item and method is 
==========================================
/new_dialog/System/Request/InspectMe
=====================================
# Get the Service Template Object
   service_template = $evm.vmdb('ServiceTemplate').where(:name => $evm.root['azure_item']).first
   # Order the Service Template
   result = $evm.execute('create_service_provision_request', service_template)
   $evm.log(:info, "The Request ID is #{result.id}")





Logs show :
==========================
[----] I, [2017-11-15T19:37:19.383589 #13277:ca76f0]  INFO -- : Instantiating [/SYSTEM/PROCESS/Request?MiqServer%3A%3Amiq_server=2&User%3A%3Auser=1&message=create&object_name=Request&request=InspectMe#create]
[----] I, [2017-11-15T19:37:19.427863 #13277:ca76f0]  INFO -- : Updated namespace [/SYSTEM/PROCESS/Request?MiqServer%3A%3Amiq_server=2&User%3A%3Auser=1&message=create&object_name=Request&request=InspectMe#create  ManageIQ/SYSTEM]
[----] I, [2017-11-15T19:37:19.533180 #13277:ca76f0]  INFO -- : Updated namespace [SYSTEM/PROCESS/parse_provider_category  ManageIQ/SYSTEM]
[----] I, [2017-11-15T19:37:19.539604 #13277:ca76f0]  INFO -- : Invoking [builtin] method [/ManageIQ/System/Process/parse_provider_category] with inputs [{}]
[----] I, [2017-11-15T19:37:19.540321 #13277:ca76f0]  INFO -- : Setting provider_category to: 
[----] I, [2017-11-15T19:37:19.540879 #13277:ca76f0]  INFO -- : Following Relationship [miqaedb:/System/Request/InspectMe#create]
[----] I, [2017-11-15T19:37:19.556960 #13277:ca76f0]  INFO -- : Updated namespace [miqaedb:/System/Request/InspectMe#create  new_dialog/System]
[----] I, [2017-11-15T19:37:19.635525 #13277:ca76f0]  INFO -- : Updated namespace [System/Request/inspectme  new_dialog/System]
[----] I, [2017-11-15T19:37:19.648078 #13277:ca76f0]  INFO -- : Invoking [inline] method [/new_dialog/System/Request/InspectMe] with inputs [{}]
[----] I, [2017-11-15T19:37:19.650711 #13277:ca76f0]  INFO -- : <AEMethod [/new_dialog/System/Request/InspectMe]> Starting 
[----] E, [2017-11-15T19:37:20.091145 #13277:8e4151c] ERROR -- : <AEMethod inspectme> The following error occurred during method evaluation:
[----] E, [2017-11-15T19:37:20.092049 #13277:8e4151c] ERROR -- : <AEMethod inspectme>   DRb::DRbRemoteError: undefined method `object_send' for nil:NilClass
Did you mean?  object_id (MiqAeException::MethodNotFound)
[----] E, [2017-11-15T19:37:20.093190 #13277:8e4151c] ERROR -- : <AEMethod inspectme>   (druby://127.0.0.1:37766) /opt/rh/cfme-gemset/bundler/gems/manageiq-automation_engine-a5f735529730/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb:166:in `rescue in execute'
(druby://127.0.0.1:37766) /opt/rh/cfme-gemset/bundler/gems/manageiq-automation_engine-a5f735529730/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb:163:in `execute'
(druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:in `perform_without_block'
(druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:in `perform'
(druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:in `block (2 levels) in main_loop'
(druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `loop'
(druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `block in main_loop'
[----] E, [2017-11-15T19:37:20.098775 #13277:8e4151c] ERROR -- : Method STDERR: (druby://127.0.0.1:37766) /opt/rh/cfme-gemset/bundler/gems/manageiq-automation_engine-a5f735529730/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb:166:in `rescue in execute': undefined method `object_send' for nil:NilClass (DRb::DRbRemoteError)
[----] E, [2017-11-15T19:37:20.100003 #13277:8e4151c] ERROR -- : Method STDERR: Did you mean?  object_id (MiqAeException::MethodNotFound)
[----] E, [2017-11-15T19:37:20.100795 #13277:8e4151c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:37766) /opt/rh/cfme-gemset/bundler/gems/manageiq-automation_engine-a5f735529730/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service.rb:163:in `execute'
[----] E, [2017-11-15T19:37:20.101377 #13277:8e4151c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1624:in `perform_without_block'
[----] E, [2017-11-15T19:37:20.102064 #13277:8e4151c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1584:in `perform'
[----] E, [2017-11-15T19:37:20.102708 #13277:8e4151c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1657:in `block (2 levels) in main_loop'
[----] E, [2017-11-15T19:37:20.103336 #13277:8e4151c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `loop'
[----] E, [2017-11-15T19:37:20.104024 #13277:8e4151c] ERROR -- : Method STDERR: 	from (druby://127.0.0.1:37766) /opt/rh/rh-ruby23/root/usr/share/ruby/drb/drb.rb:1653:in `block in main_loop'
[----] E, [2017-11-15T19:37:20.104668 #13277:8e4151c] ERROR -- : Method STDERR: 	from /new_dialog/System/Request/InspectMe:4:in `<main>'
[----] I, [2017-11-15T19:37:20.135849 #13277:ca76f0]  INFO -- : <AEMethod [/new_dialog/System/Request/InspectMe]> Ending
[----] E, [2017-11-15T19:37:20.137193 #13277:ca76f0] ERROR -- : Aborting instantiation (unknown method return code) because [Method exited with rc=Unknown RC: [1]]
[----] E, [2017-11-15T19:37:20.137495 #13277:ca76f0] ERROR -- : Aborting instantiation (unknown method return code) because [Method exited with rc=Unknown RC: [1]]

Comment 9 mkanoor 2017-11-16 16:01:38 UTC
The reason this could fail is because
(1) The method needs a value called azure_item, which basically is the name of the service template
(2) Even when you pass in the azure_item = azure_item in the simulation parameters if you dont pass in all the required parameters for the Service Template the provisioning will fail. I think this service template in your example is expecting to a whole bunch of parameters as evident in this log.

/var/www/miq/vmdb/app/models/service_template.rb:375:in `provision_request': Basic Information/Cost Code/Cost Code (4 numbers) is required, Basic Information/Stack Settings/Stack Manager (UP ID) is required, Basic Information/Stack Settings/Stack Prefix (5 chars) is required, Basic Information/Billing Tag Settings/Application Name (20 chars max) is required, Basic Information/Billing Tag Settings/Purpose (20 chars max) is required, Basic Information/Billing Tag Settings/Project (20 chars max) is required, Basic Information/Billing Tag Settings/Business Unit (20 chars max) is required, Basic Information/Billing Tag Settings/Team Name (20 chars max) is required (RuntimeError)

Also if you try to order the Catalog Item manually you would see the Dialogs asking for additional parameters.

I would suggest testing with a simpler service catalog item which has no parameters.

Comment 10 Shveta 2017-11-17 22:44:54 UTC
Worked in  5.9.0.8.20171109215303_ed87902 .

Used method :
====================
# Get the Service Template Object
   service_template = $evm.vmdb('ServiceTemplate').where(:name => $evm.root['service_template_name']).first
   # Order the Service Template
   raise "No Service Template Found" unless service_template
   result = $evm.execute('create_service_provision_request', service_template)
   $evm.log(:info, "The Request ID is #{result.id}")



Passed parameters 
=====
service_template_name = catalog_item