Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new verify_checksum endpoints #1138

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,24 @@ def content_reclaim_space(self, synchronous=True, timeout=None, **kwargs):
response = client.post(self.path('content_reclaim_space'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def content_verify_checksum(self, synchronous=True, timeout=None, **kwargs):
"""Check for missing or corrupted artifacts, and attempt to redownload them.

: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.
Comment on lines +1028 to +1030
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my understanding about synchronous execution,
if synchronous=True then don't wait for current task to execute completely and go for next step
if synchronous=False then wait till current execution to finish completely.

Please correct me if I am wrong.

Suggested change
: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 synchronous: What should happen if the server returns an HTTP
202 (accepted) status code? Immediately return the server's response
if synchronous is ``True``. Wait for the task to complete otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's exaclty the opposite - synchronous means we wait until the task is finished.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see every nailgun entities define doc string in same way.

: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()
kwargs.update(self._server_config.get_client_kwargs())
response = client.post(self.path('content_verify_checksum'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def path(self, which=None):
"""Extend ``nailgun.entity_mixins.Entity.path``.

Expand All @@ -1037,6 +1055,8 @@ def path(self, which=None):
/capsules/<id>/content/update_counts
content_reclaim_space
/capsules/<id>/content/reclaim_space
content_verify_checksum
/capsules/<id>/content/verify_checksum

``super`` is called otherwise.

Expand Down Expand Up @@ -2596,11 +2616,13 @@ def path(self, which=None):
/content_view_versions/incremental_update
promote
/content_view_versions/<id>/promote
verify_checksum
/content_view_versions/<id>/verify_checksum

``super`` is called otherwise.

"""
if which in ("incremental_update", "promote"):
if which in ("incremental_update", "promote", "verify_checksum"):
prefix = "base" if which == "incremental_update" else "self"
return f"{super().path(prefix)}/{which}"
return super().path(which)
Expand Down Expand Up @@ -2643,6 +2665,25 @@ def promote(self, synchronous=True, timeout=None, **kwargs):
response = client.post(self.path('promote'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def verify_checksum(self, synchronous=True, timeout=None, **kwargs):
"""Verify checksum of repository contents in the content view version.

: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)


class ContentViewFilterRule(
Entity,
Expand Down Expand Up @@ -6296,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 @@ -6380,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 @@ -6828,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 @@ -6843,6 +6907,7 @@ def path(self, which=None):
'module_streams',
'remove_content',
'sync',
'verify_checksum',
'import_uploads',
'upload_content',
):
Expand Down Expand Up @@ -6913,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
9 changes: 9 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def test_id_and_which(self):
(entities.ContentView, 'copy'),
(entities.ContentView, 'publish'),
(entities.ContentViewVersion, 'promote'),
(entities.ContentViewVersion, 'verify_checksum'),
(entities.DiscoveredHost, 'auto_provision'),
(entities.DiscoveredHost, 'refresh_facts'),
(entities.DiscoveredHost, 'reboot'),
Expand Down Expand Up @@ -346,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 @@ -398,6 +400,7 @@ def test_no_such_path_error(self):
(entities.ContentView, 'content_view_versions'),
(entities.ContentView, 'publish'),
(entities.ContentViewVersion, 'promote'),
(entities.ContentViewVersion, 'verify_checksum'),
(entities.ForemanTask, 'self'),
(entities.HostGroup, 'rebuild_config'),
(entities.Organization, 'products'),
Expand All @@ -413,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 @@ -569,6 +573,7 @@ def test_capsule(self):
'content_counts',
'content_update_counts',
'content_reclaim_space',
'content_verify_checksum',
):
with self.subTest(which):
path = capsule.path(which)
Expand Down Expand Up @@ -2110,6 +2115,7 @@ def setUpClass(cls):
(entities.Capsule(**generic).content_counts, 'get'),
(entities.Capsule(**generic).content_update_counts, 'post'),
(entities.Capsule(**generic).content_reclaim_space, 'post'),
(entities.Capsule(**generic).content_verify_checksum, 'post'),
(entities.Role(**generic).clone, 'post'),
(entities.ProvisioningTemplate(**generic).build_pxe_default, 'post'),
(entities.ProvisioningTemplate(**generic).clone, 'post'),
Expand All @@ -2118,6 +2124,7 @@ def setUpClass(cls):
(entities.ContentView(**generic).publish, 'post'),
(entities.ContentViewVersion(**generic).incremental_update, 'post'),
(entities.ContentViewVersion(**generic).promote, 'post'),
(entities.ContentViewVersion(**generic).verify_checksum, 'post'),
(entities.DiscoveredHost(cfg).facts, 'post'),
(entities.DiscoveredHost(**generic).refresh_facts, 'put'),
(entities.DiscoveredHost(**generic).reboot, 'put'),
Expand Down Expand Up @@ -2154,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 @@ -2162,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
Loading