Skip to content

Commit

Permalink
Remove delete content units.
Browse files Browse the repository at this point in the history
In order to avoid a race condition it was removed the feature to remove
content units.

See: https://pulp.plan.io/issues/3445

A new endpoint was added `/api/v3/orphans/` and using the
DELETE method and this endpoint all orphan content units will be
removed. This endpoint also removes orphan artifact units.

Adjust pulp-smash to this new scenario.

Remove:
 * clean_content_units
 * clean_artifacts

Add:
 * delete_orphan_units

Closes:#926

Related:#914
  • Loading branch information
Kersom authored and Ichimonji10 committed Apr 6, 2018
1 parent f93f19a commit 92014a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 37 deletions.
2 changes: 2 additions & 0 deletions pulp_smash/tests/pulp3/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

JWT_PATH = urljoin(BASE_PATH, 'jwt/')

ORPHANS_PATH = urljoin(BASE_PATH, 'orphans/')

PUBLICATIONS_PATH = urljoin(BASE_PATH, 'publications/')

REPO_PATH = urljoin(BASE_PATH, 'repositories/')
Expand Down
9 changes: 2 additions & 7 deletions pulp_smash/tests/pulp3/file/api_v3/test_crd_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pulp_smash.constants import FILE_URL
from pulp_smash.tests.pulp3.constants import ARTIFACTS_PATH
from pulp_smash.tests.pulp3.file.utils import set_up_module as setUpModule # noqa pylint:disable=unused-import
from pulp_smash.tests.pulp3.utils import clean_artifacts, get_auth
from pulp_smash.tests.pulp3.utils import delete_orphans, get_auth


class ArtifactTestCase(unittest.TestCase, utils.SmokeTest):
Expand All @@ -20,6 +20,7 @@ def setUpClass(cls):
"""Create class-wide variable."""
cls.artifact = {}
cls.cfg = config.get_config()
delete_orphans(cls.cfg)
cls.client = api.Client(cls.cfg, api.json_handler)
cls.client.request_kwargs['auth'] = get_auth()

Expand All @@ -43,12 +44,6 @@ def test_01_create(self):
the checksum of the file that was uploaded.
"""
files = {'file': utils.http_get(FILE_URL)}

# To avoid upload of duplicates in pulp. This function call may be
# removed after pulp3 is able to handle duplicates, and how to delete
# artifacts that are content units as well.
clean_artifacts(self.cfg)

type(self).artifact = self.client.post(ARTIFACTS_PATH, files=files)
self.assertEqual(
self.artifact['sha256'],
Expand Down
13 changes: 3 additions & 10 deletions pulp_smash/tests/pulp3/file/api_v3/test_crud_content_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pulp_smash.tests.pulp3.file.utils import set_up_module as setUpModule # noqa pylint:disable=unused-import
from pulp_smash.tests.pulp3.pulpcore.utils import gen_repo
from pulp_smash.tests.pulp3.utils import (
clean_artifacts,
delete_orphans,
get_auth,
get_content,
sync_repo,
Expand All @@ -38,7 +38,7 @@ class ContentUnitTestCase(unittest.TestCase, utils.SmokeTest):
def setUpClass(cls):
"""Create class-wide variable."""
cls.cfg = config.get_config()
clean_artifacts(cls.cfg)
delete_orphans(cls.cfg)
cls.content_unit = {}
cls.client = api.Client(cls.cfg, api.json_handler)
cls.client.request_kwargs['auth'] = get_auth()
Expand All @@ -48,7 +48,7 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
"""Clean class-wide variable."""
cls.client.delete(cls.artifact['_href'])
delete_orphans(cls.cfg)

def test_01_create_content_unit(self):
"""Create content unit."""
Expand Down Expand Up @@ -86,13 +86,6 @@ def test_03_fully_update(self):
with self.assertRaises(HTTPError):
self.client.put(self.content_unit['_href'], attrs)

@selectors.skip_if(bool, 'content_unit', False)
def test_04_delete_content_unit(self):
"""Delete a content unit."""
self.client.delete(self.content_unit['_href'])
with self.assertRaises(HTTPError):
self.client.get(self.content_unit['_href'])


def _gen_content_unit_attrs(artifact):
"""Generate a dict with content unit attributes.
Expand Down
27 changes: 7 additions & 20 deletions pulp_smash/tests/pulp3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

from pulp_smash import api, config, selectors
from pulp_smash.tests.pulp3.constants import (
ARTIFACTS_PATH,
FILE_CONTENT_PATH,
JWT_PATH,
ORPHANS_PATH,
STATUS_PATH,
)

Expand Down Expand Up @@ -251,31 +250,19 @@ def get_content_unit_paths(repo):
]


def clean_artifacts(cfg=None):
"""Clean all artifacts present in pulp.
:param pulp_smash.config.PulpSmashConfig cfg: Information about the Pulp
host.
"""
if cfg is None:
cfg = config.get_config()
clean_content_units(cfg)
client = api.Client(cfg, api.json_handler)
for artifact in client.get(ARTIFACTS_PATH)['results']:
client.delete(artifact['_href'])


def clean_content_units(cfg=None):
def delete_orphans(cfg=None):
"""Clean all content units present in pulp.
An orphaned artifact is an artifact that is not in any content units.
An orphaned content unit is a content unit that is not in any repository
version.
:param pulp_smash.config.PulpSmashConfig cfg: Information about the Pulp
host.
"""
if cfg is None:
cfg = config.get_config()
client = api.Client(cfg, api.json_handler)
for content_unit in client.get(FILE_CONTENT_PATH)['results']:
client.delete(content_unit['_href'])
api.Client(cfg, api.safe_handler).delete(ORPHANS_PATH)


def get_repo_versions(repo):
Expand Down

0 comments on commit 92014a3

Please sign in to comment.