Bug 1101537

Summary: activation_keys.add_host_collections API removes host collections from the activation key
Product: Red Hat Satellite Reporter: Tomas Lestach <tlestach>
Component: APIAssignee: Dustin Tsang <dtsang>
Status: CLOSED CURRENTRELEASE QA Contact: sthirugn <sthirugn>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.0.3CC: bbuckingham, bkearney, inecas, jmontleo, mmccune, sthirugn
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/6347
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-09-11 12:29:09 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:
Attachments:
Description Flags
attaching patch none

Description Tomas Lestach 2014-05-27 12:59:29 UTC
Description of problem:

Calling
        @api.resource(:activation_keys).call(
          :add_host_collections,
          {
            :id => ak_id,
            :host_collection_ids => hc_ids
          })
does not associate host_collections with the activation key

Version-Release number of selected component (if applicable):
Satellite-6.0.3-RHEL-6-20140521.0-Satellite-x86_64

How reproducible:
always

Steps to Reproduce:
# bundle exec irb
irb> require 'apipie-bindings'
irb> api = ApipieBindings::API.new({:uri => 'http://localhost:3000/', :username => 'admin', :password => 'changeme', :api_version=> '2', :aggressive_cache_checking => true})
irb> api.resource(:activation_keys).call(
          :add_host_collections,
          {
            :id => ak_id,
            :host_collection_ids => hc_ids
          })

Actual results:
* API call runs without issues, but does not associate host collections with the activation key
* according to config/routes/api/v2.rb it looks like :remove_host_collections is called instead

Expected results:
associate host collections with the activation key

Additional info:
* <sat6>/apidoc/v2/activation_keys/add_host_collections
does not have complete apidoc
* Ivan's patch:

diff --git a/config/routes/api/v2.rb b/config/routes/api/v2.rb
index ad7cb9a..3456d10 100644
--- a/config/routes/api/v2.rb
+++ b/config/routes/api/v2.rb
 -27,8 +27,8 @@ Katello::Engine.routes.draw do
         match '/releases' => 'activation_keys#available_releases', :via => :get, :on => :member
         api_resources :host_collections, :only => [:index]
         member do
-          match '/host_collections' => 'activation_keys#add_host_collections', :via => :post
-          match '/host_collections' => 'activation_keys#remove_host_collections', :via => :put
+          match '/host_collections' => 'activation_keys#add_host_collections', :via => :put
+          match '/host_collections' => 'activation_keys#remove_host_collections', :via => :delete
           match '/host_collections/available' => 'activation_keys#available_host_collections', :via => :get
         end
         api_resources :products, :only => [:index]

Comment 1 RHEL Program Management 2014-05-27 13:03:52 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Tomas Lestach 2014-05-27 13:05:16 UTC
Created attachment 899496 [details]
attaching patch

Comment 4 Dustin Tsang 2014-06-23 23:59:55 UTC
redmine issue created.

Comment 5 Dustin Tsang 2014-06-24 00:01:27 UTC
for the actions had documented(apipie) the wrong http actions

Comment 6 Bryan Kearney 2014-06-26 16:03:09 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/6347 has been closed

Comment 8 sthirugn@redhat.com 2014-08-13 20:49:14 UTC
Verified.

Tested both CLI and API calls and they work fine:

hammer> activation-key add-host-collection --host-collection-id=1 --id=7 --organization-id=3
The host collection has been associated

# curl -X POST -H "Accept:application/json" -H "Content-Type: application/json" -u admin:changeme --insecure -d '{"id":"7","host_collection_ids":["1"]}' https://$host/katello/api/activation_keys/7/host_collections
success

Comment 9 Bryan Kearney 2014-09-11 12:29:09 UTC
This was delivered with Satellite 6.0 which was released on 10 September 2014.