Skip to content

Commit

Permalink
Add support for older verify_checksum endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik authored and ogajduse committed May 21, 2024
1 parent 95647ef commit 1774a48
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
46 changes: 45 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ def path(self, which=None):
/capsules/<id>/content/reclaim_space
content_verify_checksum
/capsules/<id>/content/verify_checksum
``super`` is called otherwise.
"""
Expand Down Expand Up @@ -6336,11 +6337,13 @@ def path(self, which=None):
/products/bulk/sync_plan
http_proxy
/products/bulk/http_proxy
verify_checksum
/products/bulk/verify_checksum
``super`` is called otherwise.
"""
if which in ("destroy", "sync", "sync_plan", "http_proxy"):
if which in ("destroy", "sync", "sync_plan", "http_proxy", "verify_checksum"):
return f'{super().path(which="base")}/{which}'
return super().path(which)

Expand Down Expand Up @@ -6420,6 +6423,25 @@ def sync_plan(self, synchronous=True, timeout=None, **kwargs):
response = client.put(self.path('sync_plan'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def verify_checksum(self, synchronous=True, timeout=None, **kwargs):
"""Verify checksum for one or more products.
:param synchronous: What should happen if the server returns an HTTP
202 (accepted) status code? Wait for the task to complete if
``True``. Immediately return the server's response otherwise.
:param timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
:param kwargs: Arguments to pass to requests.
:returns: The server's response, with all JSON decoded.
:raises: ``requests.exceptions.HTTPError`` If the server responds with
an HTTP 4XX or 5XX message.
"""
kwargs = kwargs.copy() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.put(self.path('verify_checksum'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)


class PartitionTable(
Entity,
Expand Down Expand Up @@ -6868,6 +6890,8 @@ def path(self, which=None):
/repositories/<id>/remove_content
sync
/repositories/<id>/sync
verify_checksum
/repositories/<id>/verify_checksum
upload_content
/repositories/<id>/upload_content
import_uploads
Expand All @@ -6883,6 +6907,7 @@ def path(self, which=None):
'module_streams',
'remove_content',
'sync',
'verify_checksum',
'import_uploads',
'upload_content',
):
Expand Down Expand Up @@ -6953,6 +6978,25 @@ def sync(self, synchronous=True, timeout=None, **kwargs):
response = client.post(self.path('sync'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def verify_checksum(self, synchronous=True, timeout=None, **kwargs):
"""Verify checksum of repository contents.
:param synchronous: What should happen if the server returns an HTTP
202 (accepted) status code? Wait for the task to complete if
``True``. Immediately return the server's response otherwise.
:param timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
:param kwargs: Arguments to pass to requests.
:returns: The server's response, with all JSON decoded.
:raises: ``requests.exceptions.HTTPError`` If the server responds with
an HTTP 4XX or 5XX message.
"""
kwargs = kwargs.copy() # shadow the passed-in kwargs
kwargs.update(self._server_config.get_client_kwargs())
response = client.post(self.path('verify_checksum'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def upload_content(self, synchronous=True, timeout=None, **kwargs):
"""Upload a file or files to the current repository.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def test_id_and_which(self):
(entities.Repository, 'packages'),
(entities.Repository, 'remove_content'),
(entities.Repository, 'sync'),
(entities.Repository, 'verify_checksum'),
(entities.Repository, 'upload_content'),
(entities.RHCIDeployment, 'deploy'),
(entities.ScapContents, 'xml'),
Expand Down Expand Up @@ -415,6 +416,7 @@ def test_no_such_path_error(self):
(entities.Organization, 'repo_discover'),
(entities.Product, 'repository_sets'),
(entities.Repository, 'sync'),
(entities.Repository, 'verify_checksum'),
(entities.Repository, 'upload_content'),
(entities.ScapContents, 'xml'),
(entities.RHCIDeployment, 'deploy'),
Expand Down Expand Up @@ -2159,6 +2161,7 @@ def setUpClass(cls):
(entities.ProductBulkAction(**generic).sync, 'put'),
(entities.ProductBulkAction(**generic).http_proxy, 'put'),
(entities.ProductBulkAction(**generic).sync_plan, 'put'),
(entities.ProductBulkAction(**generic).verify_checksum, 'put'),
(entities.PuppetClass(**generic).list_scparams, 'get'),
(entities.RHCIDeployment(**generic).deploy, 'put'),
(entities.RecurringLogic(**generic).cancel, 'post'),
Expand All @@ -2167,6 +2170,7 @@ def setUpClass(cls):
(entities.Repository(**generic).module_streams, 'get'),
(entities.Repository(**generic).remove_content, 'put'),
(entities.Repository(**generic).sync, 'post'),
(entities.Repository(**generic).verify_checksum, 'post'),
(entities.ScapContents(**generic).xml, 'get'),
(entities.SmartProxy(**generic).import_puppetclasses, 'post'),
(entities.SmartProxy(**generic).refresh, 'put'),
Expand Down

0 comments on commit 1774a48

Please sign in to comment.