diff --git a/pulp_rpm/app/downloaders.py b/pulp_rpm/app/downloaders.py index 07dfc4dc3..2da96808a 100644 --- a/pulp_rpm/app/downloaders.py +++ b/pulp_rpm/app/downloaders.py @@ -176,7 +176,7 @@ async def _run(self, extra_data=None): if not self.session_key: self.session_key = await client.auth.login(self.username, self.password) if len(self.session_key) != 43: - raise UlnCredentialsError("No valid ULN credentials given.") + raise UlnCredentialsError() self.headers = {"X-ULN-API-User-Key": self.session_key} await client.close() # build request url from input uri diff --git a/pulp_rpm/app/exceptions.py b/pulp_rpm/app/exceptions.py index 3af30de06..bb420b7c6 100644 --- a/pulp_rpm/app/exceptions.py +++ b/pulp_rpm/app/exceptions.py @@ -1,3 +1,5 @@ +from gettext import gettext as _ + from pulpcore.plugin.exceptions import PulpException @@ -23,20 +25,17 @@ def __str__(self): return self.msg -class DistributionTreeConflict(PulpException): +class DistributionTreeConflict(FileNotFoundError): """ Raised when two or more distribution trees are being added to a repository version. """ def __init__(self, msg): """ - Set the exception identifier. - - Args: - msg(str): Detailed message about the reasons for Distribution Tree conflict + Set the exception identifier and msg. """ super().__init__("RPM0002") - self.msg = msg + self.msg = _("More than one distribution tree cannot be added to a " "repository version.") def __str__(self): """ @@ -52,13 +51,10 @@ class UlnCredentialsError(PulpException): def __init__(self, msg): """ - Set the exception identifier. - - Args: - msg(str): Detailed message about the reasons for Distribution Tree conflict + Set the exception identifier and msg. """ super().__init__("RPM0003") - self.msg = msg + self.msg = _("No valid ULN credentials given.") def __str__(self): """ diff --git a/pulp_rpm/app/models/repository.py b/pulp_rpm/app/models/repository.py index fb9b9c558..115f84986 100644 --- a/pulp_rpm/app/models/repository.py +++ b/pulp_rpm/app/models/repository.py @@ -487,9 +487,7 @@ def _resolve_distribution_trees(self, new_version, previous_version): incoming_disttrees = new_version.content.filter(pulp_type=disttree_pulp_type) if len(incoming_disttrees) != 1: - raise DistributionTreeConflict( - _("More than one distribution tree cannot be added to a " "repository version.") - ) + raise DistributionTreeConflict() class RpmPublication(Publication, AutoAddObjPermsMixin): @@ -529,10 +527,28 @@ def content_handler(self, path): repository, publication = self.get_repository_and_publication() if not publication: return + + # "Where content will be retrieved from" comes first from CONTENT_ORIGIN. + # If that's not set, use a specified baseurl. + # If *that* isn't set - fail, we can't build a config.repo because we + # don't have enough information to set the baseurl correctly. + origin = ( + settings.CONTENT_ORIGIN + if settings.CONTENT_ORIGIN + else publication.repo_config.get("baseurl") + ) + if not origin: + return Response( + status=404, + reason=_( + "Cannot auto-generate config.repo when CONTENT_ORIGIN is not set and " + "no baseurl specified." + ), + ) if settings.DOMAIN_ENABLED: base_url = "{}/".format( urlpath_sanitize( - settings.CONTENT_ORIGIN, + origin, settings.CONTENT_PATH_PREFIX, self.pulp_domain.name, self.base_path, @@ -541,7 +557,7 @@ def content_handler(self, path): else: base_url = "{}/".format( urlpath_sanitize( - settings.CONTENT_ORIGIN, + origin, settings.CONTENT_PATH_PREFIX, self.base_path, ) diff --git a/pulp_rpm/tests/functional/api/test_consume_content.py b/pulp_rpm/tests/functional/api/test_consume_content.py index 41f65215a..c5572e7a4 100644 --- a/pulp_rpm/tests/functional/api/test_consume_content.py +++ b/pulp_rpm/tests/functional/api/test_consume_content.py @@ -15,7 +15,7 @@ @pytest.fixture -def dnf_config_add_repo(): +def dnf_config_add_repo(distribution_base_url): added_repos = [] def _add_repo(distribution, has_signing_service=False): @@ -23,7 +23,9 @@ def _add_repo(distribution, has_signing_service=False): repo_id = "*{}_".format(distribution.base_path) args = ["sudo", "dnf", "config-manager", "--save", f"--setopt={repo_id}.gpgcheck=0"] if has_signing_service: - public_key_url = f"{distribution.base_url}repodata/repomd.xml.key" + public_key_url = ( + f"{distribution_base_url(distribution.base_url)}repodata/repomd.xml.key" + ) args.extend( ( f"--setopt={repo_id}.repo_gpgcheck=1", @@ -188,6 +190,7 @@ def test_publish_signed_repo_metadata( @pytest.mark.parallel @pytest.mark.parametrize("repo_config,has_signing_service,generate_repo_config", func_params) def test_config_dot_repo( + distribution_base_url, repo_config, has_signing_service, generate_repo_config, @@ -205,15 +208,18 @@ def test_config_dot_repo( has_signing_service=has_signing_service, generate_repo_config=generate_repo_config, ) - content = requests.get(f"{distribution.base_url}config.repo").text + content = requests.get(f"{distribution_base_url(distribution.base_url)}/config.repo").text assert f"[{distribution.name}]\n" in content - assert f"baseurl={distribution.base_url}\n" in content + assert f"baseurl={distribution_base_url(distribution.base_url)}\n" in content assert "gpgcheck=0\n" in content assert "repo_gpgcheck=0\n" in content if has_signing_service: - assert f"gpgkey={distribution.base_url}repodata/repomd.xml.key" in content + assert ( + f"gpgkey={distribution_base_url(distribution.base_url)}/repodata/repomd.xml.key" + in content + ) if repo_config: assert "assumeyes=True\n" in content @@ -221,16 +227,16 @@ def test_config_dot_repo( @pytest.mark.parallel -def test_repomd_headers(create_distribution): +def test_repomd_headers(create_distribution, distribution_base_url): """Test if repomd.xml is returned with Cache-control: no-cache header.""" distribution = create_distribution( repo_config={}, has_signing_service=True, generate_repo_config=True ) - resp = requests.get(f"{distribution.base_url}repodata/repomd.xml") + resp = requests.get(f"{distribution_base_url(distribution.base_url)}/repodata/repomd.xml") assert resp.headers.get("Cache-control", "") == "no-cache" - resp = requests.get(f"{distribution.base_url}config.repo") + resp = requests.get(f"{distribution_base_url(distribution.base_url)}/config.repo") assert not resp.headers.get("Cache-control", "") == "no-cache" - resp = requests.get(f"{distribution.base_url}repodata/repomd.xml.key") + resp = requests.get(f"{distribution_base_url(distribution.base_url)}/repodata/repomd.xml.key") assert resp.headers.get("Cache-control", "") == "no-cache" diff --git a/pulp_rpm/tests/functional/api/test_domains.py b/pulp_rpm/tests/functional/api/test_domains.py index fed161543..20b0a2216 100644 --- a/pulp_rpm/tests/functional/api/test_domains.py +++ b/pulp_rpm/tests/functional/api/test_domains.py @@ -252,6 +252,7 @@ def test_rpm_from_file( @pytest.mark.parallel def test_content_promotion( cleanup_domains, + distribution_base_url, pulpcore_bindings, download_content_unit, rpm_repository_api, @@ -297,7 +298,7 @@ def test_content_promotion( assert distro.publication == pub.pulp_href # Url structure should be host/CONTENT_ORIGIN/DOMAIN_PATH/BASE_PATH - assert domain.name == distro.base_url.rstrip("/").split("/")[-2] + assert domain.name == distribution_base_url(distro.base_url).rstrip("/").split("/")[-2] # Check that content can be downloaded from base_url for pkg in ("bear-4.1-1.noarch.rpm", "pike-2.2-1.noarch.rpm"): diff --git a/pulp_rpm/tests/functional/api/test_fips_workflow.py b/pulp_rpm/tests/functional/api/test_fips_workflow.py index ad8b9d840..ef9f7097a 100644 --- a/pulp_rpm/tests/functional/api/test_fips_workflow.py +++ b/pulp_rpm/tests/functional/api/test_fips_workflow.py @@ -176,6 +176,7 @@ def _name_from_url(url): ) def test_fips_workflow( url, + distribution_base_url, init_and_sync, rpm_rpmremote_factory, rpm_publication_factory, @@ -210,5 +211,5 @@ def test_fips_workflow( assert distribution is not None # Test we can access the index of the distribution - response = requests.get(distribution.base_url) + response = requests.get(distribution_base_url(distribution.base_url)) assert response is not None diff --git a/pulp_rpm/tests/functional/api/test_publish.py b/pulp_rpm/tests/functional/api/test_publish.py index 142f6a880..0f335e778 100644 --- a/pulp_rpm/tests/functional/api/test_publish.py +++ b/pulp_rpm/tests/functional/api/test_publish.py @@ -77,6 +77,7 @@ def test_publish_any_repo_version( @pytest.mark.parallel def test_publish_with_compression_types( self, + distribution_base_url, compression_type, compression_ext, rpm_unsigned_repo_immediate, @@ -98,13 +99,16 @@ def test_publish_with_compression_types( distribution = gen_object_with_cleanup(rpm_distribution_api, body) # 2. Check "primary", "filelists", "other", "updateinfo" have correct compression ext - for md_type, md_href in self.get_repomd_metadata_urls(distribution.base_url).items(): + for md_type, md_href in self.get_repomd_metadata_urls( + distribution_base_url(distribution.base_url) + ).items(): if md_type in ("primary", "filelists", "other", "updateinfo"): assert md_href.endswith(compression_ext) @pytest.mark.parallel def test_validate_no_checksum_tag( self, + distribution_base_url, rpm_unsigned_repo_immediate, rpm_publication_api, gen_object_with_cleanup, @@ -125,9 +129,11 @@ def test_validate_no_checksum_tag( distribution = gen_object_with_cleanup(rpm_distribution_api, body) # 2. check the tag 'sum' is not present in updateinfo.xml - update_xml_url = self.get_repomd_metadata_urls(distribution.base_url)["updateinfo"] + update_xml_url = self.get_repomd_metadata_urls( + distribution_base_url(distribution.base_url) + )["updateinfo"] update_xml = download_and_decompress_file( - os.path.join(distribution.base_url, update_xml_url) + os.path.join(distribution_base_url(distribution.base_url), update_xml_url) ) update_info_content = ElementTree.fromstring(update_xml) @@ -141,7 +147,7 @@ def get_repomd_metadata_urls(repomd_url: str): Example: ``` - >>> get_repomd_metadata_urls(distribution.base_url) + >>> get_repomd_metadata_urls(distribution_base_url(distribution.base_url)) { "primary": "repodata/.../primary.xml.gz", "filelists": "repodata/.../filelists.xml.gz", @@ -225,6 +231,7 @@ def test_publish_references_update(assert_created_publication): @pytest.mark.parametrize("repo_url", [RPM_COMPLEX_FIXTURE_URL, RPM_MODULAR_FIXTURE_URL]) def test_complex_repo_core_metadata( + distribution_base_url, repo_url, init_and_sync, rpm_publication_api, @@ -259,7 +266,9 @@ def test_complex_repo_core_metadata( ) reproduced_repomd = ElementTree.fromstring( - requests.get(os.path.join(distribution.base_url, "repodata/repomd.xml")).text + requests.get( + os.path.join(distribution_base_url(distribution.base_url), "repodata/repomd.xml") + ).text ) def get_metadata_content(base_url, repomd_elem, meta_type): @@ -292,7 +301,7 @@ def get_metadata_content(base_url, repomd_elem, meta_type): for metadata_file in ["primary", "filelists", "other"]: original_metadata = get_metadata_content(repo_url, original_repomd, metadata_file) generated_metadata = get_metadata_content( - distribution.base_url, reproduced_repomd, metadata_file + distribution_base_url(distribution.base_url), reproduced_repomd, metadata_file ) _compare_xml_metadata_file(original_metadata, generated_metadata, metadata_file) @@ -300,7 +309,9 @@ def get_metadata_content(base_url, repomd_elem, meta_type): # ================= original_modulemds = get_metadata_content(repo_url, original_repomd, "modules") - generated_modulemds = get_metadata_content(distribution.base_url, reproduced_repomd, "modules") + generated_modulemds = get_metadata_content( + distribution_base_url(distribution.base_url), reproduced_repomd, "modules" + ) assert bool(original_modulemds) == bool(generated_modulemds) @@ -316,7 +327,7 @@ def get_metadata_content(base_url, repomd_elem, meta_type): # TODO: make this deeper original_updateinfo = get_metadata_content(repo_url, original_repomd, "updateinfo") generated_updateinfo = get_metadata_content( - distribution.base_url, reproduced_repomd, "updateinfo" + distribution_base_url(distribution.base_url), reproduced_repomd, "updateinfo" ) assert bool(original_updateinfo) == bool(generated_updateinfo) @@ -411,6 +422,7 @@ def _compare_xml_metadata_file(original_metadata_text, generated_metadata_text, @pytest.mark.parallel @pytest.mark.parametrize("mirror", [True, False], ids=["mirror", "standard"]) def test_distribution_tree_metadata_publish( + distribution_base_url, mirror, gen_object_with_cleanup, rpm_repository_api, @@ -445,7 +457,9 @@ def test_distribution_tree_metadata_publish( # 4. Download and parse the metadata. original_treeinfo = requests.get(os.path.join(RPM_KICKSTART_FIXTURE_URL, ".treeinfo")).text - generated_treeinfo = requests.get(os.path.join(distribution.base_url, ".treeinfo")).text + generated_treeinfo = requests.get( + os.path.join(distribution_base_url(distribution.base_url), ".treeinfo") + ).text config = ConfigParser() config.optionxform = str # by default it will cast keys to lower case @@ -495,11 +509,17 @@ def test_distribution_tree_metadata_publish( continue checksum_type, checksum = checksum.split(":") - assert requests.get(os.path.join(distribution.base_url, path)).status_code == 200 + assert ( + requests.get( + os.path.join(distribution_base_url(distribution.base_url), path) + ).status_code + == 200 + ) @pytest.fixture def get_checksum_types( + distribution_base_url, init_and_sync, rpm_publication_api, gen_object_with_cleanup, @@ -531,7 +551,9 @@ def _get_checksum_types(**kwargs): distribution = gen_object_with_cleanup(rpm_distribution_api, body) repomd = ElementTree.fromstring( - requests.get(os.path.join(distribution.base_url, "repodata/repomd.xml")).text + requests.get( + os.path.join(distribution_base_url(distribution.base_url), "repodata/repomd.xml") + ).text ) data_xpath = "{{{}}}data".format(RPM_NAMESPACES["metadata/repo"]) @@ -547,7 +569,9 @@ def _get_checksum_types(**kwargs): location_xpath = "{{{}}}location".format(RPM_NAMESPACES["metadata/repo"]) primary_href = data_elem.find(location_xpath).get("href") primary = ElementTree.fromstring( - download_and_decompress_file(os.path.join(distribution.base_url, primary_href)) + download_and_decompress_file( + os.path.join(distribution_base_url(distribution.base_url), primary_href) + ) ) package_checksum_xpath = "{{{}}}checksum".format(RPM_NAMESPACES["metadata/common"]) package_xpath = "{{{}}}package".format(RPM_NAMESPACES["metadata/common"]) @@ -709,9 +733,12 @@ def test_immediate_specified_metadata_and_package_checksum_type(get_checksum_typ @pytest.mark.parallel -def test_directory_layout_distribute_with_modules(generate_distribution): +def test_directory_layout_distribute_with_modules( + distribution_base_url, + generate_distribution, +): """Ensure no more files or folders are present when distribute repository with modules.""" - distribution = generate_distribution(RPM_MODULAR_FIXTURE_URL) + distribution = distribution_base_url(generate_distribution(RPM_MODULAR_FIXTURE_URL)) parser = etree.XMLParser(recover=True) repository = etree.fromstring(requests.get(distribution).text, parser=parser) # Get links from repository HTML @@ -730,9 +757,12 @@ def test_directory_layout_distribute_with_modules(generate_distribution): @pytest.mark.parallel -def test_directory_layout_distribute_with_treeinfo(generate_distribution): +def test_directory_layout_distribute_with_treeinfo( + generate_distribution, + distribution_base_url, +): """Ensure no more files or folders are present when distribute repository with treeinfo.""" - distribution = generate_distribution(RPM_KICKSTART_FIXTURE_URL) + distribution = distribution_base_url(generate_distribution(RPM_KICKSTART_FIXTURE_URL)) parser = etree.XMLParser(recover=True) repository = etree.fromstring(requests.get(distribution).text, parser=parser) # Get links from repository HTML @@ -785,7 +815,7 @@ def _generate_distribution(url=None): body = gen_distribution(publication=publication_href) distribution = gen_object_with_cleanup(rpm_distribution_api, body) - - return distribution.to_dict()["base_url"] + print(distribution) + return distribution.base_url return _generate_distribution diff --git a/pulp_rpm/tests/functional/api/test_pulp_to_pulp.py b/pulp_rpm/tests/functional/api/test_pulp_to_pulp.py index 2e0460b16..2b72df09e 100644 --- a/pulp_rpm/tests/functional/api/test_pulp_to_pulp.py +++ b/pulp_rpm/tests/functional/api/test_pulp_to_pulp.py @@ -11,6 +11,7 @@ def test_pulp_pulp_sync( policy, init_and_sync, + distribution_base_url, rpm_repository_version_api, rpm_publication_api, rpm_distribution_factory, @@ -42,8 +43,9 @@ def test_pulp_pulp_sync( # Create another repo pointing to distribution base_url # Should this second policy always be "immediate"? - repo2, remote2 = init_and_sync(url=distribution.base_url, policy="immediate") - + repo2, remote2 = init_and_sync( + url=distribution_base_url(distribution.base_url), policy="immediate" + ) repo_ver = rpm_repository_version_api.read(repo.latest_version_href) summary = {k: v["count"] for k, v in repo_ver.content_summary.present.items()} repo_ver2 = rpm_repository_version_api.read(repo2.latest_version_href) diff --git a/pulp_rpm/tests/functional/api/test_sync.py b/pulp_rpm/tests/functional/api/test_sync.py index 4c8fd3b64..c82ab3967 100644 --- a/pulp_rpm/tests/functional/api/test_sync.py +++ b/pulp_rpm/tests/functional/api/test_sync.py @@ -1110,9 +1110,9 @@ def test_mirror_mode(sync_policy, init_and_sync, rpm_publication_api): @pytest.mark.parallel def test_config_repo_mirror_sync( + distribution_base_url, rpm_rpmremote_factory, rpm_repository_factory, - rpm_publication_factory, rpm_distribution_factory, rpm_repository_api, rpm_publication_api, @@ -1142,11 +1142,16 @@ def test_config_repo_mirror_sync( publication=publication.pulp_href, generate_repo_config=True ) - content = requests.get(f"{distribution.base_url}config.repo").content - - # gpgcheck should follow repo_config - # repo_gpgcheck should match whether the upstream repo has signed metadata or not - assert bytes(f"[{distribution.name}]\n", "utf-8") in content - assert bytes(f"baseurl={distribution.base_url}\n", "utf-8") in content - assert bytes("gpgcheck=1\n", "utf-8") in content - assert bytes("repo_gpgcheck=0", "utf-8") in content + response = requests.get(f"{distribution_base_url(distribution.base_url)}/config.repo") + if not settings.CONTENT_ORIGIN: + assert response.status_code == 404 + else: + content = response.content + # gpgcheck should follow repo_config + # repo_gpgcheck should match whether the upstream repo has signed metadata or not + assert bytes(f"[{distribution.name}]\n", "utf-8") in content + assert ( + bytes(f"baseurl={distribution_base_url(distribution.base_url)}\n", "utf-8") in content + ) + assert bytes("gpgcheck=1\n", "utf-8") in content + assert bytes("repo_gpgcheck=0", "utf-8") in content diff --git a/pulp_rpm/tests/functional/content_handler/test_config_repo.py b/pulp_rpm/tests/functional/content_handler/test_config_repo.py index e6f11e916..f29255c40 100644 --- a/pulp_rpm/tests/functional/content_handler/test_config_repo.py +++ b/pulp_rpm/tests/functional/content_handler/test_config_repo.py @@ -1,5 +1,6 @@ import pytest import requests +from django.conf import settings @pytest.fixture @@ -16,6 +17,13 @@ def setup_empty_distribution( @pytest.mark.parallel +# For the CONTENT_ORIGIN-set tests, we explicitly **do not** use distribution_base_url - +# since in that case, we *should* be able to use distribution.base_url with the +# current semantics, and if that doesn't work, then we've broken something. +@pytest.mark.skipif( + not settings.CONTENT_ORIGIN, + reason="If you don't set CONTENT_ORIGIN Pulp can't create the config.repo for you", +) def test_config_repo_in_listing_unsigned(setup_empty_distribution): """Whether the served resources are in the directory listing.""" _, _, dist = setup_empty_distribution @@ -26,10 +34,17 @@ def test_config_repo_in_listing_unsigned(setup_empty_distribution): @pytest.mark.parallel +# For the CONTENT_ORIGIN-set tests, we explicitly **do not** use distribution_base_url - +# since in that case, we *should* be able to use distribution.base_url with the +# current semantics, and if that doesn't work, then we've broken something. +@pytest.mark.skipif( + not settings.CONTENT_ORIGIN, + reason="If you don't set CONTENT_ORIGIN Pulp can't create the config.repo for you", +) def test_config_repo_unsigned(setup_empty_distribution): """Whether config.repo can be downloaded and has the right content.""" _, _, dist = setup_empty_distribution - content = requests.get(f"{dist.base_url}config.repo").content + content = requests.get(f"{dist.base_url}/config.repo").content assert bytes(f"[{dist.name}]\n", "utf-8") in content assert bytes(f"baseurl={dist.base_url}\n", "utf-8") in content @@ -38,20 +53,28 @@ def test_config_repo_unsigned(setup_empty_distribution): @pytest.mark.parallel +# For the CONTENT_ORIGIN-set tests, we explicitly **do not** use distribution_base_url - +# since in that case, we *should* be able to use distribution.base_url with the +# current semantics, and if that doesn't work, then we've broken something. +@pytest.mark.skipif( + not settings.CONTENT_ORIGIN, + reason="If you don't set CONTENT_ORIGIN Pulp can't create the config.repo for you", +) def test_config_repo_auto_distribute( setup_empty_distribution, rpm_publication_api, rpm_distribution_api, monitor_task ): """Whether config.repo is properly served using auto-distribute.""" repo, pub, dist = setup_empty_distribution - body = {"repository": repo.pulp_href, "publication": None} + body = {"repository": repo.pulp_href, "publication": None, "generate_repo_config": True} monitor_task(rpm_distribution_api.partial_update(dist.pulp_href, body).task) # Check that distribution is now using repository to auto-distribute dist = rpm_distribution_api.read(dist.pulp_href) assert repo.pulp_href == dist.repository assert dist.publication is None - content = requests.get(f"{dist.base_url}config.repo").content + rslt = requests.get(f"{dist.base_url}/config.repo") + content = rslt.content assert bytes(f"[{dist.name}]\n", "utf-8") in content assert bytes(f"baseurl={dist.base_url}\n", "utf-8") in content assert bytes("gpgcheck=0\n", "utf-8") in content @@ -60,3 +83,15 @@ def test_config_repo_auto_distribute( # Delete publication and check that 404 is now returned rpm_publication_api.delete(pub.pulp_href) assert requests.get(f"{dist.base_url}config.repo").status_code == 404 + + +@pytest.mark.parallel +@pytest.mark.skipif( + not (settings.CONTENT_ORIGIN == ""), + reason="A This test only makes sense if you HAVE NOT set CONTENT_ORIGIN", +) +def test_config_repo_no_content_origin(distribution_base_url, setup_empty_distribution): + """Whether the served resources are in the directory listing.""" + _, _, dist = setup_empty_distribution + response = requests.get(f"{distribution_base_url(dist.base_url)}/config.repo") + assert response.status_code == 404 diff --git a/pulp_rpm/tests/performance/test_publish.py b/pulp_rpm/tests/performance/test_publish.py index 0389fd084..eaf67a5c8 100644 --- a/pulp_rpm/tests/performance/test_publish.py +++ b/pulp_rpm/tests/performance/test_publish.py @@ -48,11 +48,16 @@ def parse_date_from_string(s, parse_format="%Y-%m-%dT%H:%M:%S.%fZ"): @pytest.fixture -def centos_8stream_baseos_extra_tests(rpm_distribution_factory): +def centos_8stream_baseos_extra_tests( + rpm_distribution_factory, + distribution_base_url, +): def _extra_test(publication_href): # Test that the .treeinfo file is available and AppStream sub-repo is published correctly distribution = rpm_distribution_factory(publication=publication_href) - treeinfo_file = requests.get(urljoin(distribution.base_url, ".treeinfo")).content + treeinfo_file = requests.get( + urljoin(distribution_base_url(distribution.base_url), ".treeinfo") + ).content treeinfo = TreeInfo() with NamedTemporaryFile("wb") as temp_file: temp_file.write(treeinfo_file) @@ -68,7 +73,8 @@ def _extra_test(publication_href): # Find the first package in the 'AppStream/Packages/a/' directory and download it parser = PackagesHtmlParser() a_packages_href = urljoin( - distribution.base_url, "{}/a/".format(variant.paths.packages) + distribution_base_url(distribution.base_url), + "{}/a/".format(variant.paths.packages), ) a_packages_listing = requests.get(a_packages_href).text parser.feed(a_packages_listing) diff --git a/pulp_rpm/tests/performance/test_pulp_to_pulp.py b/pulp_rpm/tests/performance/test_pulp_to_pulp.py index 215309472..39e5bb91a 100644 --- a/pulp_rpm/tests/performance/test_pulp_to_pulp.py +++ b/pulp_rpm/tests/performance/test_pulp_to_pulp.py @@ -16,6 +16,7 @@ def test_pulp_to_pulp( rpm_publication_factory, rpm_distribution_factory, rpm_repository_version_api, + distribution_base_url, ): """Verify whether content served by pulp can be synced. @@ -41,7 +42,7 @@ def test_pulp_to_pulp( # Create another repo pointing to distribution base_url repo2, remote2, task = init_and_sync( - url=distribution.base_url, policy="on_demand", return_task=True + url=distribution_base_url(distribution.base_url), policy="on_demand", return_task=True ) task_duration = task.finished_at - task.started_at waiting_time = task.started_at - task.pulp_created diff --git a/pulp_rpm/tests/upgrade/__init__.py b/pulp_rpm/tests/upgrade/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/pulp_rpm/tests/upgrade/post/__init__.py b/pulp_rpm/tests/upgrade/post/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/pulp_rpm/tests/upgrade/post/test_publish.py b/pulp_rpm/tests/upgrade/post/test_publish.py deleted file mode 100644 index df1d16b8a..000000000 --- a/pulp_rpm/tests/upgrade/post/test_publish.py +++ /dev/null @@ -1,116 +0,0 @@ -"""Tests that publish rpm plugin repositories.""" - -from random import choice - - -from pulp_smash import config -from pulp_smash.pulp3.bindings import PulpTestCase, monitor_task -from pulp_smash.pulp3.utils import ( - gen_repo, - get_content, - gen_distribution, - get_versions, - modify_repo, -) - -from pulp_rpm.tests.functional.constants import RPM_PACKAGE_CONTENT_NAME -from pulp_rpm.tests.functional.utils import gen_rpm_client, gen_rpm_remote -from pulp_rpm.tests.functional.utils import set_up_module as setUpModule # noqa:F401 - -from pulpcore.client.pulp_rpm import ( - DistributionsRpmApi, - PublicationsRpmApi, - RepositoriesRpmApi, - RpmRepositorySyncURL, - RemotesRpmApi, - RpmRpmPublication, -) -from pulpcore.client.pulp_rpm.exceptions import ApiException - - -class PublishAnyRepoVersionTestCase(PulpTestCase): - """Test whether a particular repository version can be published. - - This test targets the following issues: - - * `Pulp #3324 `_ - * `Pulp Smash #897 `_ - """ - - def test_all(self): - """Test whether a particular repository version can be published. - - 1. Create a repository with at least 2 repository versions. - 2. Create a publication by supplying the latest ``repository_version``. - 3. Assert that the publication ``repository_version`` attribute points - to the latest repository version. - 4. Create a publication by supplying the non-latest ``repository_version``. - 5. Assert that the publication ``repository_version`` attribute points - to the supplied repository version. - 6. Assert that an exception is raised when providing two different - repository versions to be published at same time. - """ - cfg = config.get_config() - client = gen_rpm_client() - repo_api = RepositoriesRpmApi(client) - remote_api = RemotesRpmApi(client) - publications = PublicationsRpmApi(client) - distributions = DistributionsRpmApi(client) - - dist_path = "/pulp/content/pulp_pre_upgrade_test" - url = cfg.get_content_host_base_url() + dist_path - body = gen_rpm_remote(url=url) - remote = remote_api.create(body) - - repo = repo_api.create(gen_repo()) - - repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) - sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) - monitor_task(sync_response.task) - - # Step 1 - repo = repo_api.read(repo.pulp_href) - repo_content = get_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME] - for rpm_content in repo_content: - modify_repo(cfg, repo.to_dict(), remove_units=[rpm_content]) - version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo.to_dict())) - non_latest = choice(version_hrefs[1:-1]) - - # Step 2 - publish_data = RpmRpmPublication(repository=repo.pulp_href) - publish_response = publications.create(publish_data) - created_resources = monitor_task(publish_response.task).created_resources - publication_href = created_resources[0] - publication = publications.read(publication_href) - - # Step 3 - self.assertEqual(publication.repository_version, version_hrefs[-1]) - - # Step 4 - publish_data.repository_version = non_latest - publish_data.repository = None - publish_response = publications.create(publish_data) - created_resources = monitor_task(publish_response.task).created_resources - publication_href = created_resources[0] - publication = publications.read(publication_href) - - # Step 5 - body = gen_distribution() - body["base_path"] = "pulp_post_upgrade_test" - body["publication"] = publication.pulp_href - - distribution_response = distributions.create(body) - created_resources = monitor_task(distribution_response.task).created_resources - distribution = distributions.read(created_resources[0]) - - # Step 6 - self.assertEqual(publication.repository_version, non_latest) - - # Step 7 - with self.assertRaises(ApiException): - body = {"repository": repo.pulp_href, "repository_version": non_latest} - publications.create(body) - - # Step 8 - url = cfg.get_content_host_base_url() + "/pulp/content/pulp_post_upgrade_test/" - self.assertEqual(url, distribution.base_url, url) diff --git a/pulp_rpm/tests/upgrade/pre/__init__.py b/pulp_rpm/tests/upgrade/pre/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/pulp_rpm/tests/upgrade/pre/test_publish.py b/pulp_rpm/tests/upgrade/pre/test_publish.py deleted file mode 100644 index 6054b8783..000000000 --- a/pulp_rpm/tests/upgrade/pre/test_publish.py +++ /dev/null @@ -1,114 +0,0 @@ -"""Tests that publish rpm plugin repositories.""" - -from random import choice - - -from pulp_smash import config -from pulp_smash.pulp3.bindings import PulpTestCase, monitor_task -from pulp_smash.pulp3.utils import ( - gen_repo, - get_content, - gen_distribution, - get_versions, - modify_repo, -) - -from pulp_rpm.tests.functional.constants import RPM_PACKAGE_CONTENT_NAME -from pulp_rpm.tests.functional.utils import gen_rpm_client, gen_rpm_remote -from pulp_rpm.tests.functional.utils import set_up_module as setUpModule # noqa:F401 - -from pulpcore.client.pulp_rpm import ( - DistributionsRpmApi, - PublicationsRpmApi, - RepositoriesRpmApi, - RpmRepositorySyncURL, - RemotesRpmApi, - RpmRpmPublication, -) -from pulpcore.client.pulp_rpm.exceptions import ApiException - - -class PublishAnyRepoVersionTestCase(PulpTestCase): - """Test whether a particular repository version can be published. - - This test targets the following issues: - - * `Pulp #3324 `_ - * `Pulp Smash #897 `_ - """ - - def test_all(self): - """Test whether a particular repository version can be published. - - 1. Create a repository with at least 2 repository versions. - 2. Create a publication by supplying the latest ``repository_version``. - 3. Assert that the publication ``repository_version`` attribute points - to the latest repository version. - 4. Create a publication by supplying the non-latest ``repository_version``. - 5. Assert that the publication ``repository_version`` attribute points - to the supplied repository version. - 6. Assert that an exception is raised when providing two different - repository versions to be published at same time. - """ - cfg = config.get_config() - client = gen_rpm_client() - repo_api = RepositoriesRpmApi(client) - remote_api = RemotesRpmApi(client) - publications = PublicationsRpmApi(client) - distributions = DistributionsRpmApi(client) - - body = gen_rpm_remote() - remote = remote_api.create(body) - - repo = repo_api.create(gen_repo()) - - repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) - sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) - monitor_task(sync_response.task) - - # Step 1 - repo = repo_api.read(repo.pulp_href) - repo_content = get_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME][:-1] - for rpm_content in repo_content: - modify_repo(cfg, repo.to_dict(), remove_units=[rpm_content]) - version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo.to_dict())) - non_latest = choice(version_hrefs[1:-1]) - - # Step 2 - publish_data = RpmRpmPublication(repository=repo.pulp_href) - publish_response = publications.create(publish_data) - created_resources = monitor_task(publish_response.task).created_resources - publication_href = created_resources[0] - publication = publications.read(publication_href) - - # Step 3 - self.assertEqual(publication.repository_version, version_hrefs[-1]) - - # Step 4 - publish_data.repository_version = non_latest - publish_data.repository = None - publish_response = publications.create(publish_data) - created_resources = monitor_task(publish_response.task).created_resources - publication_href = created_resources[0] - publication = publications.read(publication_href) - - # Step 5 - body = gen_distribution() - body["base_path"] = "pulp_pre_upgrade_test" - body["publication"] = publication.pulp_href - - distribution_response = distributions.create(body) - created_resources = monitor_task(distribution_response.task).created_resources - distribution = distributions.read(created_resources[0]) - - # Step 6 - self.assertEqual(publication.repository_version, non_latest) - - # Step 7 - with self.assertRaises(ApiException): - body = {"repository": repo.pulp_href, "repository_version": non_latest} - publications.create(body) - - # Step 8 - url = cfg.get_content_host_base_url() + "/pulp/content/pulp_pre_upgrade_test/" - self.assertEqual(url, distribution.base_url, url) diff --git a/pyproject.toml b/pyproject.toml index 13977dc85..8ccf01931 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ "jsonschema>=4.6,<5.0", "libcomps>=0.1.20.post1,<0.2", "productmd~=1.33.0", - "pulpcore>=3.49.11,<3.70", + "pulpcore>=3.49.11,<3.85", "solv~=0.7.21", "aiohttp_xmlrpc~=1.5.0", "importlib-resources~=6.4.0", @@ -141,4 +141,4 @@ replace = "version = \"{new_version}\"" filename = "./pyproject.toml" search = "version = \"{current_version}\"" -replace = "version = \"{new_version}\"" \ No newline at end of file +replace = "version = \"{new_version}\""