Skip to content

Commit

Permalink
Add test case to trigger the reclaim_space task (#14397)
Browse files Browse the repository at this point in the history
* Add test case to trigger the reclaim_space task

* Use apypie for apidoc parsing

* Address improvement suggestions, rebase
  • Loading branch information
vsedmik authored Mar 27, 2024
1 parent 7bd2a07 commit ac4b0cf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version updates managed by dependabot

apypie==0.4.0
betelgeuse==1.11.0
broker[docker]==0.4.9
cryptography==42.0.5
Expand Down
15 changes: 15 additions & 0 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from urllib.parse import urljoin, urlparse, urlunsplit
import warnings

import apypie
from box import Box
from broker import Broker
from broker.hosts import Host
Expand Down Expand Up @@ -1762,6 +1763,7 @@ def __init__(self, hostname=None, **kwargs):
# create dummy classes for later population
self._api = type('api', (), {'_configured': False})
self._cli = type('cli', (), {'_configured': False})
self._apidoc = None
self.record_property = None

def _swap_nailgun(self, new_version):
Expand Down Expand Up @@ -1815,6 +1817,19 @@ class DecClass(cls):
self._api._configured = True
return self._api

@property
def apidoc(self):
"""Provide Satellite's apidoc via apypie"""
if not self._apidoc:
self._apidoc = apypie.Api(
uri=self.url,
username=settings.server.admin_username,
password=settings.server.admin_password,
api_version=2,
verify_ssl=settings.server.verify_ca,
).apidoc
return self._apidoc

@property
def cli(self):
"""Import all robottelo cli entities and wrap them under self.cli"""
Expand Down
52 changes: 52 additions & 0 deletions tests/foreman/api/test_capsulecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1715,3 +1715,55 @@ def test_positive_read_with_non_admin_user(
server_config=sc, id=module_capsule_configured.nailgun_capsule.id
).read()
assert res.name == module_capsule_configured.hostname, 'External Capsule not found.'

def test_positive_reclaim_space(
self,
target_sat,
module_capsule_configured,
):
"""Verify the reclaim_space endpoint spawns the Reclaim space task
and apidoc references the endpoint correctly.
:id: eb16ed53-0489-4bb9-a0da-8d857a1c7d06
:setup:
1. A registered external Capsule.
:steps:
1. Trigger the reclaim space task via API, check it succeeds.
2. Check the apidoc references the correct endpoint.
:expectedresults:
1. Reclaim_space endpoint spawns the Reclaim space task and it succeeds.
2. Apidoc references the correct endpoint.
:CaseImportance: Medium
:BZ: 2218179
:customerscenario: true
"""
# Trigger the reclaim space task via API, check it succeeds
task = module_capsule_configured.nailgun_capsule.content_reclaim_space()
assert task, 'No task was created for reclaim space.'
assert (
'Actions::Pulp3::CapsuleContent::ReclaimSpace' in task['label']
), 'Unexpected task triggered'
assert 'success' in task['result'], 'Reclaim task did not succeed'

# Check the apidoc references the correct endpoint
try:
reclaim_doc = next(
method
for method in target_sat.apidoc['docs']['resources']['capsule_content']['methods']
if '/apidoc/v2/capsule_content/reclaim_space' in method['doc_url']
)
except StopIteration:
raise AssertionError(
'Could not find the reclaim_space apidoc at the expected path.'
) from None
assert len(reclaim_doc['apis']) == 1
assert reclaim_doc['apis'][0]['http_method'] == 'POST', 'POST method was expected.'
assert (
reclaim_doc['apis'][0]['api_url'] == '/katello/api/capsules/:id/content/reclaim_space'
), 'Documented path did not meet the expectation.'

0 comments on commit ac4b0cf

Please sign in to comment.