Bug #20204

GET /hostgroup/:hostgroup_id/hosts returns all hosts when id of empty hostgroup is used

Added by Kevin Carrasco 11 months ago. Updated 7 months ago.

Status:Closed
Priority:Normal
Assigned To:Kavita Gaikwad
Category:API
Target version:Team Anurag Iteration 22
Difficulty: Bugzilla link:
Found in release:1.14.3 Pull request:https://github.com/theforeman/foreman/pull/4983
Story points-
Velocity based estimate-
Release1.17.0Release relationshipAuto

Description

This is an API issue, easily reproducible with hammer:

Issuing the following command while specifying a hostgroup with 0 hosts results in Hammer printing out all hosts known to Foreman regardless of their hostgroup membership:

hammer -u admin -p password --csv host list --hostgroup 'Fedora Rendernodes'

If we run hammer with a hostgroup that contains at least 1 host, then only the hosts associated with that hostgroup are printed (the expected behaviour). For example this works as expected since "Avere Mounts" is not an empty group:

hammer -u admin -p password --csv host list --hostgroup 'Avere Mounts'

Note that in this case, 'Avere Mounts' is inside 'Fedora Rendernodes': "Fedora Rendernodes/Avere Mounts", but the behaviour still happens with hostgroups that have no subgroups.

Expected results:
I think the correct behaviour should be to not print anything since the hostgroup we asked for is empty.

Additional notes:
This bug was introduced with fixing http://projects.theforeman.org/issues/13775/, namely it's this line: https://github.com/theforeman/foreman/commit/8e81effcedafc539cbe3477b5565d9239f1f2f51#diff-6e62e9d287766aaa9c3d35e6dc3470a1R375


Related issues

Related to Foreman - Bug #13775: Not able to change an HG for a host using API call Closed 02/17/2016
Duplicated by Hammer CLI - Bug #21369: Hammer host list shows all hosts if environment is empty Duplicate 10/17/2017

Associated revisions

Revision f4d64312
Added by Kavita Gaikwad 7 months ago

Fixes #20204 - returns all hosts for unassigned hostgroup

History

#1 Updated by Tomáš Strachota 10 months ago

  • Project changed from Hammer CLI to Foreman
  • Subject changed from Using --hostgroup on empty hostgroup prints all hosts known to Foreman to GET /hostgroup/:hostgroup_id/hosts returns all hosts when id of empty hostgroup is used
  • Description updated (diff)
  • Category changed from Host groups to API

This is an API problem, I'm switching the project and category.

#2 Updated by Tomáš Strachota 10 months ago

  • Related to Bug #13775: Not able to change an HG for a host using API call added

#3 Updated by Kavita Gaikwad 10 months ago

  • Assigned To set to Kavita Gaikwad
  • Target version set to Team Anurag backlog

#4 Updated by Tomáš Strachota 7 months ago

  • Duplicated by Bug #21369: Hammer host list shows all hosts if environment is empty added

#5 Updated by Tomáš Strachota 7 months ago

Please note that filtering by environments is affected too and

hammer host list --environment=empty 

prints all hosts as well.
See the linked duplicate issue for more details.

#6 Updated by Kavita Gaikwad 7 months ago

  • Target version changed from Team Anurag backlog to Team Anurag Iteration 22

#7 Updated by The Foreman Bot 7 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4983 added

#8 Updated by Kavita Gaikwad 7 months ago

  • % Done changed from 0 to 100
  • Status changed from Ready For Testing to Closed

#9 Updated by Marek Hulán 7 months ago

  • Release set to 1.17.0

Also available in: Atom PDF