Bug 1999123

Summary: The hostgroup[environment_id] parameter is erroneously included in Satellite's API documentation for the 'POST /api/hostgroups' and 'PUT /api/hostgroups/:id' methods
Product: Red Hat Satellite Reporter: momran
Component: Host GroupAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED WORKSFORME QA Contact: Satellite QE Team <sat-qe-bz-list>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.9.0CC: apatel, aruzicka, inecas, kgaikwad, ofedoren
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-08-14 10:14:47 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:

Description momran 2021-08-30 13:10:26 UTC
Description of problem:

On Red Hat Satellite 6.9.4, the API documentation for the following methods:

 - POST /api/hostgroups
 - PUT /api/hostgroups/:id

erroneously refer to the following parameter:

- hostgroup[environment_id]

   optional , nil allowed	
   Environment ID

   Validations:

   Must be a number.

Using this parameter raises an HTTP/500 error.


On the other hand, the correct parameter is:

- hostgroup[lifecycle_environment_id]

   optional	
   Lifecycle environment ID

   Validations:

   Must be a number.

Using this parameter does not raise any error.

The same issue was also observed on Red Hat Satellite 6.9.3.


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

- Red Hat Satellite 6.9.4:
~~~
# rpm -qa | grep -i tfm-rubygem-katello
tfm-rubygem-katello-3.18.1.33-1.el7sat.noarch

# cat /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.18.1.33/app/controllers/katello/concerns/api/v2/hostgroups_controller_extensions.rb | grep -i "environment ID"
            param :lifecycle_environment_id, :number, :desc => N_('Lifecycle environment ID')
~~~

- Red Hat Satellite 6.9.3:
~~~
# rpm -qa | grep -i tfm-rubygem-katello
tfm-rubygem-katello-3.18.1.32-1.el7sat.noarch

# cat /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.18.1.32/app/controllers/katello/concerns/api/v2/hostgroups_controller_extensions.rb | grep -i "environment ID"
            param :lifecycle_environment_id, :number, :desc => N_('Lifecycle environment ID')
~~~


How reproducible:

Always.


Steps to Reproduce:

Use an API call with either of the following methods:

 - POST /api/hostgroups
 - PUT /api/hostgroups/:id

with the following parameter:

- hostgroup[environment_id]

   optional , nil allowed	
   Environment ID

   Validations:

   Must be a number.


Actual results:

A HTTP/500 error is raised.


Expected results:

Remove the following parameter from the API documentation since the correct parameter is already included:

- hostgroup[environment_id]

   optional , nil allowed	
   Environment ID

   Validations:

   Must be a number.

Comment 1 Oleh Fedorenko 2021-09-14 10:38:56 UTC
Hi Mohamed,

I've tried to use this parameter via both hammer and curl, and it seems working just fine on Satellite 6.9.6.

Also, the hostgroup[environment_id] should not be removed since this parameter is related to Puppet environment. Removal of this parameter will make changing of the Puppet environment for a host group impossible via both hammer and API.


Could you please provide a log output when you encounter this error?

Comment 2 momran 2021-09-17 07:30:01 UTC
Hi Oleh,

Thank you for your update, as well as for the clarification you provided.

Please find below the log output from Satellite 6.9.4:


 - Using 'environment_id' does not work:
~~~
2021-08-24T09:02:38 [I|app|0a65b8e1] Started PUT "/api/hostgroups/22" for 10.57.66.18 at 2021-08-24 09:02:38 -0400
2021-08-24T09:02:38 [I|app|0a65b8e1] Processing by Api::V2::HostgroupsController#update as JSON
2021-08-24T09:02:38 [I|app|0a65b8e1]   Parameters: {"hostgroup"=>{"description"=>"Random string from process 112128", "environment_id"=>107, "id"=>22}, "apiv"=>"v2", "id"=>"22"}
2021-08-24T09:02:38 [I|aud|0a65b8e1] Hostgroup (22) update event on description Random string from process 111990, Random string from process 112128
2021-08-24T09:02:38 [I|aud|0a65b8e1] Hostgroup (22) update event on environment_id , 107
2021-08-24T09:02:38 [W|app|0a65b8e1] Action failed
2021-08-24T09:02:38 [I|app|0a65b8e1]   Rendering api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout
2021-08-24T09:02:38 [I|app|0a65b8e1]   Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (Duration: 3.7ms | Allocations: 6568)
2021-08-24T09:02:38 [I|app|0a65b8e1] Completed 500 Internal Server Error in 42ms (Views: 8.1ms | ActiveRecord: 6.4ms | Allocations: 27909)
~~~

 - Using 'lifecycle_environment_id' instead does work:
~~~
2021-08-24T09:00:54 [I|app|862e2631] Started PUT "/api/hostgroups/22" for 10.57.66.18 at 2021-08-24 09:00:54 -0400
2021-08-24T09:00:54 [I|app|862e2631] Processing by Api::V2::HostgroupsController#update as JSON
2021-08-24T09:00:54 [I|app|862e2631]   Parameters: {"hostgroup"=>{"description"=>"Random string from process 111990", "lifecycle_environment_id"=>107, "id"=>22}, "apiv"=>"v2", "id"=>"22"}
2021-08-24T09:00:54 [I|aud|862e2631] Hostgroup (22) update event on lifecycle_environment_id , 107
2021-08-24T09:00:54 [I|aud|862e2631] Hostgroup (22) update event on description , Random string from process 111990
2021-08-24T09:00:54 [I|app|862e2631]   Rendering api/v2/hostgroups/update.json.rabl
2021-08-24T09:00:54 [I|app|862e2631]   Rendered api/v2/hostgroups/update.json.rabl (Duration: 15.3ms | Allocations: 7493)
2021-08-24T09:00:54 [I|app|862e2631] Completed 200 OK in 97ms (Views: 13.7ms | ActiveRecord: 36.5ms | Allocations: 38351)
~~~

Hope this helps.

I will also ask the customer if they can update their Satellite to 6.9.6 nd test once more. Will keep you posted.

Thanks.

Comment 5 Adam Ruzicka 2023-08-14 10:14:47 UTC
This is an old bug, the release it was reported against is already EOL and we haven't heard any news from anyone on this. From the comments on this BZ I'd say there was some confusion between what environment_id and lifecycle_environment_id represent. With that being said I'll go ahead and close this, if you feel this is something that still should be resolved by us, feel free to reopen.