From a458d4482653787f54a98eee7a0e0021606aeece Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 6 Feb 2024 23:20:44 +0100 Subject: [PATCH] wip No-Issue --- .../tests/integration/api/test_api_base.py | 3 +- .../tests/integration/api/test_groups.py | 5 ++- galaxy_ng/tests/integration/api/test_move.py | 8 ++-- .../api/test_sync_enhancement_endpoints.py | 38 ++++++++---------- galaxy_ng/tests/integration/api/test_tasks.py | 39 ++++++++++++++----- .../api/test_upload_concurrency.py | 6 +-- .../api/test_upload_to_custom_repos.py | 29 ++++---------- .../integration/cli/test_dependencies.py | 12 +++--- 8 files changed, 73 insertions(+), 67 deletions(-) diff --git a/galaxy_ng/tests/integration/api/test_api_base.py b/galaxy_ng/tests/integration/api/test_api_base.py index 1414763aa9..9b873e286c 100644 --- a/galaxy_ng/tests/integration/api/test_api_base.py +++ b/galaxy_ng/tests/integration/api/test_api_base.py @@ -30,7 +30,8 @@ def test_galaxy_api_root(galaxy_client, artifact): assert "v3" in response["available_versions"] assert "pulp-v3" in response["available_versions"] - v3_root = gc.get(response['available_versions']['v3']) + # v3_root = gc.get(response['available_versions']['v3']) + v3_root = gc.get("v3/plugin/ansible/content/published/collections/") assert "published" in v3_root pulp_root = gc.get(response['available_versions']['pulp-v3']) diff --git a/galaxy_ng/tests/integration/api/test_groups.py b/galaxy_ng/tests/integration/api/test_groups.py index 50275ddabb..19c0e4cb17 100644 --- a/galaxy_ng/tests/integration/api/test_groups.py +++ b/galaxy_ng/tests/integration/api/test_groups.py @@ -40,7 +40,10 @@ def test_group_role_listing(galaxy_client, test_data): gc = galaxy_client("admin", ignore_cache=True) if not test_data["require_auth"]: gc = galaxy_client("basic_user", ignore_cache=True) - del gc.headers["Authorization"] + try: + del gc.headers["Authorization"] + except KeyError: + gc.gw_client.logout() remove_from_cache("basic_user") # Create Group diff --git a/galaxy_ng/tests/integration/api/test_move.py b/galaxy_ng/tests/integration/api/test_move.py index 5870cbae18..b7a0642009 100644 --- a/galaxy_ng/tests/integration/api/test_move.py +++ b/galaxy_ng/tests/integration/api/test_move.py @@ -58,10 +58,8 @@ def get_all_collections(): # import and wait ... resp = upload_artifact(None, gc_admin, artifact) wait_for_task(gc_admin, resp) - dest_url = ( - f"content/staging/v3/collections/{artifact.namespace}/" - f"{artifact.name}/versions/{artifact.version}/" - ) + dest_url = (f"content/staging/v3/plugin/ansible/content/staging/collections/" + f"index/{artifact.namespace}/{artifact.name}/versions/{artifact.version}/") wait_for_url(gc_admin, dest_url) # Make sure it ended up in staging but not in published ... @@ -147,6 +145,8 @@ def get_all_collections(): f"content/staging/v3/collections/{artifact.namespace}/" f"{artifact.name}/versions/{artifact.version}/" ) + dest_url = (f"content/staging/v3/plugin/ansible/content/staging/collections/" + f"index/{artifact.namespace}/{artifact.name}/versions/{artifact.version}/") wait_for_url(gc_admin, dest_url) # Make sure it ended up in staging ... diff --git a/galaxy_ng/tests/integration/api/test_sync_enhancement_endpoints.py b/galaxy_ng/tests/integration/api/test_sync_enhancement_endpoints.py index a40f9c3efd..3e60a94338 100644 --- a/galaxy_ng/tests/integration/api/test_sync_enhancement_endpoints.py +++ b/galaxy_ng/tests/integration/api/test_sync_enhancement_endpoints.py @@ -3,34 +3,30 @@ import pytest from ansible.galaxy.api import GalaxyError +from galaxykit.utils import GalaxyClientError from ..utils import get_client -def test_pulp_sync_enhancement_endpoints(ansible_config): +def test_pulp_sync_enhancement_endpoints(galaxy_client): """Tests whether the landing page returns the expected fields and numbers.""" - - client = get_client(config=ansible_config("admin"), - request_token=True, require_auth=True) - api_prefix = client.config.get("api_prefix").rstrip("/") - - # verify that the repo metadate endpoint works - results = client(f"{api_prefix}/v3/") - assert "published" in results + gc = galaxy_client("admin") + v3_root = gc.get("v3/plugin/ansible/content/published/collections/") + assert "published" in v3_root # verify that the unpaginated endpoints are disabled - with pytest.raises(GalaxyError) as ctx: - client(f"{api_prefix}/v3/collections/all/", method="GET") - assert ctx.value.http_code == 404 + with pytest.raises(GalaxyClientError) as ctx: + gc.get("v3/collections/all/", parse_json=False) + assert ctx.value.response.status_code == 404 - with pytest.raises(GalaxyError) as ctx: - client(f"{api_prefix}/v3/collection_versions/all/", method="GET") - assert ctx.value.http_code == 404 + with pytest.raises(GalaxyClientError) as ctx: + gc.get("v3/collection_versions/all/", parse_json=False) + assert ctx.value.response.status_code == 404 # verify that the content/ prefix works correctly unpaginated endpoints are disabled - with pytest.raises(GalaxyError) as ctx: - client(f"{api_prefix}/content/published/v3/collections/all/", method="GET") - assert ctx.value.http_code == 404 + with pytest.raises(GalaxyClientError) as ctx: + gc.get("content/published/v3/collections/all/", parse_json=False) + assert ctx.value.response.status_code == 404 - with pytest.raises(GalaxyError) as ctx: - client(f"{api_prefix}/content/published/v3/collection_versions/all/", method="GET") - assert ctx.value.http_code == 404 + with pytest.raises(GalaxyClientError) as ctx: + gc.get("content/published/v3/collection_versions/all/", parse_json=False) + assert ctx.value.response.status_code == 404 diff --git a/galaxy_ng/tests/integration/api/test_tasks.py b/galaxy_ng/tests/integration/api/test_tasks.py index 17fff85ed1..902a90baa0 100644 --- a/galaxy_ng/tests/integration/api/test_tasks.py +++ b/galaxy_ng/tests/integration/api/test_tasks.py @@ -12,15 +12,12 @@ @pytest.mark.pulp_api @pytest.mark.deployment_standalone @pytest.mark.min_hub_version("4.7dev") -def test_logging_cid_value_in_task(ansible_config): - # TODO: test with gateway +@pytest.mark.skip_in_gw +def test_logging_cid_value_in_task(galaxy_client, ansible_config): + gc = galaxy_client("admin") config = ansible_config("admin") - api_prefix = config.get("api_prefix").rstrip("/") - api_client = get_client(config, request_token=True) - - ans_repo = api_client( - f"{api_prefix}/pulp/api/v3/repositories/ansible/ansible/?name=rh-certified", - method="GET" + ans_repo = gc.get( + "pulp/api/v3/repositories/ansible/ansible/?name=rh-certified" )['results'][0] # extract pulp_id from pulp_href @@ -33,12 +30,36 @@ def test_logging_cid_value_in_task(ansible_config): payload={}) sync_task = sync_req.json()["task"] - logging_cid = api_client(sync_task)["logging_cid"] + logging_cid = gc.get(sync_task)["logging_cid"] assert logging_cid != "" assert sync_req.headers["Correlation-ID"] == logging_cid +@pytest.mark.pulp_api +@pytest.mark.deployment_standalone +@pytest.mark.min_hub_version("4.7dev") +def test_gateway_logging_cid_value_in_task(galaxy_client): + gc = galaxy_client("admin") + ans_repo = gc.get( + "pulp/api/v3/repositories/ansible/ansible/?name=rh-certified" + )['results'][0] + + # extract pulp_id from pulp_href + pulp_id = ans_repo["pulp_href"].split('/ansible/ansible/')[1].rstrip('/') + sync_req = gc.post( + f"pulp/api/v3/repositories/ansible/ansible/{pulp_id}/sync/", + body={}) + + correlation_id = gc.response.headers["Correlation-ID"] + + sync_task = sync_req["task"] + logging_cid = gc.get(sync_task)["logging_cid"] + + assert logging_cid != "" + assert correlation_id == logging_cid + + @pytest.mark.pulp_api @pytest.mark.deployment_standalone @pytest.mark.min_hub_version("4.7dev") diff --git a/galaxy_ng/tests/integration/api/test_upload_concurrency.py b/galaxy_ng/tests/integration/api/test_upload_concurrency.py index 985700b538..12c90ccb14 100644 --- a/galaxy_ng/tests/integration/api/test_upload_concurrency.py +++ b/galaxy_ng/tests/integration/api/test_upload_concurrency.py @@ -17,13 +17,13 @@ @pytest.mark.deployment_standalone def test_upload_concurrency(ansible_config, settings, galaxy_client): - total = 10 + total = 10 # 4 passes, 5 fails gc = galaxy_client("admin") # make a repo repo_name = f"repo-test-{generate_random_string()}" - create_repo_and_dist(gc, repo_name) + create_repo_and_dist(gc, repo_name) # publishing fails 504 gateway error # make 10 namespaces namespaces = [create_test_namespace(gc) for x in range(0, total)] @@ -37,7 +37,7 @@ def test_upload_concurrency(ansible_config, settings, galaxy_client): server_url = gc.galaxy_root + 'content/' + repo_name + '/' args_list = [f"collection publish -vvvv {x.filename}" for x in artifacts] - kwargs_list = [{'galaxy_client': gc, 'server_url': server_url} for x in artifacts] + kwargs_list = [{'galaxy_client': gc, 'server_url': server_url, 'server': repo_name} for x in artifacts] with concurrent.futures.ThreadPoolExecutor(max_workers=total) as executor: diff --git a/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py b/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py index acfa831b20..86a8f491b6 100644 --- a/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py +++ b/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py @@ -2,11 +2,12 @@ import subprocess import tempfile +from galaxykit.collections import get_collection_from_repo from ..utils import ( AnsibleDistroAndRepo, get_client, CollectionInspector, - wait_for_all_tasks + wait_for_all_tasks, ansible_galaxy ) from ..utils.repo_management_utils import create_repo_and_dist from ..utils.tasks import wait_for_all_tasks_gk @@ -15,34 +16,18 @@ def _upload_test_common(config, client, artifact, base_path, dest_base_path=None, gc=None): api_prefix = config.get("api_prefix") - url = config["url"] if dest_base_path is None: - url = f"{config['url']}content/{base_path}/" dest_base_path = base_path - cmd = [ - "ansible-galaxy", - "collection", - "publish", - "--api-key", - config["token"], - "--server", - url, - artifact.filename, - "--ignore-certs" - ] - proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - assert proc.returncode == 0 + ansible_galaxy( + f"collection publish {artifact.filename} -vvv", + galaxy_client=gc, server=base_path, server_url=gc.galaxy_root + f"content/{base_path}/" + ) if gc: wait_for_all_tasks_gk(gc) - collection_url = ( - f"content/{dest_base_path}/v3/collections/" - f"{artifact.namespace}/{artifact.name}/versions/1.0.0/" - ) - collection_resp = gc.get(collection_url) + collection_resp = get_collection_from_repo(gc, dest_base_path, artifact.namespace, artifact.name, "1.0.0") assert collection_resp["name"] == artifact.name else: wait_for_all_tasks(client) diff --git a/galaxy_ng/tests/integration/cli/test_dependencies.py b/galaxy_ng/tests/integration/cli/test_dependencies.py index ed73ecf487..fdd8ed2213 100644 --- a/galaxy_ng/tests/integration/cli/test_dependencies.py +++ b/galaxy_ng/tests/integration/cli/test_dependencies.py @@ -51,7 +51,7 @@ def test_collection_dependency_install(ansible_config, published, cleanup_collec - Dependency specs with no matching collections (galaxy-dev#104) - NPM-style specs (not part of semver) are invalid """ - + gc = galaxy_client("partner_engineer") spec = params.spec retcode = params.retcode artifact2 = build_collection(dependencies={f"{published.namespace}.{published.name}": spec}) @@ -60,8 +60,9 @@ def test_collection_dependency_install(ansible_config, published, cleanup_collec ansible_galaxy( f"collection publish {artifact2.filename} --server=automation_hub", check_retcode=retcode, - ansible_config=ansible_config("basic_user") + galaxy_client=gc ) + except AssertionError: if params.xfail: return pytest.xfail() @@ -70,17 +71,16 @@ def test_collection_dependency_install(ansible_config, published, cleanup_collec if retcode == 0: config = ansible_config("partner_engineer") - client = get_client(config) hub_4_5 = is_hub_4_5(ansible_config) - gc = galaxy_client("partner_engineer") - set_certification(client, gc, artifact2, hub_4_5=hub_4_5) + + set_certification(config, gc, artifact2, hub_4_5=hub_4_5) pid = ansible_galaxy( f"collection install -vvv --ignore-cert \ {artifact2.namespace}.{artifact2.name}:{artifact2.version} --server" f"=automation_hub", check_retcode=False, - ansible_config=ansible_config("basic_user"), + galaxy_client=gc # cleanup=False )