-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new 'external_inventory' fixture
Create a new fixture to communicate with the Insights Inventory service. This will be used to verify that the operation of "insights-client" does what expected. Fixes #12 Signed-off-by: Pino Toscano <[email protected]>
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SPDX-FileCopyrightText: Red Hat | ||
# SPDX-License-Identifier: MIT | ||
|
||
from .restclient import RestClient | ||
|
||
|
||
class Inventory: | ||
""" | ||
Inventory | ||
This class represents an Inventory server. | ||
""" | ||
|
||
def __init__(self, base_url, verify=True, request=None): | ||
self._rest_client = RestClient( | ||
base_url=base_url, | ||
verify=verify, | ||
cert=( | ||
"/etc/pki/consumer/cert.pem", | ||
"/etc/pki/consumer/key.pem", | ||
), | ||
) | ||
self._request = request | ||
|
||
@property | ||
def base_url(self): | ||
""" | ||
The base URL of the Inventory server. | ||
""" | ||
return self._rest_client.base_url | ||
|
||
def get(self, path, **kwargs): | ||
""" | ||
Perform a GET REST call. | ||
""" | ||
return self._rest_client.get(path, **kwargs) | ||
|
||
def this_system(self): | ||
""" | ||
Query Inventory for the current system. | ||
This assumes the current system is already registered with | ||
`insights-client`. Raises `SystemNotRegisteredError` if the system | ||
is not registered. | ||
:return: The dict of the current system in Inventory | ||
:rtype: dict | ||
""" | ||
if not self._request: | ||
raise RuntimeError( | ||
"Inventory.this_system(): cannot invoke without a pytest request set" | ||
) | ||
insights_client = self._request.getfixturevalue("insights_client") | ||
path = f"hosts?insights_id={insights_client.uuid}" | ||
res_json = self.get(path).json() | ||
if res_json["total"] != 1: | ||
raise RuntimeError( | ||
f"Inventory.this_system(): {res_json['total']} hosts returned " | ||
f"for the current UUID ({insights_client.uuid})" | ||
) | ||
return res_json["results"][0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters