Skip to content

Commit

Permalink
feat: add Inventory.this_system_tags()
Browse files Browse the repository at this point in the history
Add a new function in the Inventory class to query Inventory for the
tags of the current system. It leverages the existing method
"this_system()", as it needs the actual Inventory ID.

Signed-off-by: Pino Toscano <[email protected]>
  • Loading branch information
ptoscano committed Sep 25, 2024
1 parent ea248ba commit 660e9d0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pytest_client_tools/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,28 @@ def this_system_profile(self):
f"returned for the current UUID ({self._insights_client.uuid})"
)
return res_json["results"][0]["system_profile"]

def this_system_tags(self):
"""
Query Inventory for the tags of the current system.
This assumes the current system is already registered with
`insights-client`.
:return: The dict of the tags of the current system in Inventory
:rtype: dict
"""
if not self._insights_client:
raise RuntimeError(
"Inventory.this_system_tags(): cannot invoke without insights_client"
)
this = self.this_system()
inventory_id = this["id"]
path = f"hosts/{inventory_id}/tags"
res_json = self.get(path).json()
if res_json["total"] != 1:
raise RuntimeError(
f"Inventory.this_system_tags(): {res_json['total']} hosts "
f"returned for the current UUID ({self._insights_client.uuid})"
)
return res_json["results"][inventory_id]

0 comments on commit 660e9d0

Please sign in to comment.