-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes: #327
- Loading branch information
Showing
5 changed files
with
117 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rewritten test_sync.py using pytest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,103 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
import unittest | ||
|
||
from pulp_smash.pulp3.bindings import delete_orphans, monitor_task | ||
from pulp_smash.pulp3.utils import gen_repo, gen_distribution | ||
import pytest | ||
|
||
from pulp_ostree.tests.functional.utils import ( | ||
gen_ostree_client, | ||
gen_ostree_remote, | ||
init_local_repo_with_remote, | ||
validate_repo_integrity, | ||
) | ||
|
||
from pulpcore.client.pulp_ostree import ( | ||
DistributionsOstreeApi, | ||
OstreeOstreeDistribution, | ||
RepositoriesOstreeApi, | ||
RepositoriesOstreeVersionsApi, | ||
RepositorySyncURL, | ||
RemotesOstreeApi, | ||
ContentRefsApi, | ||
) | ||
|
||
|
||
class BasicSyncTestCase(unittest.TestCase): | ||
"""A test case that verifies the syncing scenario.""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Initialize class-wide variables.""" | ||
client_api = gen_ostree_client() | ||
cls.repositories_api = RepositoriesOstreeApi(client_api) | ||
cls.versions_api = RepositoriesOstreeVersionsApi(client_api) | ||
cls.remotes_api = RemotesOstreeApi(client_api) | ||
cls.distributions_api = DistributionsOstreeApi(client_api) | ||
cls.refs_api = ContentRefsApi(client_api) | ||
|
||
cls.original_dir = os.getcwd() | ||
cls.tmpdir = tempfile.TemporaryDirectory() | ||
os.chdir(cls.tmpdir.name) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Clean orphaned content after finishing the tests.""" | ||
delete_orphans() | ||
os.chdir(cls.original_dir) | ||
cls.tmpdir.cleanup() | ||
|
||
def setUp(self): | ||
"""Clean orphaned content before each test.""" | ||
delete_orphans() | ||
|
||
def test_on_demand_sync(self): | ||
"""Test on_demand synchronization.""" | ||
self.sync("on_demand") | ||
|
||
def test_immediate_sync(self): | ||
"""Test immediate synchronization.""" | ||
self.sync("immediate") | ||
|
||
def sync(self, policy): | ||
"""Synchronize content from a remote repository and check validity of a Pulp repository.""" | ||
repo = self.repositories_api.create(gen_repo()) | ||
self.addCleanup(self.repositories_api.delete, repo.pulp_href) | ||
|
||
body = gen_ostree_remote(depth=0, policy=policy) | ||
remote = self.remotes_api.create(body) | ||
self.addCleanup(self.remotes_api.delete, remote.pulp_href) | ||
@pytest.fixture | ||
def sync( | ||
ostree_distribution_factory, | ||
ostree_distributions_api_client, | ||
sync_repo_version, | ||
tmp_path, | ||
): | ||
"""Synchronize content from a remote repository and check validity of a Pulp repository.""" | ||
|
||
def _sync( | ||
policy, | ||
): | ||
# 1. synchronize content from the remote | ||
self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") | ||
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) | ||
response = self.repositories_api.sync(repo.pulp_href, repository_sync_data) | ||
repo_version = monitor_task(response.task).created_resources[0] | ||
|
||
repository_version = self.versions_api.read(repo_version) | ||
added_content = repository_version.content_summary.added | ||
repo_version, remote, repo = sync_repo_version(policy=policy) | ||
added_content = repo_version.content_summary.added | ||
|
||
# 2. validate newly added content | ||
self.assertEqual(added_content["ostree.config"]["count"], 1) | ||
self.assertEqual(added_content["ostree.refs"]["count"], 2) | ||
self.assertEqual(added_content["ostree.commit"]["count"], 2) | ||
self.assertEqual(added_content["ostree.object"]["count"], 3) | ||
self.assertEqual(added_content["ostree.summary"]["count"], 1) | ||
assert added_content["ostree.config"]["count"] == 1 | ||
assert added_content["ostree.refs"]["count"] == 2 | ||
assert added_content["ostree.commit"]["count"] == 2 | ||
assert added_content["ostree.object"]["count"] == 3 | ||
assert added_content["ostree.summary"]["count"] == 1 | ||
|
||
# 3. synchronize from the same remote once again | ||
previous_version_href = repo_version | ||
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) | ||
sync_response = self.repositories_api.sync(repo.pulp_href, repository_sync_data) | ||
monitor_task(sync_response.task) | ||
repo = self.repositories_api.read(repo.pulp_href) | ||
previous_version_href = repo_version.pulp_href | ||
_, remote, repo = sync_repo_version(remote=remote, repo=repo, policy=policy) | ||
|
||
self.assertEqual(previous_version_href, repo.latest_version_href) | ||
assert previous_version_href == repo.latest_version_href | ||
|
||
# 4. publish the synced content | ||
distribution_data = OstreeOstreeDistribution(**gen_distribution(repository=repo.pulp_href)) | ||
response = self.distributions_api.create(distribution_data) | ||
distribution = monitor_task(response.task).created_resources[0] | ||
self.addCleanup(self.distributions_api.delete, distribution) | ||
|
||
ostree_repo_path = self.distributions_api.read(distribution).base_url | ||
distribution = ostree_distribution_factory(repository=repo.pulp_href) | ||
ostree_repo_path = ostree_distributions_api_client.read(distribution.pulp_href).base_url | ||
|
||
# 5. initialize a local OSTree repository and pull the content from Pulp | ||
remote_name = init_local_repo_with_remote(remote.name, ostree_repo_path) | ||
self.addCleanup(shutil.rmtree, remote.name) | ||
validate_repo_integrity(remote.name, f"{remote_name}:rawhide") | ||
validate_repo_integrity(remote.name, f"{remote_name}:stable") | ||
|
||
def test_filter_rawhide_ref_sync(self): | ||
"""Synchronize content from a remote repository considering only a specific ref.""" | ||
repo = self.repositories_api.create(gen_repo()) | ||
self.addCleanup(self.repositories_api.delete, repo.pulp_href) | ||
|
||
body = gen_ostree_remote(depth=0, include_refs=["rawhide"], exclude_refs=["stable"]) | ||
remote = self.remotes_api.create(body) | ||
self.addCleanup(self.remotes_api.delete, remote.pulp_href) | ||
|
||
self.assertEqual(remote.include_refs, ["rawhide"]) | ||
self.assertEqual(remote.exclude_refs, ["stable"]) | ||
|
||
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) | ||
response = self.repositories_api.sync(repo.pulp_href, repository_sync_data) | ||
repo_version = monitor_task(response.task).created_resources[0] | ||
|
||
refs = self.refs_api.list(repository_version_added=repo_version).results | ||
self.assertEqual(len(refs), 1) | ||
self.assertEqual(refs[0].name, "rawhide") | ||
|
||
def test_exclude_all_refs_sync(self): | ||
"""Synchronize content from a remote repository when a user excludes all refs.""" | ||
repo = self.repositories_api.create(gen_repo()) | ||
self.addCleanup(self.repositories_api.delete, repo.pulp_href) | ||
|
||
body = gen_ostree_remote(depth=0, exclude_refs=["*"]) | ||
remote = self.remotes_api.create(body) | ||
self.addCleanup(self.remotes_api.delete, remote.pulp_href) | ||
|
||
self.assertEqual(remote.include_refs, None) | ||
self.assertEqual(remote.exclude_refs, ["*"]) | ||
|
||
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) | ||
response = self.repositories_api.sync(repo.pulp_href, repository_sync_data) | ||
repo_version = monitor_task(response.task).created_resources[0] | ||
|
||
repository_version = self.versions_api.read(repo_version) | ||
added_content = repository_version.content_summary.added | ||
|
||
self.assertEqual(added_content["ostree.config"]["count"], 1) | ||
self.assertEqual(added_content["ostree.summary"]["count"], 1) | ||
self.assertRaises(KeyError, lambda: added_content["ostree.refs"]) | ||
self.assertRaises(KeyError, lambda: added_content["ostree.commit"]) | ||
self.assertRaises(KeyError, lambda: added_content["ostree.object"]) | ||
remote_name = init_local_repo_with_remote(tmp_path / remote.name, ostree_repo_path) | ||
validate_repo_integrity(tmp_path / remote.name, f"{remote_name}:rawhide") | ||
validate_repo_integrity(tmp_path / remote.name, f"{remote_name}:stable") | ||
|
||
return _sync | ||
|
||
|
||
@pytest.mark.parallel | ||
def test_on_demand_sync(sync): | ||
"""Test on_demand synchronization.""" | ||
sync("on_demand") | ||
|
||
|
||
@pytest.mark.parallel | ||
def test_immediate_sync(sync): | ||
"""Test immediate synchronization.""" | ||
sync("immediate") | ||
|
||
|
||
@pytest.mark.parallel | ||
def test_filter_rawhide_ref_sync( | ||
ostree_content_refs_api_client, | ||
ostree_remote_factory, | ||
ostree_repository_factory, | ||
sync_repo_version, | ||
): | ||
"""Synchronize content from a remote repository considering only a specific ref.""" | ||
repo = ostree_repository_factory() | ||
remote = ostree_remote_factory(depth=0, include_refs=["rawhide"], exclude_refs=["stable"]) | ||
assert remote.include_refs == ["rawhide"] | ||
assert remote.exclude_refs == ["stable"] | ||
|
||
repo_version, _, _ = sync_repo_version(repo=repo, remote=remote) | ||
refs = ostree_content_refs_api_client.list( | ||
repository_version_added=repo_version.pulp_href | ||
).results | ||
assert len(refs) == 1 | ||
assert refs[0].name == "rawhide" | ||
|
||
|
||
@pytest.mark.parallel | ||
def test_exclude_all_refs_sync(ostree_remote_factory, ostree_repository_factory, sync_repo_version): | ||
"""Synchronize content from a remote repository when a user excludes all refs.""" | ||
repo = ostree_repository_factory() | ||
remote = ostree_remote_factory(depth=0, exclude_refs=["*"]) | ||
|
||
assert remote.include_refs is None | ||
assert remote.exclude_refs == ["*"] | ||
|
||
repository_version, _, _ = sync_repo_version(repo=repo, remote=remote) | ||
added_content = repository_version.content_summary.added | ||
|
||
assert added_content["ostree.config"]["count"] == 1 | ||
assert added_content["ostree.summary"]["count"] == 1 | ||
|
||
with pytest.raises(KeyError): | ||
added_content["ostree.refs"] | ||
with pytest.raises(KeyError): | ||
added_content["ostree.commit"] | ||
with pytest.raises(KeyError): | ||
added_content["ostree.object"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters