Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1857866 - Search for hosts based on facts randomly doesn't work
Summary: Search for hosts based on facts randomly doesn't work
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hosts
Version: 6.7.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: tstrych
URL:
Whiteboard:
Depends On:
Blocks: 1663217
TreeView+ depends on / blocked
 
Reported: 2020-07-16 17:11 UTC by Petr Kubica
Modified: 2022-02-16 11:35 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-05-06 09:15:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Petr Kubica 2020-07-16 17:11:16 UTC
Description of problem:
We need to search host based on its FQDN and in RHV product it is done via API and search based on facts

But after trying Some hosts works properly and some hosts doesn't. I couldn't find a rule which would describe in which cases it is working and in which not.

If necessary I can provide the environment where it happens.

Working:
- Host is listed between hosts
- GET https://<SATELLITE_URL>/api/v2/hosts/<HOST_FQDN> works
- host has filled FQDN on an interface (checked in portal).

Not working:
GET https://<SATELLITE_URL>/api/v2/hosts?search=facts.network::fqdn=<HOST_FQDN>
GET https://<SATELLITE_URL>/api/v2/hosts?search=facts.network::hostname=<HOST_FQDN>

Getting:
{
  "total": 6,
  "subtotal": 0,
  "page": 1,
  "per_page": 20,
  "search": "facts.network::fqdn=<HOST_FQDN>",
  "sort": {
    "by": null,
    "order": null
  },
  "results": []
}

foreman-tail:
==> /var/log/httpd/foreman-ssl_access_ssl.log <==
<IP> - - [16/Jul/2020:19:01:07 +0200] "GET /api/v2/hosts?search=facts.network::fqdn=<HOST_FQDN> HTTP/1.1" 200 204 "-" "curl/7.29.0"

==> /var/log/foreman/production.log <==
2020-07-16T19:01:07 [I|app|44e68c6e] Started GET "/api/v2/hosts?search=facts.network::fqdn=<HOST_FQDN>" for <IP> at 2020-07-16 19:01:07 +0200
2020-07-16T19:01:07 [I|app|44e68c6e] Processing by Api::V2::HostsController#index as JSON
2020-07-16T19:01:07 [I|app|44e68c6e]   Parameters: {"search"=>"facts.network::fqdn=<HOST_FQDN>", "apiv"=>"v2"}
2020-07-16T19:01:07 [I|app|44e68c6e] Authorized user admin(Admin User)
2020-07-16T19:01:08 [I|app|44e68c6e]   Rendering api/v2/hosts/index.json.rabl within api/v2/layouts/index_layout
2020-07-16T19:01:08 [I|app|44e68c6e]   Rendered api/v2/hosts/index.json.rabl within api/v2/layouts/index_layout (1.0ms)
2020-07-16T19:01:08 [I|app|44e68c6e] Completed 200 OK in 152ms (Views: 5.2ms | ActiveRecord: 17.5ms)


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

How reproducible:
With almost half cases, but randomly

Steps to Reproduce:
1. Have configured satellite environment, create a host within satellite (it could be a dummy host) a.sub1.sub2.sub3.sub4.example.com and also fill an interface
2. 
Search in search bar for this host: facts.network::fqdn=a.sub1.sub2.sub3.sub4.example.com
or
GET https://<SATELLITE_URL>/api/v2/hosts?search=facts.network::fqdn=<HOST_FQDN>

Actual results:
In some cases it will successfully find the host in some doesn't

Comment 3 tstrych 2020-09-03 14:51:36 UTC
I reproduced this BZ with sat 6.7.3 and with 6.8.0 snap 14.

Comment 4 Lukas Zapletal 2020-09-04 06:35:50 UTC
Hello, this is probably misunderstanding of Facts API and what it provides.

Satellite does not give any guarantee about facts, it only stores all facts in the inventory database. What is important is what fact client (facter or rhsm) reports them, if it reports anything. Some hosts may or may not have those clients enabled, some not. E.g. RHEL host which was registered to content has always facts reported by rhsm, client that was configured to have puppet also reports facty by facter. But it is totally possible to have e.g. CentOS host without either puppet or rhsm (or ansible). In that case, that host has completely *empty* facts. Therefore all searches will fail to find the host.

And it turns out that's your case, look:

# foreman-rake console

irb> Host.unscoped.all.each {|h| puts "HOST: #{h.name} HOSTNAME: #{h.facts["network::hostname"]} FQDN: #{h.facts["network::fqdn"]}" }

HOST: capsule.sat0.rhev.lab.eng.brq.redhat.com HOSTNAME: capsule.sat0.rhev.lab.eng.brq.redhat.com FQDN: capsule.sat0.rhev.lab.eng.brq.redhat.com
HOST: engine.sat0.rhev.lab.eng.brq.redhat.com HOSTNAME: engine.sat0.rhev.lab.eng.brq.redhat.com FQDN: engine.sat0.rhev.lab.eng.brq.redhat.com
HOST: brq-satellite.rhev.lab.eng.brq.redhat.com HOSTNAME:  FQDN: 
HOST: host-01.sat0.rhev.lab.eng.brq.redhat.com HOSTNAME: host-01.sat0.rhev.lab.eng.brq.redhat.com FQDN: host-01.sat0.rhev.lab.eng.brq.redhat.com
HOST: a.sat0.rhev.lab.eng.brq.redhat.com HOSTNAME:  FQDN: 
HOST: vm.sat0.rhev.lab.eng.brq.redhat.com HOSTNAME: vmnewname.sat0.rhev.lab.eng.brq.redhat.com FQDN: vmnewname.sat0.rhev.lab.eng.brq.redhat.com

Two hosts named brq-satellite and a do not have any facts associated with them for the reason explained above.

irb> Host.unscoped.find_by_name("a.sat0.rhev.lab.eng.brq.redhat.com").facts
=> {}

We have discussed possibility to have some "fallback" fact client that would be installed for hosts which don't have any client available. But this is just in planning phase.

Solution: Install RHSM or Facter or Ansible on those machines, register or configure them to upload facts.


Note You need to log in before you can comment on or make changes to this bug.