From 95647ef68ef6e7aa7870b88a45458b67279f18e1 Mon Sep 17 00:00:00 2001 From: Vladimir Sedmik Date: Fri, 19 Apr 2024 18:23:34 +0200 Subject: [PATCH] Add new verify_checksum endpoints --- nailgun/entities.py | 44 ++++++++++++++++++++++++++++++++++++++++-- tests/test_entities.py | 5 +++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/nailgun/entities.py b/nailgun/entities.py index 20601ffc..034c4b1a 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -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``. @@ -1037,7 +1055,8 @@ def path(self, which=None): /capsules//content/update_counts content_reclaim_space /capsules//content/reclaim_space - + content_verify_checksum + /capsules//content/verify_checksum ``super`` is called otherwise. """ @@ -2596,11 +2615,13 @@ def path(self, which=None): /content_view_versions/incremental_update promote /content_view_versions//promote + verify_checksum + /content_view_versions//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) @@ -2643,6 +2664,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, diff --git a/tests/test_entities.py b/tests/test_entities.py index a20fb636..1f9d568f 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -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'), @@ -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'), @@ -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) @@ -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'), @@ -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'),