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 support for delete with args, and republish_repositories endpoints #1209

Merged
merged 3 commits into from
Aug 7, 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
43 changes: 42 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,11 +2618,13 @@ def path(self, which=None):
/content_view_versions/<id>/promote
verify_checksum
/content_view_versions/<id>/verify_checksum
republish_repositories
/content_view_versions/<id>/republish_repositories

``super`` is called otherwise.

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

def republish_repositories(self, synchronous=True, timeout=None, **kwargs):
"""Force a republish of the version's repositories metadata.

: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('republish_repositories'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)


class ContentViewFilterRule(
Entity,
Expand Down Expand Up @@ -6839,6 +6860,7 @@ def __init__(self, server_config=None, **kwargs):
default='yum',
required=True,
),
'is_container_push': entity_fields.BooleanField(default=False),
'container_repository_name': entity_fields.StringField(),
# Just setting `str_type='alpha'` will fail with this error:
# {"docker_upstream_name":["must be a valid docker name"]}}
Expand Down Expand Up @@ -6973,6 +6995,25 @@ def docker_manifests(self, synchronous=True, timeout=None, **kwargs):
response = client.get(self.path('docker_manifests'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def delete_with_args(self, synchronous=True, timeout=None, **kwargs):
"""Delete a repository, and respect args passed to it.

: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.delete(self.path(), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def errata(self, synchronous=True, timeout=None, **kwargs):
"""List errata inside repository.

Expand Down
1 change: 1 addition & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def test_id_and_which(self):
(entities.ContentView, 'publish'),
(entities.ContentViewVersion, 'promote'),
(entities.ContentViewVersion, 'verify_checksum'),
(entities.ContentViewVersion, 'republish_repositories'),
(entities.DiscoveredHost, 'auto_provision'),
(entities.DiscoveredHost, 'refresh_facts'),
(entities.DiscoveredHost, 'reboot'),
Expand Down