Bug 1347409

Summary: Service order through API does not auto approve
Product: Red Hat CloudForms Management Engine Reporter: Fabien Dupont <fdupont>
Component: APIAssignee: abellott
Status: CLOSED CURRENTRELEASE QA Contact: Jan Krocil <jkrocil>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 5.6.0CC: abellott, cbolz, cpelland, dajohnso, gmccullo, jhardy, jkrocil, lbopf, obarenbo, simaishi, sshveta
Target Milestone: GAKeywords: TestOnly, ZStream
Target Release: 5.7.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: rest:service
Fixed In Version: 5.7.0.0 Doc Type: Known Issue
Doc Text:
If a user orders a service through the REST API, they will see that their request stays in the 'Pending' state. Workaround: Copy the following instance to a writeable domain and remove the guard condition: Automate Instance: / ManageIQ / System / Policy / ServiceTemplateProvisionRequest_created guard: ${/#miq_request.process}
Story Points: ---
Clone Of:
: 1350903 (view as bug list) Environment:
Last Closed: 2017-01-11 20:09:29 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:
Bug Depends On:    
Bug Blocks: 1350903    

Description Fabien Dupont 2016-06-16 18:27:29 UTC
Description of problem:


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


How reproducible: Always


Steps to Reproduce:
1. Order a service through /api/service_catalogs/3/service_templates endpoint with a request object have a requester with auto_approve=true, such as:

content = {
  :action => "order",
  :resource => {
    :href => "http://miq.coe.evenit.info:3000/api/service_catalogs/3/service_templates/2",
    :devops_project_business_unit_id => "428800024",
    :devops_project_name => "api_test2",
    :devops_project_team_development => "development_team_a",
    :devops_project_team_review => "review_team_y",
    :devops_project_team_production => "production_team_1",
  },
  :requester => {
    :user_name => 'admin',
    :auto_approve => true
  },
}

2. The request is created but is pending due to an assertion in /ManageIQ/System/Policy/ServiceTemplateProvisionRequest_created that checks the value of ${/#miq_request.process}. This assertion is always false when deploying from API.

Actual results:
The service orders (without shopping cart) through API are always pending.

Expected results:
The service orders (without shopping cart) through API with auto_approve=true are approved and processed.

Additional info:
Early discussion with ManageIQ team points to this PR: https://github.com/ManageIQ/manageiq/commit/948647176b6dd671062192eae0e45f6220feffb5. But it may not be related.

Comment 3 Greg McCullough 2016-06-17 12:49:30 UTC
Worked with Alberto to track down the issue.  The REST API call creates the request differently then the OpsUI, which works with the new shopping cart logic, is doing it.  They should both use the OpsUI logic.

Code has been tested and once tests are cleaned up we will have a PR available.

Comment 5 CFME Bot 2016-06-17 21:20:52 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/52be816b9ac11515fa31c0ee0e86b166c4a2fa7e

commit 52be816b9ac11515fa31c0ee0e86b166c4a2fa7e
Author:     Alberto Bellotti <abellott>
AuthorDate: Thu Jun 16 17:58:41 2016 -0400
Commit:     Alberto Bellotti <abellott>
CommitDate: Fri Jun 17 16:32:19 2016 -0400

    [api] Fix for service_template order
    
    - Leverages new resource action workflow's submit_request
    - Provides validation
    - Added Service Template validate_order method and orderable? alias
    - Updated rspecs
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1347409

 app/controllers/api_controller/service_orders.rb   |  4 ++
 .../api_controller/service_templates.rb            | 17 +++--
 app/models/service_template.rb                     |  5 ++
 config/api.yml                                     |  2 +
 spec/requests/api/service_catalogs_spec.rb         | 78 ++++++++++++++++++++--
 spec/support/api_spec_helper.rb                    |  4 ++
 6 files changed, 96 insertions(+), 14 deletions(-)

Comment 6 Fabien Dupont 2016-06-18 09:01:39 UTC
Looks good to me. I checked out the commit and my test is ok.

Comment 8 Dave Johnson 2016-06-22 19:31:09 UTC
Taras, lean on Shveta if you need assistance with services.

Comment 10 Satoe Imaishi 2016-06-28 12:53:37 UTC
In fact, it's not backported yet... putting back to ON_DEV.

Comment 11 abellott 2016-06-28 13:17:37 UTC
Odd, PR# 9276 showed backported to darga. I labeled https://github.com/ManageIQ/manageiq/pull/9276 back to darga/yes.