diff --git a/pulp_file/pytest_plugin.py b/pulp_file/pytest_plugin.py index ff4be06649..4c513988b0 100644 --- a/pulp_file/pytest_plugin.py +++ b/pulp_file/pytest_plugin.py @@ -69,14 +69,7 @@ def _file_distribution_factory(pulp_domain=None, **body): kwargs = {} if pulp_domain: kwargs["pulp_domain"] = pulp_domain - file_distribution = gen_object_with_cleanup(file_bindings.DistributionsFileApi, data, **kwargs) - - # if the base_url starts with / it means content_origin is not defined - if file_distribution.base_url.startswith("/"): - file_distribution.base_url.replace("/", bindings_cfg.host, 1) - return file_distribution - - + return gen_object_with_cleanup(file_bindings.DistributionsFileApi, data, **kwargs) return _file_distribution_factory @@ -387,3 +380,15 @@ def _generate_server_and_remote(*, manifest_path, policy): return server, remote yield _generate_server_and_remote + + +# if content_origin == null, base_url will return the relative path and +# we need to add the hostname to run the tests +@pytest.fixture +def file_distribution_base_url(bindings_cfg): + def _file_distribution_base_url(base_url): + if base_url.startswith("http"): + return base_url + return bindings_cfg.host+base_url + + return _file_distribution_base_url \ No newline at end of file diff --git a/pulpcore/pytest_plugin.py b/pulpcore/pytest_plugin.py index d8d97d9a3f..859bb33b6a 100644 --- a/pulpcore/pytest_plugin.py +++ b/pulpcore/pytest_plugin.py @@ -773,10 +773,10 @@ def pulp_api_v3_url(bindings_cfg, pulp_api_v3_path): @pytest.fixture(scope="session") -def pulp_content_url(pulp_settings, pulp_domain_enabled): +def pulp_content_url(bindings_cfg, pulp_settings, pulp_domain_enabled): url = f"{pulp_settings.CONTENT_ORIGIN}{pulp_settings.CONTENT_PATH_PREFIX}" if not pulp_settings.CONTENT_ORIGIN: - url = f"https://pulp{pulp_settings.CONTENT_PATH_PREFIX}" + url = f"{bindings_cfg.host}{pulp_settings.CONTENT_PATH_PREFIX}" if pulp_domain_enabled: url += "default/" diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_access.py b/pulpcore/tests/functional/api/using_plugin/test_content_access.py index 9029374865..8890af120f 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_access.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_access.py @@ -15,6 +15,7 @@ @pytest.mark.parallel def test_file_remote_on_demand( basic_manifest_path, + file_distribution_base_url, file_distribution_factory, file_fixtures_root, file_repo_with_auto_publish, @@ -39,7 +40,7 @@ def test_file_remote_on_demand( # Create a distribution from the publication distribution = file_distribution_factory(repository=repo.pulp_href) # attempt to download_file() a file - download_file(f"{distribution.base_url}/1.iso") + download_file(f"{file_distribution_base_url(distribution.base_url)}/1.iso") @pytest.mark.parallel diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py b/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py index fdd5582a7f..87004b0b3a 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_delivery.py @@ -14,6 +14,7 @@ @pytest.mark.parallel def test_delete_remote_on_demand( + file_distribution_base_url, file_repo_with_auto_publish, file_remote_ssl_factory, file_bindings, @@ -33,6 +34,7 @@ def test_delete_remote_on_demand( # Create a distribution pointing to the repository distribution = file_distribution_factory(repository=repo.pulp_href) + distribution_base_url = file_distribution_base_url(distribution.base_url) # Download the manifest from the remote expected_file_list = list(get_files_in_manifest(remote.url)) @@ -40,7 +42,7 @@ def test_delete_remote_on_demand( # Delete the remote and assert that downloading content returns a 404 monitor_task(file_bindings.RemotesFileApi.delete(remote.pulp_href).task) with pytest.raises(ClientResponseError) as exc: - url = urljoin(distribution.base_url, expected_file_list[0][0]) + url = urljoin(distribution_base_url, expected_file_list[0][0]) download_file(url) assert exc.value.status == 404 @@ -50,7 +52,7 @@ def test_delete_remote_on_demand( monitor_task(file_bindings.RepositoriesFileApi.sync(repo.pulp_href, body).task) # Assert that files can now be downloaded from the distribution - content_unit_url = urljoin(distribution.base_url, expected_file_list[0][0]) + content_unit_url = urljoin(distribution_base_url, expected_file_list[0][0]) downloaded_file = download_file(content_unit_url) actual_checksum = hashlib.sha256(downloaded_file.body).hexdigest() expected_checksum = expected_file_list[0][1] @@ -59,6 +61,7 @@ def test_delete_remote_on_demand( @pytest.mark.parallel def test_remote_artifact_url_update( + file_distribution_base_url, file_repo_with_auto_publish, file_remote_ssl_factory, file_bindings, @@ -79,13 +82,14 @@ def test_remote_artifact_url_update( # Create a distribution from the publication distribution = file_distribution_factory(repository=repo.pulp_href) + distribution_base_url = file_distribution_base_url(distribution.base_url) # Download the manifest from the remote expected_file_list = list(get_files_in_manifest(remote.url)) # Assert that trying to download content raises a 404 with pytest.raises(ClientResponseError) as exc: - url = urljoin(distribution.base_url, expected_file_list[0][0]) + url = urljoin(distribution_base_url, expected_file_list[0][0]) download_file(url) assert exc.value.status == 404 @@ -97,7 +101,7 @@ def test_remote_artifact_url_update( monitor_task( file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task ) - content_unit_url = urljoin(distribution.base_url, expected_file_list[0][0]) + content_unit_url = urljoin(distribution_base_url, expected_file_list[0][0]) downloaded_file = download_file(content_unit_url) actual_checksum = hashlib.sha256(downloaded_file.body).hexdigest() expected_checksum = expected_file_list[0][1] @@ -106,8 +110,8 @@ def test_remote_artifact_url_update( @pytest.mark.parallel def test_remote_content_changed_with_on_demand( - bindings_cfg, write_3_iso_file_fixture_data_factory, + file_distribution_base_url, file_repo_with_auto_publish, file_remote_ssl_factory, file_bindings, @@ -136,10 +140,7 @@ def test_remote_content_changed_with_on_demand( expected_file_list = list(get_files_in_manifest(remote.url)) write_3_iso_file_fixture_data_factory("basic", overwrite=True) - if distribution.base_url.startswith("http"): - get_url = urljoin(distribution.base_url, expected_file_list[0][0]) - else: - get_url = urljoin(bindings_cfg.host+distribution.base_url, expected_file_list[0][0]) + get_url = urljoin(file_distribution_base_url(distribution.base_url), expected_file_list[0][0]) # WHEN (first request) result = subprocess.run(["curl", "-v", get_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -160,6 +161,7 @@ def test_remote_content_changed_with_on_demand( @pytest.mark.parallel def test_handling_remote_artifact_on_demand_streaming_failure( write_3_iso_file_fixture_data_factory, + file_distribution_base_url, file_repo_with_auto_publish, file_remote_factory, file_bindings, @@ -219,7 +221,7 @@ def get_original_content_info(remote): return content_unit[0], content_unit[1] def download_from_distribution(content, distribution): - content_unit_url = urljoin(distribution.base_url, content_name) + content_unit_url = urljoin(file_distribution_base_url(distribution.base_url), content_name) downloaded_file = download_file(content_unit_url) actual_checksum = hashlib.sha256(downloaded_file.body).hexdigest() return actual_checksum diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_directory.py b/pulpcore/tests/functional/api/using_plugin/test_content_directory.py index 414f222538..7b7f0efa5c 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_directory.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_directory.py @@ -18,6 +18,7 @@ def test_hidden_distros(file_distribution_factory, pulp_content_url, http_get): def test_zero_byte_file_listing( file_bindings, file_distribution_factory, + file_distribution_base_url, file_repo_with_auto_publish, random_artifact_factory, http_get, @@ -37,8 +38,7 @@ def test_zero_byte_file_listing( ).task monitor_task(task) distribution = file_distribution_factory(repository=file_repo_with_auto_publish.pulp_href) - - response = http_get(distribution.base_url) + response = http_get(file_distribution_base_url(distribution.base_url)) z_line = [i for i in response.decode("utf-8").split("\n") if i.startswith('')] assert len(z_line) == 1 assert z_line[0].endswith("0 Bytes") diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_path.py b/pulpcore/tests/functional/api/using_plugin/test_content_path.py index a36c9a09bb..a2533f3737 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_path.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_path.py @@ -11,6 +11,7 @@ @pytest.mark.parallel def test_content_directory_listing( + bindings_cfg, pulpcore_bindings, file_distribution_factory, gen_object_with_cleanup, @@ -37,7 +38,7 @@ def test_content_directory_listing( content_origin = pulp_status.content_settings.content_origin if not content_origin: - content_origin = "https://pulp" + content_origin = bindings_cfg.host base_url = urljoin( content_origin, pulp_status.content_settings.content_path_prefix, diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py b/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py index d118aa0d82..d9dbc9bcae 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py @@ -12,6 +12,7 @@ @pytest.mark.parallel def test_content_promotion( file_bindings, + file_distribution_base_url, file_repo_with_auto_publish, file_remote_ssl_factory, file_distribution_factory, @@ -43,12 +44,13 @@ def test_content_promotion( for distro in [distribution1, distribution2, distribution3]: # Assert that all 3 distributions can be accessed - r = get_from_url(distro.base_url) + distro_base_url = file_distribution_base_url(distro.base_url) + r = get_from_url(distro_base_url) assert r.status == 200 # Download one of the files from the distribution and assert it has the correct checksum expected_files_list = list(expected_files) content_unit = expected_files_list[0] - content_unit_url = urljoin(distro.base_url, content_unit[0]) + content_unit_url = urljoin(distro_base_url, content_unit[0]) downloaded_file = download_file(content_unit_url) actual_checksum = hashlib.sha256(downloaded_file.body).hexdigest() expected_checksum = content_unit[1] diff --git a/pulpcore/tests/functional/api/using_plugin/test_contentguard.py b/pulpcore/tests/functional/api/using_plugin/test_contentguard.py index b6d66d9b75..b3f4ceea10 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_contentguard.py +++ b/pulpcore/tests/functional/api/using_plugin/test_contentguard.py @@ -14,6 +14,7 @@ def test_rbac_content_guard_full_workflow( pulpcore_bindings, file_bindings, + file_distribution_base_url, pulp_admin_user, anonymous_user, gen_user, @@ -44,7 +45,7 @@ def _assert_access(authorized_users): auth = BasicAuth(login=user.username, password=user.password) else: auth = None - response = get_from_url(distro.base_url, auth=auth) + response = get_from_url(file_distribution_base_url(distro.base_url), auth=auth) expected_status = 404 if user in authorized_users else 403 assert response.status == expected_status, f"Failed on {user.username=}" @@ -94,6 +95,7 @@ def _assert_access(authorized_users): def test_header_contentguard_workflow( pulpcore_bindings, file_bindings, + file_distribution_base_url, gen_user, file_distribution_factory, gen_object_with_cleanup, @@ -118,7 +120,8 @@ def test_header_contentguard_workflow( assert guard.pulp_href == distro.content_guard # Expect to receive a 403 Forbiden - response = get_from_url(distro.base_url, headers=None) + distro_base_url = file_distribution_base_url(distro.base_url) + response = get_from_url(distro_base_url, headers=None) assert response.status == 403 # Expect the status to be 404 given the distribution is accessible @@ -126,7 +129,7 @@ def test_header_contentguard_workflow( header_value = b64encode(b"123456").decode("ascii") headers = {"x-header": header_value} - response = get_from_url(distro.base_url, headers=headers) + response = get_from_url(distro_base_url, headers=headers) assert response.status == 404 # Check the access using an jq_filter @@ -160,7 +163,7 @@ def test_header_contentguard_workflow( header_value = b64encode(byte_header_content).decode("utf8") headers = {header_name: header_value} - response = get_from_url(distro.base_url, headers=headers) + response = get_from_url(file_distribution_base_url(distro.base_url), headers=headers) assert response.status == 404 diff --git a/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py b/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py index a287e053e6..e645e1c1c7 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py +++ b/pulpcore/tests/functional/api/using_plugin/test_reclaim_disk_space.py @@ -83,6 +83,7 @@ def _sync_repository_distribution(policy="immediate"): @pytest.mark.parallel def test_reclaim_on_demand_content( + file_distribution_base_url, pulpcore_bindings, sync_repository_distribution, monitor_task, @@ -93,8 +94,9 @@ def test_reclaim_on_demand_content( """ repo, remote, distribution = sync_repository_distribution(policy="on_demand") - content = get_files_in_manifest(urljoin(distribution.base_url, "PULP_MANIFEST")).pop() - download_file(urljoin(distribution.base_url, content[0])) + distribution_base_url = file_distribution_base_url(distribution.base_url) + content = get_files_in_manifest(urljoin(distribution_base_url, "PULP_MANIFEST")).pop() + download_file(urljoin(distribution_base_url, content[0])) expected_files = get_files_in_manifest(remote.url) artifact_sha256 = get_file_by_path(content[0], expected_files)[1] @@ -108,13 +110,14 @@ def test_reclaim_on_demand_content( assert 0 == pulpcore_bindings.ArtifactsApi.list(sha256=artifact_sha256).count - download_file(urljoin(distribution.base_url, content[0])) + download_file(urljoin(distribution_base_url, content[0])) assert 1 == pulpcore_bindings.ArtifactsApi.list(sha256=artifact_sha256).count @pytest.mark.parallel def test_immediate_reclaim_becomes_on_demand( + file_distribution_base_url, pulpcore_bindings, sync_repository_distribution, monitor_task, @@ -125,9 +128,10 @@ def test_immediate_reclaim_becomes_on_demand( artifacts_before_reclaim = pulpcore_bindings.ArtifactsApi.list().count assert artifacts_before_reclaim > 0 - content = get_files_in_manifest(urljoin(distribution.base_url, "PULP_MANIFEST")).pop() + distribution_base_url = file_distribution_base_url(distribution.base_url) + content = get_files_in_manifest(urljoin(distribution_base_url, "PULP_MANIFEST")).pop() # Populate cache - download_file(urljoin(distribution.base_url, content[0])) + download_file(urljoin(distribution_base_url, content[0])) reclaim_response = pulpcore_bindings.RepositoriesReclaimSpaceApi.reclaim( {"repo_hrefs": [repo.pulp_href]} @@ -138,7 +142,7 @@ def test_immediate_reclaim_becomes_on_demand( artifact_sha256 = get_file_by_path(content[0], expected_files)[1] assert 0 == pulpcore_bindings.ArtifactsApi.list(sha256=artifact_sha256).count - download_file(urljoin(distribution.base_url, content[0])) + download_file(urljoin(distribution_base_url, content[0])) assert 1 == pulpcore_bindings.ArtifactsApi.list(sha256=artifact_sha256).count 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 115dcba355..74170f2686 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_repo_versions.py @@ -793,6 +793,7 @@ def test_clear_all_units_repo_version( @pytest.mark.parallel def test_repo_version_retention( file_bindings, + file_distribution_base_url, file_repository_content, file_repository_factory, file_remote_ssl_factory, @@ -873,7 +874,8 @@ def test_repo_version_retention( # check that the last publication is distributed distro = file_distribution_factory(repository=repo.pulp_href) - manifest_files = get_files_in_manifest(f"{distro.base_url}PULP_MANIFEST") + distro_base_url = file_distribution_base_url(distro.base_url) + manifest_files = get_files_in_manifest(f"{distro_base_url}PULP_MANIFEST") assert len(manifest_files) == contents.count