uyuni-project / uyuni

Source code for Uyuni
https://www.uyuni-project.org/
GNU General Public License v2.0
428 stars 177 forks source link

Search by hostname API return the full list of systems - #1215601 #7574

Open cbosdo opened 11 months ago

cbosdo commented 11 months ago

Bugzilla report: https://bugzilla.suse.com/show_bug.cgi?id=1215601

Running this script return the whole list of systems rather than only the one matching. In any case that system should be the first one returned.

#!/usr/bin/env python3
from xmlrpc.client import ServerProxy
import ssl

MANAGER_URL = "https://myserver/rpc/api"
MANAGER_LOGIN = "user"
MANAGER_PASSWORD = "pass"

# You might need to set to set other options depending on your
# server SSL configuration and your local SSL configuration
context = ssl.create_default_context()
client = ServerProxy(MANAGER_URL, context=context)
key = client.auth.login(MANAGER_LOGIN, MANAGER_PASSWORD)

print(client.system.search.hostname(key, "a-registered-minion"))

client.auth.logout(key)
Bischoff commented 11 months ago

I can reproduce only on uyuni branch, not on head.

[
 {'hostname': 'uyuni-master-min-suse.mgr.suse.de', 'ip': '10.137.210.214', 'name': 'uyuni-master-min-suse.mgr.suse.de', 'id': 1000010001, 'last_checkin': <DateTime '20230922T11:32:38'
 at 0x7fded178cc18>},
 {'hostname': 'uyuni-master-min-kvm.mgr.suse.de', 'ip': '10.137.210.222', 'name': 'uyuni-master-min-kvm.mgr.suse.de', 'id': 1000010005, 'last_checkin': <DateTime 
'20230922T11:44:56' at 0x7fded17a1048>},
 {'name': 'uyuni-master-minssh-suse.mgr.suse.de', 'id': 1000010002, 'last_checkin': <DateTime '20230922T11:34:30' at 0x7fded17a10f0>},
 {'hostname': 'uyuni-master-min-ubuntu2204.mgr.suse.de', 'ip': '10.137.210.219', 'name': 'uyuni-master-min-ubuntu2204.mgr.suse.de', 'id': 1000010004, 'last_checkin': <DateTime '20230922T11:40:
48' at 0x7fded17a11d0>},
 {'hostname': 'uyuni-master-min-build.mgr.suse.de', 'ip': '10.137.210.221', 'name': 'uyuni-master-min-build.mgr.suse.de', 'id': 1000010006, 'last_checkin': <Da
teTime '20230922T11:46:37' at 0x7fded17a12b0>},
 {'hostname': 'uyuni-master-min-rocky8.mgr.suse.de', 'ip': '10.137.210.217', 'name': 'uyuni-master-min-rocky8.mgr.suse.de', 'id': 100001
0003, 'last_checkin': <DateTime '20230922T11:37:01' at 0x7fded17a1390>}
]
Bischoff commented 11 months ago

I have the explanation of the problem.

If you search for mgr-de-uyuni-suse-master you also get all systems.

I suppose that the search function works as follows:

  1. the searched term gets decomposed into its compenents: at dashes: 'uyuni-master-min-suse' => 'uyuni', 'master', 'min', and 'suse'
  2. each of the terms gets searched, in the case of 'suse' it gives all systems because they all end up in 'mgr.suse.de'
  3. the result sets are interesected

The issue does not happen on HEAD because we have sles15 instead of suse in minion's name. The issue does not happen on the other minions for the same reason: their names are more specific.

avshiliaev commented 11 months ago

Hey @Bischoff thanks for the explanation. I still think it's more of an unintended behavior. At least from the initial report. Should we have it eventually as a bug?