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 helper to delete LCE from capsule #935

Merged
merged 1 commit into from
Jun 20, 2023
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
28 changes: 28 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,34 @@ def content_add_lifecycle_environment(self, synchronous=True, timeout=None, **kw
response = client.post(self.path('content_lifecycle_environments'), **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def content_delete_lifecycle_environment(self, synchronous=True, timeout=None, **kwargs):
"""Helper to disassociate lifecycle environment from capsule

Here is an example of how to use this method::
capsule.content_delete_lifecycle_environment(data={'environment_id': lce.id})

Constructs path:
/katello/api/capsules/:capsule_id/content/lifecycle_environments/:id

: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())
path = (
f'{self.path("content_lifecycle_environments")}/{kwargs["data"].pop("environment_id")}'
)
response = client.delete(path, **kwargs)
return _handle_response(response, self._server_config, synchronous, timeout)

def content_lifecycle_environments(self, synchronous=True, timeout=None, **kwargs):
"""Helper to get all the lifecycle environments, associated with
capsule
Expand Down
6 changes: 6 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,9 +2206,15 @@ def setUpClass(cls):
(entities.Template(**generic).exports, 'post'),
(entities.VirtWhoConfig(**generic).deploy_script, 'get'),
)
capsule = {'server_config': cfg, 'id': 1}
repo_set = {'server_config': cfg, 'id': 1, 'product': 2}
snapshot = {'server_config': cfg, 'id': 'snapshot-1', 'host': 1}
cls.intelligent_methods_requests = (
(
entities.Capsule(**capsule).content_delete_lifecycle_environment,
'delete',
{'environment_id': 2},
),
(entities.RepositorySet(**repo_set).available_repositories, 'get', {'product_id': 2}),
(entities.RepositorySet(**repo_set).disable, 'put', {'product_id': 2}),
(entities.RepositorySet(**repo_set).enable, 'put', {'product_id': 2}),
Expand Down