From 10d8f47478e180de7475b1533c519c431930684c Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Fri, 8 Dec 2023 17:28:38 +0100 Subject: [PATCH] Make pytest plugin resiliant to missing bindings This also provides new pulpcore_bindings and file_bindings fixtures that will provide all the bindings apis preconfigured. fixes #4751 --- CHANGES/4751.misc | 1 + pulp_file/pytest_plugin.py | 78 ++-- pulpcore/tests/functional/__init__.py | 404 +++++++++++------- .../functional/api/test_access_policy.py | 56 +-- .../tests/functional/api/test_api_docs.py | 12 +- .../functional/api/test_correlation_id.py | 6 +- .../tests/functional/api/test_replication.py | 43 +- pulpcore/tests/functional/api/test_status.py | 14 +- pulpcore/tests/functional/api/test_tasking.py | 80 ++-- pulpcore/tests/functional/api/test_upload.py | 1 - .../api/using_plugin/test_contentguard.py | 60 ++- .../api/using_plugin/test_labels.py | 10 +- .../api/using_plugin/test_orphans.py | 41 +- .../functional/api/using_plugin/test_purge.py | 78 ++-- .../api/using_plugin/test_repo_versions.py | 17 +- .../functional/api/using_plugin/test_tasks.py | 9 +- .../gpg_ascii_armor_signing_service.py | 42 +- pulpcore/tests/functional/utils.py | 15 + 18 files changed, 541 insertions(+), 426 deletions(-) create mode 100644 CHANGES/4751.misc diff --git a/CHANGES/4751.misc b/CHANGES/4751.misc new file mode 100644 index 00000000000..4984745dee4 --- /dev/null +++ b/CHANGES/4751.misc @@ -0,0 +1 @@ +Changed bindings fixtures in the pytest plugin to load lazily. diff --git a/pulp_file/pytest_plugin.py b/pulp_file/pytest_plugin.py index 9c13205cbda..96d82ca0790 100644 --- a/pulp_file/pytest_plugin.py +++ b/pulp_file/pytest_plugin.py @@ -1,69 +1,77 @@ import os import uuid import subprocess +import warnings from collections import defaultdict from pathlib import Path import aiofiles import pytest from aiohttp import web -from pulpcore.client.pulp_file import ( - AcsFileApi, - ApiClient, - ContentFilesApi, - DistributionsFileApi, - PublicationsFileApi, - RemotesFileApi, - RepositoriesFileApi, - RepositoriesFileVersionsApi, -) - -from pulpcore.tests.functional.utils import generate_iso, generate_manifest + +from pulpcore.tests.functional.utils import BindingsNamespace, generate_iso, generate_manifest # Api Bindings fixtures @pytest.fixture(scope="session") -def file_client(_api_client_set, bindings_cfg): - api_client = ApiClient(bindings_cfg) - _api_client_set.add(api_client) - yield api_client - _api_client_set.remove(api_client) +def file_bindings(_api_client_set, bindings_cfg): + """ + A namespace providing preconfigured pulp_file api clients. + + e.g. `file_bindings.RepositoriesFileApi.list()`. + """ + from pulpcore.client import pulp_file as file_bindings_module + + file_client = file_bindings_module.ApiClient(bindings_cfg) + _api_client_set.add(file_client) + yield BindingsNamespace(file_bindings_module, file_client) + _api_client_set.remove(file_client) + + +# TODO Deprecate all the api_client fixtures below. @pytest.fixture(scope="session") -def file_acs_api_client(file_client): - return AcsFileApi(file_client) +def file_acs_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.AcsFileApi @pytest.fixture(scope="session") -def file_content_api_client(file_client): - return ContentFilesApi(file_client) +def file_content_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.ContentFilesApi @pytest.fixture(scope="session") -def file_distribution_api_client(file_client): - return DistributionsFileApi(file_client) +def file_distribution_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.DistributionsFileApi @pytest.fixture(scope="session") -def file_publication_api_client(file_client): - return PublicationsFileApi(file_client) +def file_publication_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.PublicationsFileApi @pytest.fixture(scope="session") -def file_repository_api_client(file_client): - return RepositoriesFileApi(file_client) +def file_repository_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.RepositoriesFileApi @pytest.fixture(scope="session") -def file_repository_version_api_client(file_client): - return RepositoriesFileVersionsApi(file_client) +def file_repository_version_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.RepositoriesFileVersionsApi @pytest.fixture(scope="session") -def file_remote_api_client(file_client): - return RemotesFileApi(file_client) +def file_remote_api_client(file_bindings): + warnings.warn("This fixture is deprecated. Use `file_bindings` instead.", DeprecationWarning) + return file_bindings.RemotesFileApi # Factory fixtures @@ -75,11 +83,13 @@ def file_random_content_unit(file_content_unit_with_name_factory): @pytest.fixture -def file_content_unit_with_name_factory(file_content_api_client, random_artifact, monitor_task): +def file_content_unit_with_name_factory(file_bindings, random_artifact, monitor_task): def _file_content_unit_with_name_factory(name): artifact_attrs = {"artifact": random_artifact.pulp_href, "relative_path": name} - return file_content_api_client.read( - monitor_task(file_content_api_client.create(**artifact_attrs).task).created_resources[0] + return file_bindings.ContentFilesApi.read( + monitor_task( + file_bindings.ContentFilesApi.create(**artifact_attrs).task + ).created_resources[0] ) return _file_content_unit_with_name_factory diff --git a/pulpcore/tests/functional/__init__.py b/pulpcore/tests/functional/__init__.py index 214f1e7fc55..120c5d4bfb2 100644 --- a/pulpcore/tests/functional/__init__.py +++ b/pulpcore/tests/functional/__init__.py @@ -10,8 +10,6 @@ import uuid import warnings -import trustme -import proxy import pytest from aiohttp import web @@ -20,60 +18,16 @@ from packaging.version import parse as parse_version from time import sleep from yarl import URL -from opentelemetry.proto.trace.v1.trace_pb2 import TracesData from pulpcore.tests.functional.utils import ( SLEEP_TIME, TASK_TIMEOUT, + BindingsNamespace, PulpTaskError, PulpTaskGroupError, add_recording_route, ) -from pulpcore.client.pulpcore import ( - Configuration, - AccessPoliciesApi, - ApiClient, - ApiException, - ArtifactsApi, - ContentApi, - ContentguardsApi, - ContentguardsRbacApi, - ContentguardsCompositeApi, - ContentguardsContentRedirectApi, - ContentguardsHeaderApi, - DomainsApi, - DistributionsApi, - ExportersPulpApi, - ExportersPulpExportsApi, - ExportersFilesystemApi, - ExportersFilesystemExportsApi, - GroupsApi, - GroupsRolesApi, - GroupsUsersApi, - ImportersPulpApi, - ImportersPulpImportsApi, - ImportersPulpImportCheckApi, - OrphansCleanupApi, - PublicationsApi, - RemotesApi, - RepairApi, - RepositoriesApi, - RepositoryVersionsApi, - RepositoriesReclaimSpaceApi, - RolesApi, - SigningServicesApi, - StatusApi, - TaskGroupsApi, - TasksApi, - TaskSchedulesApi, - UploadsApi, - UpstreamPulpsApi, - UsersApi, - UsersRolesApi, - WorkersApi, -) - from .gpg_ascii_armor_signing_service import ( _ascii_armored_detached_signing_service_name, ascii_armored_detached_signing_service, @@ -95,19 +49,6 @@ def __init__(self, awaitable): self.awaitable = awaitable -def get_bindings_config(): - api_protocol = os.environ.get("API_PROTOCOL", "https") - api_host = os.environ.get("API_HOST", "pulp") - api_port = os.environ.get("API_PORT", "443") - configuration = Configuration( - host=f"{api_protocol}://{api_host}:{api_port}", - username=os.environ.get("ADMIN_USERNAME", "admin"), - password=os.environ.get("ADMIN_PASSWORD", "password"), - ) - configuration.safe_chars_for_path_param = "/" - return configuration - - def pytest_configure(config): config.addinivalue_line( "markers", @@ -139,12 +80,23 @@ class FixturesConfig: return FixturesConfig() -# API Clients +# API Bindings fixtures @pytest.fixture(scope="session") def bindings_cfg(): - return get_bindings_config() + from pulpcore.client.pulpcore import Configuration + + api_protocol = os.environ.get("API_PROTOCOL", "https") + api_host = os.environ.get("API_HOST", "pulp") + api_port = os.environ.get("API_PORT", "443") + configuration = Configuration( + host=f"{api_protocol}://{api_host}:{api_port}", + username=os.environ.get("ADMIN_USERNAME", "admin"), + password=os.environ.get("ADMIN_PASSWORD", "password"), + ) + configuration.safe_chars_for_path_param = "/" + return configuration @pytest.fixture(scope="session") @@ -169,202 +121,334 @@ def _patch_cid_user_agent(_api_client_set, cid, monkeypatch): @pytest.fixture(scope="session") -def pulpcore_client(_api_client_set, bindings_cfg): - api_client = ApiClient(bindings_cfg) - _api_client_set.add(api_client) - yield api_client - _api_client_set.remove(api_client) +def pulpcore_bindings(_api_client_set, bindings_cfg): + """ + A namespace providing preconfigured pulpcore api clients. + + e.g. `pulpcore_bindings.WorkersApi.list()`. + """ + from pulpcore.client import pulpcore as pulpcore_bindings_module + + pulpcore_client = pulpcore_bindings_module.ApiClient(bindings_cfg) + _api_client_set.add(pulpcore_client) + yield BindingsNamespace(pulpcore_bindings_module, pulpcore_client) + _api_client_set.remove(pulpcore_client) + + +# TODO Deprecate all the api_client fixtures below. + + +@pytest.fixture(scope="session") +def pulpcore_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings.client` instead.", DeprecationWarning + ) + return pulpcore_bindings.client @pytest.fixture(scope="session") -def access_policies_api_client(pulpcore_client): - return AccessPoliciesApi(pulpcore_client) +def access_policies_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.AccessPoliciesApi @pytest.fixture(scope="session") -def tasks_api_client(pulpcore_client): - return TasksApi(pulpcore_client) +def tasks_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.TasksApi @pytest.fixture(scope="session") -def task_groups_api_client(pulpcore_client): - return TaskGroupsApi(pulpcore_client) +def task_groups_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.TaskGroupsApi @pytest.fixture(scope="session") -def workers_api_client(pulpcore_client): - return WorkersApi(pulpcore_client) +def workers_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.WorkersApi @pytest.fixture(scope="session") -def artifacts_api_client(pulpcore_client): - return ArtifactsApi(pulpcore_client) +def artifacts_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ArtifactsApi @pytest.fixture(scope="session") -def uploads_api_client(pulpcore_client): - return UploadsApi(pulpcore_client) +def uploads_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UploadsApi @pytest.fixture(scope="session") -def task_schedules_api_client(pulpcore_client): - return TaskSchedulesApi(pulpcore_client) +def task_schedules_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.TaskSchedulesApi @pytest.fixture(scope="session") -def status_api_client(pulpcore_client): - return StatusApi(pulpcore_client) +def status_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.StatusApi @pytest.fixture(scope="session") -def groups_api_client(pulpcore_client): - return GroupsApi(pulpcore_client) +def groups_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.GroupsApi @pytest.fixture(scope="session") -def groups_users_api_client(pulpcore_client): - return GroupsUsersApi(pulpcore_client) +def groups_users_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.GroupsUsersApi @pytest.fixture(scope="session") -def groups_roles_api_client(pulpcore_client): - return GroupsRolesApi(pulpcore_client) +def groups_roles_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.GroupsRolesApi @pytest.fixture(scope="session") -def users_api_client(pulpcore_client): - return UsersApi(pulpcore_client) +def users_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UsersApi @pytest.fixture(scope="session") -def users_roles_api_client(pulpcore_client): - return UsersRolesApi(pulpcore_client) +def users_roles_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UsersRolesApi @pytest.fixture(scope="session") -def roles_api_client(pulpcore_client): +def roles_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) "Provies the pulp core Roles API client object." - return RolesApi(pulpcore_client) + return pulpcore_bindings.RolesApi @pytest.fixture(scope="session") -def content_api_client(pulpcore_client): - return ContentApi(pulpcore_client) +def content_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentApi @pytest.fixture(scope="session") -def domains_api_client(pulpcore_client): - return DomainsApi(pulpcore_client) +def domains_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.DomainsApi @pytest.fixture(scope="session") -def distributions_api_client(pulpcore_client): - return DistributionsApi(pulpcore_client) +def distributions_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.DistributionsApi @pytest.fixture(scope="session") -def remotes_api_client(pulpcore_client): - return RemotesApi(pulpcore_client) +def remotes_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RemotesApi @pytest.fixture(scope="session") -def repositories_api_client(pulpcore_client): - return RepositoriesApi(pulpcore_client) +def repositories_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepositoriesApi @pytest.fixture(scope="session") -def repository_versions_api_client(pulpcore_client): - return RepositoryVersionsApi(pulpcore_client) +def repository_versions_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepositoryVersionsApi @pytest.fixture(scope="session") -def publications_api_client(pulpcore_client): - return PublicationsApi(pulpcore_client) +def publications_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.PublicationsApi @pytest.fixture(scope="session") -def exporters_pulp_api_client(pulpcore_client): - return ExportersPulpApi(pulpcore_client) +def exporters_pulp_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersPulpApi @pytest.fixture(scope="session") -def exporters_pulp_exports_api_client(pulpcore_client): - return ExportersPulpExportsApi(pulpcore_client) +def exporters_pulp_exports_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersPulpExportsApi @pytest.fixture(scope="session") -def exporters_filesystem_api_client(pulpcore_client): - return ExportersFilesystemApi(pulpcore_client) +def exporters_filesystem_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersFilesystemApi @pytest.fixture(scope="session") -def exporters_filesystem_exports_api_client(pulpcore_client): - return ExportersFilesystemExportsApi(pulpcore_client) +def exporters_filesystem_exports_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ExportersFilesystemExportsApi @pytest.fixture(scope="session") -def importers_pulp_api_client(pulpcore_client): - return ImportersPulpApi(pulpcore_client) +def importers_pulp_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ImportersPulpApi @pytest.fixture(scope="session") -def importers_pulp_imports_api_client(pulpcore_client): - return ImportersPulpImportsApi(pulpcore_client) +def importers_pulp_imports_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ImportersPulpImportsApi @pytest.fixture(scope="session") -def importers_pulp_imports_check_api_client(pulpcore_client): - return ImportersPulpImportCheckApi(pulpcore_client) +def importers_pulp_imports_check_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ImportersPulpImportCheckApi @pytest.fixture(scope="session") -def signing_service_api_client(pulpcore_client): - return SigningServicesApi(pulpcore_client) +def signing_service_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.SigningServicesApi @pytest.fixture(scope="session") -def content_guards_api_client(pulpcore_client): - return ContentguardsApi(pulpcore_client) +def content_guards_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsApi @pytest.fixture(scope="session") -def rbac_contentguard_api_client(pulpcore_client): - return ContentguardsRbacApi(pulpcore_client) +def rbac_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsRbacApi @pytest.fixture(scope="session") -def redirect_contentguard_api_client(pulpcore_client): - return ContentguardsContentRedirectApi(pulpcore_client) +def redirect_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsContentRedirectApi @pytest.fixture(scope="session") -def header_contentguard_api_client(pulpcore_client): - return ContentguardsHeaderApi(pulpcore_client) +def header_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsHeaderApi @pytest.fixture(scope="session") -def composite_contentguard_api_client(pulpcore_client): - return ContentguardsCompositeApi(pulpcore_client) +def composite_contentguard_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.ContentguardsCompositeApi @pytest.fixture(scope="session") -def orphans_cleanup_api_client(pulpcore_client): - return OrphansCleanupApi(pulpcore_client) +def orphans_cleanup_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.OrphansCleanupApi @pytest.fixture(scope="session") -def repositories_reclaim_space_api_client(pulpcore_client): - return RepositoriesReclaimSpaceApi(pulpcore_client) +def repositories_reclaim_space_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepositoriesReclaimSpaceApi @pytest.fixture(scope="session") -def repair_api_client(pulpcore_client): - return RepairApi(pulpcore_client) +def repair_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.RepairApi @pytest.fixture(scope="session") -def upstream_pulp_api_client(pulpcore_client): - return UpstreamPulpsApi(pulpcore_client) +def upstream_pulp_api_client(pulpcore_bindings): + warnings.warn( + "This fixture is deprecated. Use `pulpcore_bindings` instead.", DeprecationWarning + ) + return pulpcore_bindings.UpstreamPulpsApi # Threaded local fixture servers @@ -515,7 +599,14 @@ def _gen_fixture_server(fixtures_root, ssl_ctx): @pytest.fixture -def http_proxy(fixtures_cfg, unused_port): +def _proxy_module(): + import proxy + + return proxy + + +@pytest.fixture +def http_proxy(_proxy_module, fixtures_cfg, unused_port): host = fixtures_cfg.aiohttp_fixtures_origin port = unused_port() proxypy_args = [ @@ -529,12 +620,12 @@ def http_proxy(fixtures_cfg, unused_port): proxy_data = ProxyData(host=host, port=port) - with proxy.Proxy(input_args=proxypy_args): + with _proxy_module.Proxy(input_args=proxypy_args): yield proxy_data @pytest.fixture -def http_proxy_with_auth(fixtures_cfg, unused_port): +def http_proxy_with_auth(_proxy_module, fixtures_cfg, unused_port): host = fixtures_cfg.aiohttp_fixtures_origin port = unused_port() @@ -554,12 +645,12 @@ def http_proxy_with_auth(fixtures_cfg, unused_port): proxy_data = ProxyData(host=host, port=port, username=username, password=password) - with proxy.Proxy(input_args=proxypy_args): + with _proxy_module.Proxy(input_args=proxypy_args): yield proxy_data @pytest.fixture -def https_proxy(fixtures_cfg, unused_port, proxy_tls_certificate_pem_path): +def https_proxy(_proxy_module, fixtures_cfg, unused_port, proxy_tls_certificate_pem_path): host = fixtures_cfg.aiohttp_fixtures_origin port = unused_port() @@ -578,7 +669,7 @@ def https_proxy(fixtures_cfg, unused_port, proxy_tls_certificate_pem_path): proxy_data = ProxyData(host=host, port=port, ssl=True) # TODO update me - with proxy.Proxy(input_args=proxypy_args): + with _proxy_module.Proxy(input_args=proxypy_args): yield proxy_data @@ -611,6 +702,8 @@ def __init__(self, *, host, port, username=None, password=None, ssl=False): @pytest.fixture(scope="session") def tls_certificate_authority(): + import trustme + return trustme.CA() @@ -631,6 +724,8 @@ def tls_certificate(fixtures_cfg, tls_certificate_authority): @pytest.fixture(scope="session") def proxy_tls_certificate_authority(): + import trustme + return trustme.CA() @@ -652,6 +747,8 @@ def proxy_tls_certificate_pem_path(proxy_tls_certificate): @pytest.fixture(scope="session") def client_tls_certificate_authority(): + import trustme + return trustme.CA() @@ -839,7 +936,7 @@ def delete_orphans_pre(request, orphans_cleanup_api_client, monitor_task): @pytest.fixture(scope="session") -def monitor_task(tasks_api_client, pulp_domain_enabled): +def monitor_task(pulpcore_bindings, pulp_domain_enabled): """ Wait for a task to reach a final state. @@ -847,12 +944,13 @@ def monitor_task(tasks_api_client, pulp_domain_enabled): in seconds (defaulting to 30*60) exceeded or a `PulpTaskError` in case it reached any other final state. """ + from pulpcore.client.pulpcore import ApiException def _monitor_task(task_href, timeout=TASK_TIMEOUT): task_timeout = int(timeout / SLEEP_TIME) for dummy in range(task_timeout): try: - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) except ApiException as e: if pulp_domain_enabled and e.status == 404: # Task's domain has been deleted, nothing to show anymore @@ -874,7 +972,7 @@ def _monitor_task(task_href, timeout=TASK_TIMEOUT): @pytest.fixture(scope="session") -def monitor_task_group(task_groups_api_client): +def monitor_task_group(pulpcore_bindings): """ Wait for a task group to reach a final state. @@ -886,7 +984,7 @@ def monitor_task_group(task_groups_api_client): def _monitor_task_group(task_group_href, timeout=TASK_TIMEOUT): task_timeout = int(timeout / SLEEP_TIME) for dummy in range(task_timeout): - task_group = task_groups_api_client.read(task_group_href) + task_group = pulpcore_bindings.TaskGroupsApi.read(task_group_href) if (task_group.waiting + task_group.running + task_group.canceling) == 0: break diff --git a/pulpcore/tests/functional/api/test_access_policy.py b/pulpcore/tests/functional/api/test_access_policy.py index 5b0f0dd11bc..3f38649d3af 100644 --- a/pulpcore/tests/functional/api/test_access_policy.py +++ b/pulpcore/tests/functional/api/test_access_policy.py @@ -4,87 +4,87 @@ @pytest.mark.parallel -def test_access_policy_cannot_be_created(access_policies_api_client): +def test_access_policy_cannot_be_created(pulpcore_bindings): """Test that only plugin writers can ship a new AccessPolicy.""" - assert not hasattr(access_policies_api_client, "create") + assert not hasattr(pulpcore_bindings.AccessPoliciesApi, "create") @pytest.mark.parallel -def test_access_policy_default_policies(access_policies_api_client): +def test_access_policy_default_policies(pulpcore_bindings): """Test that the default policies from pulpcore are installed.""" - groups_response = access_policies_api_client.list(viewset_name="groups") + groups_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="groups") assert groups_response.count == 1 - groups_users_response = access_policies_api_client.list(viewset_name="groups/users") + groups_users_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="groups/users") assert groups_users_response.count == 1 - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") assert tasks_response.count == 1 -def test_statements_attr_can_be_modified(access_policies_api_client): +def test_statements_attr_can_be_modified(pulpcore_bindings): """Test that `AccessPolicy.statements` can be modified""" - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") tasks_href = tasks_response.results[0].pulp_href - task_access_policy = access_policies_api_client.read(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) original_statements = task_access_policy.statements assert not task_access_policy.customized assert original_statements != [] - access_policies_api_client.partial_update(tasks_href, {"statements": []}) - task_access_policy = access_policies_api_client.read(tasks_href) + pulpcore_bindings.AccessPoliciesApi.partial_update(tasks_href, {"statements": []}) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) assert task_access_policy.customized assert task_access_policy.statements == [] - access_policies_api_client.reset(tasks_href) - task_access_policy = access_policies_api_client.read(tasks_href) + pulpcore_bindings.AccessPoliciesApi.reset(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) assert not task_access_policy.customized assert task_access_policy.statements == original_statements -def test_creation_hooks_attr_can_be_modified(access_policies_api_client): +def test_creation_hooks_attr_can_be_modified(pulpcore_bindings): """Test that `AccessPolicy.creation_hooks` can be modified""" - groups_response = access_policies_api_client.list(viewset_name="groups") + groups_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="groups") groups_href = groups_response.results[0].pulp_href - groups_access_policy = access_policies_api_client.read(groups_href) + groups_access_policy = pulpcore_bindings.AccessPoliciesApi.read(groups_href) original_creation_hooks = groups_access_policy.creation_hooks assert not groups_access_policy.customized assert original_creation_hooks != [] - access_policies_api_client.partial_update(groups_href, {"creation_hooks": []}) - groups_access_policy = access_policies_api_client.read(groups_href) + pulpcore_bindings.AccessPoliciesApi.partial_update(groups_href, {"creation_hooks": []}) + groups_access_policy = pulpcore_bindings.AccessPoliciesApi.read(groups_href) assert groups_access_policy.customized assert groups_access_policy.creation_hooks == [] - access_policies_api_client.reset(groups_href) - groups_access_policy = access_policies_api_client.read(groups_href) + pulpcore_bindings.AccessPoliciesApi.reset(groups_href) + groups_access_policy = pulpcore_bindings.AccessPoliciesApi.read(groups_href) assert not groups_access_policy.customized assert groups_access_policy.creation_hooks == original_creation_hooks @pytest.mark.parallel -def test_customized_is_read_only(access_policies_api_client): +def test_customized_is_read_only(pulpcore_bindings): """Test that the `AccessPolicy.customized` attribute is read only""" - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") tasks_href = tasks_response.results[0].pulp_href - task_access_policy = access_policies_api_client.read(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) - response = access_policies_api_client.partial_update( + response = pulpcore_bindings.AccessPoliciesApi.partial_update( tasks_href, {"customized": not task_access_policy.customized} ) assert response.customized == task_access_policy.customized @pytest.mark.parallel -def test_viewset_name_is_read_only(access_policies_api_client): +def test_viewset_name_is_read_only(pulpcore_bindings): """Test that the `AccessPolicy.viewset_name` attribute is read only""" - tasks_response = access_policies_api_client.list(viewset_name="tasks") + tasks_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="tasks") tasks_href = tasks_response.results[0].pulp_href - task_access_policy = access_policies_api_client.read(tasks_href) + task_access_policy = pulpcore_bindings.AccessPoliciesApi.read(tasks_href) - response = access_policies_api_client.partial_update( + response = pulpcore_bindings.AccessPoliciesApi.partial_update( tasks_href, {"viewset_name": "not-a-real-name"} ) assert response.viewset_name == task_access_policy.viewset_name diff --git a/pulpcore/tests/functional/api/test_api_docs.py b/pulpcore/tests/functional/api/test_api_docs.py index a824e3dd8a6..45416b0bbdb 100644 --- a/pulpcore/tests/functional/api/test_api_docs.py +++ b/pulpcore/tests/functional/api/test_api_docs.py @@ -9,33 +9,33 @@ def pulp_docs_url(pulp_api_v3_url): @pytest.mark.parallel -def test_valid_credentials(pulpcore_client, pulp_docs_url): +def test_valid_credentials(pulpcore_bindings, pulp_docs_url): """Get API documentation with valid credentials. Assert the API documentation is returned. """ - response = pulpcore_client.request("GET", pulp_docs_url) + response = pulpcore_bindings.client.request("GET", pulp_docs_url) assert response.status == 200 @pytest.mark.parallel -def test_no_credentials(pulpcore_client, pulp_docs_url, anonymous_user): +def test_no_credentials(pulpcore_bindings, pulp_docs_url, anonymous_user): """Get API documentation with no credentials. Assert the API documentation is returned. """ with anonymous_user: - response = pulpcore_client.request("GET", pulp_docs_url) + response = pulpcore_bindings.client.request("GET", pulp_docs_url) assert response.status == 200 @pytest.mark.parallel -def test_http_method(pulpcore_client, pulp_docs_url): +def test_http_method(pulpcore_bindings, pulp_docs_url): """Get API documentation with an HTTP method other than GET. Assert an error is returned. """ with pytest.raises(ApiException) as e: - pulpcore_client.request("POST", pulp_docs_url) + pulpcore_bindings.client.request("POST", pulp_docs_url) assert e.value.status == 405 diff --git a/pulpcore/tests/functional/api/test_correlation_id.py b/pulpcore/tests/functional/api/test_correlation_id.py index 3ebb1fe3fab..ffeca6024f9 100644 --- a/pulpcore/tests/functional/api/test_correlation_id.py +++ b/pulpcore/tests/functional/api/test_correlation_id.py @@ -1,7 +1,7 @@ -def test_correlation_id(cid, tasks_api_client, orphans_cleanup_api_client, monitor_task): +def test_correlation_id(cid, pulpcore_bindings, monitor_task): """Test that a correlation can be passed as a header and logged.""" - response, status, headers = orphans_cleanup_api_client.cleanup_with_http_info({}) + response, status, headers = pulpcore_bindings.OrphansCleanupApi.cleanup_with_http_info({}) monitor_task(response.task) - task = tasks_api_client.read(response.task) + task = pulpcore_bindings.TasksApi.read(response.task) assert headers["Correlation-ID"] == cid assert task.logging_cid == cid diff --git a/pulpcore/tests/functional/api/test_replication.py b/pulpcore/tests/functional/api/test_replication.py index f31f42922a6..44eca90d56d 100644 --- a/pulpcore/tests/functional/api/test_replication.py +++ b/pulpcore/tests/functional/api/test_replication.py @@ -11,7 +11,7 @@ def test_replication( domain_factory, bindings_cfg, - upstream_pulp_api_client, + pulpcore_bindings, monitor_task_group, pulp_settings, gen_object_with_cleanup, @@ -35,10 +35,10 @@ def test_replication( "password": bindings_cfg.password, } upstream_pulp = gen_object_with_cleanup( - upstream_pulp_api_client, upstream_pulp_body, pulp_domain=non_default_domain.name + pulpcore_bindings.UpstreamPulpsApi, upstream_pulp_body, pulp_domain=non_default_domain.name ) # Run the replicate task and assert that all tasks successfully complete. - response = upstream_pulp_api_client.replicate(upstream_pulp.pulp_href) + response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href) task_group = monitor_task_group(response.task_group) for task in task_group.tasks: assert task.state == "completed" @@ -48,11 +48,10 @@ def test_replication( def test_replication_with_wrong_ca_cert( domain_factory, bindings_cfg, - upstream_pulp_api_client, + pulpcore_bindings, monitor_task_group, pulp_settings, gen_object_with_cleanup, - tasks_api_client, ): # This test assures that setting ca_cert on an Upstream Pulp causes that CA bundle to be used # to verify the certificate presented by the Upstream Pulp's REST API. The replication tasks @@ -103,21 +102,23 @@ def test_replication_with_wrong_ca_cert( """, } upstream_pulp = gen_object_with_cleanup( - upstream_pulp_api_client, upstream_pulp_body, pulp_domain=non_default_domain.name + pulpcore_bindings.UpstreamPulpsApi, upstream_pulp_body, pulp_domain=non_default_domain.name ) # Run the replicate task and assert that it fails with SSLError with pytest.raises(PulpTaskGroupError) as e: - response = upstream_pulp_api_client.replicate(upstream_pulp.pulp_href) + response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href) monitor_task_group(response.task_group) - task = tasks_api_client.read(e.value.task_group.tasks[0].pulp_href) + task = pulpcore_bindings.TasksApi.read(e.value.task_group.tasks[0].pulp_href) assert "SSLError" in task.error["description"] # Update Upstream Pulp with tls_validation=False - upstream_pulp_api_client.partial_update(upstream_pulp.pulp_href, {"tls_validation": False}) + pulpcore_bindings.UpstreamPulpsApi.partial_update( + upstream_pulp.pulp_href, {"tls_validation": False} + ) # Run the replicate task again and assert that all tasks successfully complete. - response = upstream_pulp_api_client.replicate(upstream_pulp.pulp_href) + response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href) task_group = monitor_task_group(response.task_group) for task in task_group.tasks: assert task.state == "completed" @@ -166,7 +167,7 @@ def test_replicate_rbac( try_action, domain_factory, bindings_cfg, - upstream_pulp_api_client, + pulpcore_bindings, pulp_settings, gen_object_with_cleanup, ): @@ -185,23 +186,29 @@ def test_replicate_rbac( "pulp_label_select": str(uuid.uuid4()), } upstream_pulp = gen_object_with_cleanup( - upstream_pulp_api_client, upstream_pulp_body, pulp_domain=non_default_domain.name + pulpcore_bindings.UpstreamPulpsApi, + upstream_pulp_body, + pulp_domain=non_default_domain.name, ) # Assert that Alice (upstream pulp viewer) gets a 403 - try_action(alice, upstream_pulp_api_client, "replicate", 403, upstream_pulp.pulp_href) + try_action(alice, pulpcore_bindings.UpstreamPulpsApi, "replicate", 403, upstream_pulp.pulp_href) # Assert that B (upstream pulp owner) gets a 202 - try_action(bob, upstream_pulp_api_client, "replicate", 202, upstream_pulp.pulp_href) + try_action(bob, pulpcore_bindings.UpstreamPulpsApi, "replicate", 202, upstream_pulp.pulp_href) # Assert that Charlie (no role) get a 404 - try_action(charlie, upstream_pulp_api_client, "replicate", 404, upstream_pulp.pulp_href) + try_action( + charlie, pulpcore_bindings.UpstreamPulpsApi, "replicate", 404, upstream_pulp.pulp_href + ) # Assert that Dean can run replication - try_action(dean, upstream_pulp_api_client, "replicate", 202, upstream_pulp.pulp_href) + try_action(dean, pulpcore_bindings.UpstreamPulpsApi, "replicate", 202, upstream_pulp.pulp_href) # Assert that Dean can view the upstream pulp - try_action(dean, upstream_pulp_api_client, "read", 200, upstream_pulp.pulp_href) + try_action(dean, pulpcore_bindings.UpstreamPulpsApi, "read", 200, upstream_pulp.pulp_href) # Assert that Dean can't update the upstream pulp - try_action(dean, upstream_pulp_api_client, "partial_update", 403, upstream_pulp.pulp_href, {}) + try_action( + dean, pulpcore_bindings.UpstreamPulpsApi, "partial_update", 403, upstream_pulp.pulp_href, {} + ) diff --git a/pulpcore/tests/functional/api/test_status.py b/pulpcore/tests/functional/api/test_status.py index 8a671491a50..bde2ad806e7 100644 --- a/pulpcore/tests/functional/api/test_status.py +++ b/pulpcore/tests/functional/api/test_status.py @@ -99,7 +99,7 @@ def test_post_authenticated( test_path, pulp_api_v3_path, status_api_client, - pulpcore_client, + pulpcore_bindings, pulp_api_v3_url, received_otel_span, ): @@ -114,7 +114,7 @@ def test_post_authenticated( # Try anyway to POST to /status/ status_url = f"{pulp_api_v3_url}status/" with pytest.raises(ApiException) as e: - pulpcore_client.request("POST", status_url, headers={"User-Agent": test_path}) + pulpcore_bindings.client.request("POST", status_url, headers={"User-Agent": test_path}) assert e.value.status == 405 assert received_otel_span( @@ -130,7 +130,7 @@ def test_post_authenticated( @pytest.mark.parallel def test_storage_per_domain( status_api_client, - pulpcore_client, + pulpcore_bindings, pulp_api_v3_url, domain_factory, random_artifact_factory, @@ -139,13 +139,13 @@ def test_storage_per_domain( domain = domain_factory() # Status endpoint is not exposed at domain url in API spec to prevent duplicates, call manually status_url = f"{pulp_api_v3_url}status/".replace("default", domain.name) - status_response = pulpcore_client.request("GET", status_url) - domain_status = pulpcore_client.deserialize(status_response, "StatusResponse") + status_response = pulpcore_bindings.client.request("GET", status_url) + domain_status = pulpcore_bindings.client.deserialize(status_response, "StatusResponse") assert domain_status.storage.used == 0 random_artifact_factory(size=1, pulp_domain=domain.name) - status_response = pulpcore_client.request("GET", status_url) - domain_status = pulpcore_client.deserialize(status_response, "StatusResponse") + status_response = pulpcore_bindings.client.request("GET", status_url) + domain_status = pulpcore_bindings.client.deserialize(status_response, "StatusResponse") assert domain_status.storage.used == 1 diff --git a/pulpcore/tests/functional/api/test_tasking.py b/pulpcore/tests/functional/api/test_tasking.py index df89d73055c..f7bc1d1ce83 100644 --- a/pulpcore/tests/functional/api/test_tasking.py +++ b/pulpcore/tests/functional/api/test_tasking.py @@ -13,10 +13,10 @@ @pytest.fixture(scope="session") -def dispatch_task(pulpcore_client): +def dispatch_task(pulpcore_bindings): def _dispatch_task(*args, **kwargs): - cid = pulpcore_client.default_headers.get("Correlation-ID") or str(uuid4()) - username = pulpcore_client.configuration.username + cid = pulpcore_bindings.client.default_headers.get("Correlation-ID") or str(uuid4()) + username = pulpcore_bindings.client.configuration.username commands = ( "from django_guid import set_guid; " "from pulpcore.tasking.tasks import dispatch; " @@ -81,7 +81,7 @@ def test_multi_resource_locking(dispatch_task, monitor_task): @pytest.mark.parallel -def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): +def test_delete_cancel_waiting_task(dispatch_task, pulpcore_bindings): # Queue one task after a long running one resource = str(uuid4()) blocking_task_href = dispatch_task( @@ -91,18 +91,18 @@ def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): "pulpcore.app.tasks.test.sleep", args=(0,), exclusive_resources=[resource] ) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "waiting" # Try to delete first with pytest.raises(ApiException) as ctx: - tasks_api_client.delete(task_href) + pulpcore_bindings.TasksApi.delete(task_href) assert ctx.value.status == 409 # Now cancel the task - task = tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + task = pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) # cancel the blocking task - tasks_api_client.tasks_cancel(blocking_task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(blocking_task_href, {"state": "canceled"}) if task.state == "canceling": assert task.started_at is None @@ -112,7 +112,7 @@ def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): if task.state != "canceling": break time.sleep(1) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "canceled" assert task.started_at is None @@ -120,11 +120,11 @@ def test_delete_cancel_waiting_task(dispatch_task, tasks_api_client): @pytest.mark.parallel -def test_delete_cancel_running_task(dispatch_task, tasks_api_client): +def test_delete_cancel_running_task(dispatch_task, pulpcore_bindings): task_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(600,)) for i in range(10): - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) if task.state == "running": break time.sleep(1) @@ -133,11 +133,11 @@ def test_delete_cancel_running_task(dispatch_task, tasks_api_client): # Try to delete first with pytest.raises(ApiException) as ctx: - tasks_api_client.delete(task_href) + pulpcore_bindings.TasksApi.delete(task_href) assert ctx.value.status == 409 # Now cancel the task - task = tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + task = pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) if task.state == "canceling": assert task.started_at is not None @@ -147,7 +147,7 @@ def test_delete_cancel_running_task(dispatch_task, tasks_api_client): if task.state != "canceling": break time.sleep(1) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "canceled" assert task.started_at is not None @@ -155,24 +155,24 @@ def test_delete_cancel_running_task(dispatch_task, tasks_api_client): @pytest.mark.parallel -def test_cancel_delete_finished_task(tasks_api_client, dispatch_task, monitor_task): +def test_cancel_delete_finished_task(pulpcore_bindings, dispatch_task, monitor_task): task_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) monitor_task(task_href) # Try to cancel first with pytest.raises(ApiException) as ctx: - tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) assert ctx.value.status == 409 # Now delete the task - tasks_api_client.delete(task_href) + pulpcore_bindings.TasksApi.delete(task_href) @pytest.mark.parallel -def test_cancel_nonexistent_task(pulp_api_v3_path, tasks_api_client): +def test_cancel_nonexistent_task(pulp_api_v3_path, pulpcore_bindings): task_href = f"{pulp_api_v3_path}tasks/{uuid4()}/" with pytest.raises(ApiException) as ctx: - tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) assert ctx.value.status == 404 @@ -225,71 +225,71 @@ def test_retrieve_task_with_minimal_fields(task, bindings_cfg): @pytest.mark.parallel -def test_retrieve_task_using_invalid_worker(tasks_api_client): +def test_retrieve_task_using_invalid_worker(pulpcore_bindings): """Expects to raise an exception when using invalid worker value as filter.""" with pytest.raises(ApiException) as ctx: - tasks_api_client.list(worker=str(uuid4())) + pulpcore_bindings.TasksApi.list(worker=str(uuid4())) assert ctx.value.status == 400 @pytest.mark.parallel -def test_retrieve_task_using_valid_worker(task, tasks_api_client): +def test_retrieve_task_using_valid_worker(task, pulpcore_bindings): """Expects to retrieve a task using a valid worker URI as filter.""" - response = tasks_api_client.list(worker=task.worker) + response = pulpcore_bindings.TasksApi.list(worker=task.worker) assert response.results and response.count @pytest.mark.parallel -def test_retrieve_task_using_invalid_date(tasks_api_client): +def test_retrieve_task_using_invalid_date(pulpcore_bindings): """Expects to raise an exception when using invalid dates as filters""" with pytest.raises(ApiException) as ctx: - tasks_api_client.list(finished_at=str(uuid4()), started_at=str(uuid4())) + pulpcore_bindings.TasksApi.list(finished_at=str(uuid4()), started_at=str(uuid4())) assert ctx.value.status == 400 @pytest.mark.parallel -def test_retrieve_task_using_valid_date(task, tasks_api_client): +def test_retrieve_task_using_valid_date(task, pulpcore_bindings): """Expects to retrieve a task using a valid date.""" - response = tasks_api_client.list(started_at=task.started_at) + response = pulpcore_bindings.TasksApi.list(started_at=task.started_at) assert response.results and response.count @pytest.mark.parallel -def test_search_task_by_name(task, tasks_api_client): +def test_search_task_by_name(task, pulpcore_bindings): task_name = task.name - search_results = tasks_api_client.list(name=task.name).results + search_results = pulpcore_bindings.TasksApi.list(name=task.name).results assert search_results assert all([task.name == task_name for task in search_results]) @pytest.mark.parallel -def test_search_task_using_an_invalid_name(tasks_api_client): +def test_search_task_using_an_invalid_name(pulpcore_bindings): """Expect to return an empty results array when searching using an invalid task name. """ - search_results = tasks_api_client.list(name=str(uuid4())) + search_results = pulpcore_bindings.TasksApi.list(name=str(uuid4())) assert not search_results.results and not search_results.count @pytest.mark.parallel -def test_filter_tasks_using_worker__in_filter(tasks_api_client, dispatch_task, monitor_task): +def test_filter_tasks_using_worker__in_filter(pulpcore_bindings, dispatch_task, monitor_task): task1_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) task2_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,)) task1 = monitor_task(task1_href) task2 = monitor_task(task2_href) - search_results = tasks_api_client.list(worker__in=(task1.worker, task2.worker)) + search_results = pulpcore_bindings.TasksApi.list(worker__in=(task1.worker, task2.worker)) tasks_hrefs = [task.pulp_href for task in search_results.results] @@ -297,22 +297,22 @@ def test_filter_tasks_using_worker__in_filter(tasks_api_client, dispatch_task, m assert task2_href in tasks_hrefs -def test_cancel_gooey_task(tasks_api_client, dispatch_task, monitor_task): +def test_cancel_gooey_task(pulpcore_bindings, dispatch_task, monitor_task): task_href = dispatch_task("pulpcore.app.tasks.test.gooey_task", args=(60,)) for i in range(10): - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) if task.state == "running": break time.sleep(1) - task = tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + task = pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) if task.state == "canceling": for i in range(30): if task.state != "canceling": break time.sleep(1) - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "canceled" @@ -339,12 +339,12 @@ def test_task_created_by(dispatch_task, monitor_task, gen_user, anonymous_user): @pytest.mark.parallel -def test_task_version_prevent_pickup(dispatch_task, tasks_api_client): +def test_task_version_prevent_pickup(dispatch_task, pulpcore_bindings): task1 = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,), versions={"core": "4.0.0"}) task2 = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,), versions={"catdog": "0.0.0"}) time.sleep(5) for task_href in [task1, task2]: - task = tasks_api_client.read(task_href) + task = pulpcore_bindings.TasksApi.read(task_href) assert task.state == "waiting" - tasks_api_client.tasks_cancel(task_href, {"state": "canceled"}) + pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"}) diff --git a/pulpcore/tests/functional/api/test_upload.py b/pulpcore/tests/functional/api/test_upload.py index 3cfb1047852..129e61670cb 100644 --- a/pulpcore/tests/functional/api/test_upload.py +++ b/pulpcore/tests/functional/api/test_upload.py @@ -44,7 +44,6 @@ def pulpcore_upload_chunks( uploads_api_client, artifacts_api_client, gen_object_with_cleanup, - tasks_api_client, monitor_task, ): """Upload file in chunks.""" diff --git a/pulpcore/tests/functional/api/using_plugin/test_contentguard.py b/pulpcore/tests/functional/api/using_plugin/test_contentguard.py index e8a401d8ee2..c2dc9476c48 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_contentguard.py +++ b/pulpcore/tests/functional/api/using_plugin/test_contentguard.py @@ -12,7 +12,7 @@ @pytest.mark.parallel def test_rbac_content_guard_full_workflow( - rbac_contentguard_api_client, + pulpcore_bindings, groups_api_client, groups_users_api_client, file_distribution_api_client, @@ -55,7 +55,9 @@ def _assert_access(authorized_users): # Check that RBAC ContentGuard can be created and assigned to a distribution with creator_user: - guard = gen_object_with_cleanup(rbac_contentguard_api_client, {"name": distro.name}) + guard = gen_object_with_cleanup( + pulpcore_bindings.ContentguardsRbacApi, {"name": distro.name} + ) body = PatchedfileFileDistribution(content_guard=guard.pulp_href) monitor_task(file_distribution_api_client.partial_update(distro.pulp_href, body).task) distro = file_distribution_api_client.read(distro.pulp_href) @@ -70,29 +72,29 @@ def _assert_access(authorized_users): "role": "core.rbaccontentguard_downloader", } with creator_user: - rbac_contentguard_api_client.add_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.add_role(distro.content_guard, body) _assert_access([creator_user, user_b, user_a, pulp_admin_user]) # Use the /remove/ endpoint to remove users permission to access distribution with creator_user: - rbac_contentguard_api_client.remove_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.remove_role(distro.content_guard, body) _assert_access([creator_user, pulp_admin_user]) # Use the /add/ endpoint to add group body = {"groups": [group.name], "role": "core.rbaccontentguard_downloader"} with creator_user: - rbac_contentguard_api_client.add_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.add_role(distro.content_guard, body) _assert_access([creator_user, user_b, user_a, pulp_admin_user]) # Use the /remove/ endpoint to remove group with creator_user: - rbac_contentguard_api_client.remove_role(distro.content_guard, body) + pulpcore_bindings.ContentguardsRbacApi.remove_role(distro.content_guard, body) _assert_access([creator_user, pulp_admin_user]) @pytest.mark.parallel def test_header_contentguard_workflow( - header_contentguard_api_client, + pulpcore_bindings, gen_user, file_distribution_factory, gen_object_with_cleanup, @@ -109,7 +111,7 @@ def test_header_contentguard_workflow( with creator_user: guard = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, {"name": distro.name, "header_name": "x-header", "header_value": "123456"}, ) body = PatchedfileFileDistribution(content_guard=guard.pulp_href) @@ -139,7 +141,7 @@ def test_header_contentguard_workflow( with creator_user: guard = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, { "name": distro.name, "header_name": header_name, @@ -165,9 +167,7 @@ def test_header_contentguard_workflow( def test_composite_contentguard_crud( - composite_contentguard_api_client, - redirect_contentguard_api_client, - header_contentguard_api_client, + pulpcore_bindings, gen_user, gen_object_with_cleanup, ): @@ -183,44 +183,44 @@ def test_composite_contentguard_crud( with creator_user: # Create RedirectContentGuard, HeaderContentGuard hcg = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, {"name": str(uuid.uuid4()), "header_name": "x-header", "header_value": "123456"}, ) rcg = gen_object_with_cleanup( - redirect_contentguard_api_client, + pulpcore_bindings.ContentguardsContentRedirectApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_crud"}, ) # Create CCG1, no guards; evaluate ccg1 = gen_object_with_cleanup( - composite_contentguard_api_client, + pulpcore_bindings.ContentguardsCompositeApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_crud"}, ) assert not ccg1.guards - ccg1 = composite_contentguard_api_client.read(ccg1.pulp_href) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.read(ccg1.pulp_href) assert not ccg1.guards # Update CCG1, RCG, evaluate, expect 1 body = PatchedCompositeContentGuard(guards=[rcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) assert ccg1.guards assert len(ccg1.guards) == 1 # Update CCG1, HCG, evaluate, expect 1 body = PatchedCompositeContentGuard(guards=[hcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) assert ccg1.guards assert len(ccg1.guards) == 1 # Update CCG1, [RCG, HCG], evaluate, expect 2 body = PatchedCompositeContentGuard(guards=[rcg.pulp_href, hcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) assert ccg1.guards assert len(ccg1.guards) == 2 # Create CCG2, [RCG, HCG], evaluate ccg2 = gen_object_with_cleanup( - composite_contentguard_api_client, + pulpcore_bindings.ContentguardsCompositeApi, { "name": str(uuid.uuid4()), "description": "test_composite_contentguard_crud", @@ -231,20 +231,18 @@ def test_composite_contentguard_crud( assert len(ccg2.guards) == 2 # List CCGs, expect 2 - list_response = composite_contentguard_api_client.list() + list_response = pulpcore_bindings.ContentguardsCompositeApi.list() assert list_response.count == 2 # Delete CCG1 - composite_contentguard_api_client.delete(ccg1.pulp_href) + pulpcore_bindings.ContentguardsCompositeApi.delete(ccg1.pulp_href) # List CCG, expect 1 - list_response = composite_contentguard_api_client.list() + list_response = pulpcore_bindings.ContentguardsCompositeApi.list() assert list_response.count == 1 def test_composite_contentguard_permissions( - composite_contentguard_api_client, - redirect_contentguard_api_client, - header_contentguard_api_client, + pulpcore_bindings, gen_user, gen_object_with_cleanup, monitor_task, @@ -265,17 +263,17 @@ def test_composite_contentguard_permissions( with creator_user: # Create RedirectContentGuard, HeaderContentGuard hcg = gen_object_with_cleanup( - header_contentguard_api_client, + pulpcore_bindings.ContentguardsHeaderApi, {"name": str(uuid.uuid4()), "header_name": "x-header", "header_value": "123456"}, ) rcg = gen_object_with_cleanup( - redirect_contentguard_api_client, + pulpcore_bindings.ContentguardsContentRedirectApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_permissions"}, ) # Create CCG1, no guards ccg1 = gen_object_with_cleanup( - composite_contentguard_api_client, + pulpcore_bindings.ContentguardsCompositeApi, {"name": str(uuid.uuid4()), "description": "test_composite_contentguard_permissions"}, ) @@ -297,7 +295,7 @@ def test_composite_contentguard_permissions( # update CCG with RCG body = PatchedCompositeContentGuard(guards=[rcg.pulp_href]) - ccg1 = composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + ccg1 = pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) # attempt dist-access, expect 403 (1 guard, forbids) response = get_from_url(distro.base_url) @@ -305,7 +303,7 @@ def test_composite_contentguard_permissions( # Create HeaderContentGuard, update CCG with [RCG, HCG] body = PatchedCompositeContentGuard(guards=[rcg.pulp_href, hcg.pulp_href]) - composite_contentguard_api_client.partial_update(ccg1.pulp_href, body) + pulpcore_bindings.ContentguardsCompositeApi.partial_update(ccg1.pulp_href, body) # attempt dist-access, expect 403 (2 guards, both forbid) response = get_from_url(distro.base_url) diff --git a/pulpcore/tests/functional/api/using_plugin/test_labels.py b/pulpcore/tests/functional/api/using_plugin/test_labels.py index 598628b7d81..f320e4d4d0c 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_labels.py +++ b/pulpcore/tests/functional/api/using_plugin/test_labels.py @@ -2,8 +2,8 @@ @pytest.fixture -def label_access_policy(access_policies_api_client): - orig_access_policy = access_policies_api_client.list( +def label_access_policy(pulpcore_bindings): + orig_access_policy = pulpcore_bindings.AccessPoliciesApi.list( viewset_name="repositories/file/file" ).results[0] new_statements = orig_access_policy.statements.copy() @@ -18,16 +18,16 @@ def label_access_policy(access_policies_api_client): "principal": "authenticated", } ) - access_policies_api_client.partial_update( + pulpcore_bindings.AccessPoliciesApi.partial_update( orig_access_policy.pulp_href, {"statements": new_statements} ) yield if orig_access_policy.customized: - access_policies_api_client.partial_update( + pulpcore_bindings.AccessPoliciesApi.partial_update( orig_access_policy.pulp_href, {"statements": orig_access_policy.statements} ) else: - access_policies_api_client.reset(orig_access_policy.pulp_href) + pulpcore_bindings.AccessPoliciesApi.reset(orig_access_policy.pulp_href) @pytest.mark.parallel diff --git a/pulpcore/tests/functional/api/using_plugin/test_orphans.py b/pulpcore/tests/functional/api/using_plugin/test_orphans.py index 7e8051dcacc..8681f94c330 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_orphans.py +++ b/pulpcore/tests/functional/api/using_plugin/test_orphans.py @@ -4,23 +4,14 @@ from pulpcore.app import settings -from pulpcore.client.pulpcore import OrphansApi -from pulpcore.client.pulpcore.exceptions import ApiException as CoreApiException -from pulpcore.client.pulp_file.exceptions import ApiException - - -@pytest.fixture -def orphans_api_client(pulpcore_client): - # This API is deprecated. Use it only to test its own functionality. - return OrphansApi(pulpcore_client) - def test_orphans_delete( random_artifact, file_random_content_unit, artifacts_api_client, file_content_api_client, - orphans_api_client, + pulpcore_bindings, + file_bindings, monitor_task, ): # Verify that the system contains the orphan content unit and the orphan artifact. @@ -36,11 +27,11 @@ def test_orphans_delete( assert os.path.exists(artifact_path2) is True # Delete orphans using deprecated API - monitor_task(orphans_api_client.delete().task) + monitor_task(pulpcore_bindings.OrphansApi.delete().task) # Assert that the content unit and artifact are gone if settings.ORPHAN_PROTECTION_TIME == 0: - with pytest.raises(ApiException) as exc: + with pytest.raises(file_bindings.ApiException) as exc: file_content_api_client.read(file_random_content_unit.pulp_href) assert exc.value.status == 404 if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": @@ -53,11 +44,12 @@ def test_orphans_cleanup( file_random_content_unit, artifacts_api_client, file_content_api_client, - orphans_cleanup_api_client, + pulpcore_bindings, + file_bindings, monitor_task, ): # Cleanup orphans with a nonzero orphan_protection_time - monitor_task(orphans_cleanup_api_client.cleanup({"orphan_protection_time": 10}).task) + monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 10}).task) # Verify that the system contains the orphan content unit and the orphan artifact. content_unit = file_content_api_client.read(file_random_content_unit.pulp_href) @@ -72,10 +64,10 @@ def test_orphans_cleanup( assert os.path.exists(artifact_path2) is True # Cleanup orphans with a zero orphan_protection_time - monitor_task(orphans_cleanup_api_client.cleanup({"orphan_protection_time": 0}).task) + monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup({"orphan_protection_time": 0}).task) # Assert that the content unit and the artifact are gone - with pytest.raises(ApiException) as exc: + with pytest.raises(file_bindings.ApiException) as exc: file_content_api_client.read(file_random_content_unit.pulp_href) assert exc.value.status == 404 if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem": @@ -86,28 +78,29 @@ def test_orphans_cleanup( def test_cleanup_specific_orphans( file_content_unit_with_name_factory, file_content_api_client, - orphans_cleanup_api_client, + pulpcore_bindings, + file_bindings, monitor_task, ): content_unit_1 = file_content_unit_with_name_factory("1.iso") content_unit_2 = file_content_unit_with_name_factory("2.iso") cleanup_dict = {"content_hrefs": [content_unit_1.pulp_href], "orphan_protection_time": 0} - monitor_task(orphans_cleanup_api_client.cleanup(cleanup_dict).task) + monitor_task(pulpcore_bindings.OrphansCleanupApi.cleanup(cleanup_dict).task) # Assert that content_unit_2 is gone and content_unit_1 is present - with pytest.raises(ApiException) as exc: + with pytest.raises(file_bindings.ApiException) as exc: file_content_api_client.read(content_unit_1.pulp_href) assert exc.value.status == 404 assert file_content_api_client.read(content_unit_2.pulp_href).pulp_href # Test whether the `content_hrefs` param raises a ValidationError with [] as the value content_hrefs_dict = {"content_hrefs": []} - with pytest.raises(CoreApiException) as exc: - orphans_cleanup_api_client.cleanup(content_hrefs_dict) + with pytest.raises(pulpcore_bindings.ApiException) as exc: + pulpcore_bindings.OrphansCleanupApi.cleanup(content_hrefs_dict) assert exc.value.status == 400 # Test whether the `content_hrefs` param raises a ValidationError with and invalid href""" content_hrefs_dict = {"content_hrefs": ["/not/a/valid/content/href"]} - with pytest.raises(CoreApiException) as exc: - orphans_cleanup_api_client.cleanup(content_hrefs_dict) + with pytest.raises(pulpcore_bindings.ApiException) as exc: + pulpcore_bindings.OrphansCleanupApi.cleanup(content_hrefs_dict) assert exc.value.status == 400 diff --git a/pulpcore/tests/functional/api/using_plugin/test_purge.py b/pulpcore/tests/functional/api/using_plugin/test_purge.py index e7e0be911fd..d022643aac2 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_purge.py +++ b/pulpcore/tests/functional/api/using_plugin/test_purge.py @@ -14,7 +14,7 @@ TOMORROW_STR = (datetime.now(timezone.utc) + timedelta(days=1)).strftime("%Y-%m-%dT%H:%M") -def _task_summary(tasks_api_client): +def _task_summary(pulpcore_bindings): """ Summary of number of tasks in all known task-states. :return: tuple of (total-tasks, number of final tasks, summary) @@ -23,7 +23,7 @@ def _task_summary(tasks_api_client): total = 0 final_total = 0 for state in TASK_STATES.__dict__.values(): - response = tasks_api_client.list(state=state) + response = pulpcore_bindings.TasksApi.list(state=state) summary[state] = response.count total += summary[state] final_total += summary[state] if state in TASK_FINAL_STATES else 0 @@ -50,7 +50,7 @@ def _check_delete_report(task, expected): @pytest.fixture def sync_results( file_repository_api_client, - tasks_api_client, + pulpcore_bindings, file_remote_factory, file_remote_ssl_factory, file_repository_factory, @@ -67,7 +67,7 @@ def sync_results( bad_repo = file_repository_factory() bad_sync_data = RepositorySyncURL(remote=bad_remote.pulp_href) - pre_total, pre_final, pre_summary = _task_summary(tasks_api_client) + pre_total, pre_final, pre_summary = _task_summary(pulpcore_bindings.TasksApi) # good sync sync_response = file_repository_api_client.sync(good_repo.pulp_href, good_sync_data) @@ -79,125 +79,125 @@ def sync_results( sync_response = file_repository_api_client.sync(bad_repo.pulp_href, bad_sync_data) with pytest.raises(PulpTaskError): monitor_task(sync_response.task) - task = tasks_api_client.read(sync_response.task) + task = pulpcore_bindings.TasksApi.read(sync_response.task) assert "failed" == task.state failed_sync_task = task - post_total, post_final, post_summary = _task_summary(tasks_api_client) + post_total, post_final, post_summary = _task_summary(pulpcore_bindings.TasksApi) assert post_total == (pre_total + 2) assert post_final == (pre_final + 2) return completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary -def test_purge_before_time(tasks_api_client, sync_results, monitor_task): +def test_purge_before_time(pulpcore_bindings, sync_results, monitor_task): """Purge that should find no tasks to delete.""" _, _, pre_total, _, _ = sync_results dta = Purge(finished_before="1970-01-01T00:00") - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) - new_total, new_final, new_summary = _task_summary(tasks_api_client) + new_total, new_final, new_summary = _task_summary(pulpcore_bindings.TasksApi) # Should have all tasks remaining (2 completed, 1 failed) assert (pre_total + 3) == new_total # Should show we report having purged no tasks assert _purge_report_total(task) == 0 -def test_purge_defaults(tasks_api_client, sync_results, monitor_task): +def test_purge_defaults(pulpcore_bindings, sync_results, monitor_task): """Purge using defaults (finished_before=30-days-ago, state=completed)""" dta = Purge() - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) monitor_task(response.task) completed_sync_task, failed_sync_task, _, _, _ = sync_results # default is "completed before 30 days ago" - so both sync tasks should still exist # Make sure good sync-task still exists - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # Make sure the failed sync still exists - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) -def test_purge_all(tasks_api_client, sync_results, monitor_task): +def test_purge_all(pulpcore_bindings, sync_results, monitor_task): """Purge all tasks in any 'final' state.""" completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary = sync_results states = list(TASK_FINAL_STATES) dta = Purge(finished_before=TOMORROW_STR, states=states) - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) - new_total, new_final, new_summary = _task_summary(tasks_api_client) + new_total, new_final, new_summary = _task_summary(pulpcore_bindings.TasksApi) assert 1 == new_final, "The purge-task should be the only final-task left" # Make sure good sync-task is gone with pytest.raises(ApiException): - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # Make sure failed sync-task is gone with pytest.raises(ApiException): - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) # Make sure we reported the deletions _check_delete_report(task, pre_final + 2) -def test_purge_leave_one(tasks_api_client, sync_results, monitor_task): +def test_purge_leave_one(pulpcore_bindings, sync_results, monitor_task): """Arrange to leave one task unscathed.""" # Leave only the failed sync completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary = sync_results dta = Purge(finished_before=failed_sync_task.finished_at) - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) task = monitor_task(response.task) # Make sure good sync-task is gone with pytest.raises(ApiException): - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # Make sure the failed sync still exists - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) # Make sure we reported the task-deletion _check_delete_report(task, pre_final + 1) -def test_purge_only_failed(tasks_api_client, sync_results, monitor_task): +def test_purge_only_failed(pulpcore_bindings, sync_results, monitor_task): """Purge all failed tasks only.""" dta = Purge(finished_before=TOMORROW_STR, states=["failed"]) - response = tasks_api_client.purge(dta) + response = pulpcore_bindings.TasksApi.purge(dta) monitor_task(response.task) # completed sync-task should exist completed_sync_task, failed_sync_task, pre_total, pre_final, pre_summary = sync_results - tasks_api_client.read(completed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(completed_sync_task.pulp_href) # failed should not exist with pytest.raises(ApiException): - tasks_api_client.read(failed_sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(failed_sync_task.pulp_href) -def test_bad_date(tasks_api_client, sync_results): +def test_bad_date(pulpcore_bindings, sync_results): """What happens if you use a bad date format?""" dta = Purge(finished_before="THISISNOTADATE") with pytest.raises(ApiException): - tasks_api_client.purge(dta) + pulpcore_bindings.TasksApi.purge(dta) -def test_bad_state(tasks_api_client, sync_results): +def test_bad_state(pulpcore_bindings, sync_results): """What happens if you specify junk for a state?""" dta = Purge(finished_before=TOMORROW_STR, states=["BAD STATE"]) with pytest.raises(ApiException): - tasks_api_client.purge(dta) + pulpcore_bindings.TasksApi.purge(dta) -def test_not_final_state(tasks_api_client, sync_results): +def test_not_final_state(pulpcore_bindings, sync_results): """What happens if you use a valid state that isn't a 'final' one?""" dta = Purge(finished_before=TOMORROW_STR, states=["running"]) with pytest.raises(ApiException): - tasks_api_client.purge(dta) + pulpcore_bindings.TasksApi.purge(dta) def test_purge_with_different_users( - tasks_api_client, + pulpcore_bindings, file_repository_api_client, file_remote_ssl_factory, file_repository_factory, @@ -231,11 +231,11 @@ def test_purge_with_different_users( states = list(TASK_FINAL_STATES) data = Purge(finished_before=TOMORROW_STR, states=states) with user: - response = tasks_api_client.purge(data) + response = pulpcore_bindings.TasksApi.purge(data) task = monitor_task(response.task) # Make sure sync-task (executed by admin) still exists - tasks_api_client.read(task.pulp_href) + pulpcore_bindings.TasksApi.read(task.pulp_href) # Sync as user with user: @@ -246,12 +246,12 @@ def test_purge_with_different_users( states = list(TASK_FINAL_STATES) data = Purge(finished_before=TOMORROW_STR, states=states) with user: - response = tasks_api_client.purge(data) + response = pulpcore_bindings.TasksApi.purge(data) monitor_task(response.task) # Make sure task DOES NOT exist with pytest.raises(ApiException): - tasks_api_client.read(sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(sync_task.pulp_href) # Sync as user with user: @@ -261,9 +261,9 @@ def test_purge_with_different_users( # Purge as ADMIN states = list(TASK_FINAL_STATES) data = Purge(finished_before=TOMORROW_STR, states=states) - response = tasks_api_client.purge(data) + response = pulpcore_bindings.TasksApi.purge(data) monitor_task(response.task) # Make sure task DOES NOT exist with pytest.raises(ApiException): - tasks_api_client.read(sync_task.pulp_href) + pulpcore_bindings.TasksApi.read(sync_task.pulp_href) diff --git a/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py b/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py index 9233e17381b..be69532dae5 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py @@ -375,9 +375,8 @@ def test_squash_repo_version( @pytest.mark.parallel def test_content_immutable_repo_version( + file_bindings, file_repository_api_client, - file_repository_version_api_client, - file_client, file_repository_factory, file_remote_ssl_factory, basic_manifest_path, @@ -389,18 +388,20 @@ def test_content_immutable_repo_version( """ file_repo = file_repository_factory() remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") - task = file_repository_api_client.sync(file_repo.pulp_href, {"remote": remote.pulp_href}).task + task = file_bindings.RepositoriesFileApi.sync( + file_repo.pulp_href, {"remote": remote.pulp_href} + ).task monitor_task(task) - repo = file_repository_api_client.read(file_repo.pulp_href) + repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) assert repo.latest_version_href[-2] == "1" - repo_ver_attributes = dir(file_repository_version_api_client) + repo_ver_attributes = dir(file_bindings.RepositoriesFileVersionsApi) # POST assertion for attr in repo_ver_attributes: assert "create" not in attr with pytest.raises(ApiException) as e: - file_client.call_api(repo.latest_version_href, "POST", auth_settings=["basicAuth"]) + file_bindings.client.call_api(repo.latest_version_href, "POST", auth_settings=["basicAuth"]) assert e.value.status == 405 body = {"base_version": f"{repo.versions_href}0/"} @@ -408,7 +409,7 @@ def test_content_immutable_repo_version( for attr in repo_ver_attributes: assert "update" not in attr with pytest.raises(ApiException) as e: - file_client.call_api( + file_bindings.client.call_api( repo.latest_version_href, "PUT", body=body, auth_settings=["basicAuth"] ) assert e.value.status == 405 @@ -417,7 +418,7 @@ def test_content_immutable_repo_version( for attr in repo_ver_attributes: assert "partial_update" not in attr with pytest.raises(ApiException) as e: - file_client.call_api( + file_bindings.client.call_api( repo.latest_version_href, "PATCH", body=body, auth_settings=["basicAuth"] ) assert e.value.status == 405 diff --git a/pulpcore/tests/functional/api/using_plugin/test_tasks.py b/pulpcore/tests/functional/api/using_plugin/test_tasks.py index d0bc86f3d6d..90349995bf1 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_tasks.py +++ b/pulpcore/tests/functional/api/using_plugin/test_tasks.py @@ -12,9 +12,9 @@ @pytest.fixture -def distribution(file_repo, file_distribution_api_client, gen_object_with_cleanup): +def distribution(file_bindings, file_repo, gen_object_with_cleanup): distribution = gen_object_with_cleanup( - file_distribution_api_client, + file_bindings.DistributionsFileApi, {"name": str(uuid4()), "base_path": str(uuid4()), "repository": file_repo.pulp_href}, ) @@ -42,6 +42,7 @@ def test_retrieve_task_with_fields_created_resources_only( @pytest.fixture def setup_filter_fixture( + file_bindings, file_repo, file_repository_api_client, file_remote_ssl_factory, @@ -52,7 +53,9 @@ def setup_filter_fixture( remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand") body = RepositorySyncURL(remote=remote.pulp_href) - repo_sync_task = monitor_task(file_repository_api_client.sync(file_repo.pulp_href, body).task) + repo_sync_task = monitor_task( + file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task + ) repo_update_action = file_repository_api_client.partial_update( file_repo.pulp_href, {"description": str(uuid4())} diff --git a/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py b/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py index ee64396f217..c34247ade5c 100644 --- a/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py +++ b/pulpcore/tests/functional/gpg_ascii_armor_signing_service.py @@ -1,16 +1,13 @@ -import asyncio import json -import os -import stat import subprocess import uuid -import aiohttp +import requests import gnupg import pytest -signing_script_string = r"""#!/usr/bin/env bash +SIGNING_SCRIPT_STRING = r"""#!/usr/bin/env bash FILE_PATH=$1 SIGNATURE_PATH="$1.asc" @@ -33,26 +30,24 @@ @pytest.fixture(scope="session") def signing_script_path(signing_script_temp_dir, signing_gpg_homedir_path): - signing_script_filename = signing_script_temp_dir / "sign-metadata.sh" - with open(signing_script_filename, "w", 0o770) as sign_metadata_file: - sign_metadata_file.write( - signing_script_string.replace("HOMEDIRHERE", str(signing_gpg_homedir_path)) - ) + signing_script_file = signing_script_temp_dir / "sign-metadata.sh" + signing_script_file.write_text( + SIGNING_SCRIPT_STRING.replace("HOMEDIRHERE", str(signing_gpg_homedir_path)) + ) - st = os.stat(signing_script_filename) - os.chmod(signing_script_filename, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + signing_script_file.chmod(0o755) - return signing_script_filename + return signing_script_file @pytest.fixture(scope="session") -def signing_script_temp_dir(tmpdir_factory): - yield tmpdir_factory.mktemp(str(uuid.uuid4())) +def signing_script_temp_dir(tmp_path_factory): + return tmp_path_factory.mktemp("sigining_script_dir") @pytest.fixture(scope="session") -def signing_gpg_homedir_path(tmpdir_factory): - return tmpdir_factory.mktemp(str(uuid.uuid4())) +def signing_gpg_homedir_path(tmp_path_factory): + return tmp_path_factory.mktemp("gpghome") @pytest.fixture @@ -87,18 +82,13 @@ def _sign_with_ascii_armored_detached_signing_service(filename): @pytest.fixture(scope="session") def signing_gpg_metadata(signing_gpg_homedir_path): """A fixture that returns a GPG instance and related metadata (i.e., fingerprint, keyid).""" - private_key_url = "https://raw.githubusercontent.com/pulp/pulp-fixtures/master/common/GPG-PRIVATE-KEY-fixture-signing" # noqa: E501 + PRIVATE_KEY_URL = "https://raw.githubusercontent.com/pulp/pulp-fixtures/master/common/GPG-PRIVATE-KEY-fixture-signing" # noqa: E501 - async def download_key(): - async with aiohttp.ClientSession() as session: - async with session.get(private_key_url) as response: - return await response.text() - - private_key_data = asyncio.run(download_key()) + response = requests.get(PRIVATE_KEY_URL) + response.raise_for_status() gpg = gnupg.GPG(gnupghome=signing_gpg_homedir_path) - - gpg.import_keys(private_key_data) + gpg.import_keys(response.content) fingerprint = gpg.list_keys()[0]["fingerprint"] keyid = gpg.list_keys()[0]["keyid"] diff --git a/pulpcore/tests/functional/utils.py b/pulpcore/tests/functional/utils.py index 1cb60c25f00..865a974ae5a 100644 --- a/pulpcore/tests/functional/utils.py +++ b/pulpcore/tests/functional/utils.py @@ -40,6 +40,21 @@ def __init__(self, task_group): self.task_group = task_group +class BindingsNamespace: + def __init__(self, module, client): + self.module = module + self.client = client + self.ApiException = self.module.exceptions.ApiException + + def __getattr__(self, name): + # __getattr__ is only consulted if nothing is found in __dict__. + assert name.endswith("Api") + + api_object = getattr(self.module, name)(self.client) + self.__dict__[name] = api_object + return api_object + + @dataclass class MockDownload: """Class for representing a downloaded file."""