From 660e9d00e47974acc8321f638eeaf94278cb472f Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 25 Sep 2024 13:28:04 +0200 Subject: [PATCH] feat: add Inventory.this_system_tags() 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 --- pytest_client_tools/inventory.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pytest_client_tools/inventory.py b/pytest_client_tools/inventory.py index 9b89146..42115a4 100644 --- a/pytest_client_tools/inventory.py +++ b/pytest_client_tools/inventory.py @@ -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]