Bug 1376613

Summary: Host environments API returns incorrect results
Product: Red Hat Satellite Reporter: Erinn Looney-Triggs <erinn.looneytriggs>
Component: Configuration ManagementAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED NOTABUG QA Contact: Katello QA List <katello-qa-list>
Severity: high Docs Contact:
Priority: high    
Version: 6.2.0CC: bbuckingham, erinn.looneytriggs, jcallaha, oprazak
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-10-07 05:58:28 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:

Description Erinn Looney-Triggs 2016-09-15 23:06:47 UTC
Description of problem:
When using the API a call to /api/environments/(env number)/hosts returns ALL host regardless of environment that hosts are in, where a call to /katello/api/environments/(env number)/systems returns ONLY content hosts that are in the environment.

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

How reproducible:
Create an organization with multiple hosts, place different hosts in different LEs. Exercise the API.

Steps to Reproduce:
1. hammer --debug host list --environment-id=1 --organization-id=1
[DEBUG 2016-09-15 16:53:34 API] Response: {
       "total" => 501,
    "subtotal" => 501,
        "page" => 1,
    "per_page" => 1000,
      "search" => nil,
        "sort" => {
           "by" => nil,
        "order" => nil
    },
Output will contain hosts that are not in the Library LE.

2.hammer --debug content-host list --organization-id 1 --lifecycle-environment-id 1

[DEBUG 2016-09-15 17:04:23 API] Response: {
       "total" => 435,
    "subtotal" => 435,
        "page" => "1",
    "per_page" => "20",
       "error" => nil,
      "search" => nil,


Actual results:
You receive two different responses from calling two different places and NO these are not hosts that have been provisioned and not subscribed, the results are incorrect.

Expected results:
I expect that the hosts list will return ONLY hosts that are in the environment, not all hosts

Comment 2 Ondřej Pražák 2016-09-29 10:30:33 UTC
The word 'environment' is overloaded here, please note that 'environment' and 'lifecycle-environment' are not the same entities.

1. hammer host list --environment-id=1 --organization-id=1
This lists all hosts that are assigned to Puppet environment with id 1.
You can check with:

hammer host info --id $id_of_a_host_from_output_of_previous_command 
note the Environment in the output

hammer environment list
the Environment with name from previous command will have id 1.

2. hammer content-host list --organization-id 1 --lifecycle-environment-id 1
This lists all (content) hosts that are assigned to Lifecycle environment with id 1.

Could you elaborate on what you are trying to achieve? If you are using 2 different hammer commands that call different API endpoints, why do you expect them to return same results?

Comment 3 Erinn Looney-Triggs 2016-09-29 15:26:26 UTC
Ok, then how do you filter the host list based off of lifecycle environment? You could do this with content hosts but those APIs were deprecated and in fact despite them still being there are no longer documented. As well if environment means puppet environment, probably best to document that for the next person that gets confused like I am.

-Erinn

Comment 4 Ondřej Pražák 2016-09-30 08:18:40 UTC
You are right, it probably should be in the docs. I opened a new issue (https://bugzilla.redhat.com/show_bug.cgi?id=1380627).

hammer host list --search 'lifecycle_environment_id = 1'

lists hosts with given lifecycle environment. Does this resolve your issue?

Comment 5 Erinn Looney-Triggs 2016-10-06 19:10:42 UTC
Yeah that basically solves it, the larger problem is more philosophical in nature. An API was deprecated, a new API was put into place, the old had a lifecycle-environment option, the new had an environment option, easy to assume the old and the new were the same with the minimal documentation. I would love to see the API docs and the hammer help updated to reflect that environments is in fact referring to puppet environments.

But that is about all, just a misunderstanding and frustration with the API changing in that way.

Thanks,
-Erinn

Comment 6 Ondřej Pražák 2016-10-07 05:58:28 UTC
The docs will be updated in a separate issue (see comment #4). Closing since this is not a bug.