Skip to content

Commit

Permalink
Add new verify_checksum endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik committed Apr 19, 2024
1 parent 95b3ce1 commit 78a6886
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
44 changes: 42 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.
: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,7 +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 @@ -2518,11 +2537,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 @@ -2565,6 +2586,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
5 changes: 5 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 @@ -398,6 +399,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 Down Expand Up @@ -569,6 +571,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 +2113,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 +2122,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

0 comments on commit 78a6886

Please sign in to comment.