Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES/3856.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Taught pulp_rpm to respond gracefully when CONTENT_ORIGIN is not set.

NOTE: Without CONTENT_ORIGIN, the plugin cannot autogenerate config.repo for a repository
unless a config-repo JSON has been provided which contains baseurl. Without CONTENT_ORIGIN
or a baseurl, requests for config.repo will return a 404.
2 changes: 1 addition & 1 deletion pulp_rpm/app/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions pulp_rpm/app/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from gettext import gettext as _

from pulpcore.plugin.exceptions import PulpException


Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
26 changes: 21 additions & 5 deletions pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
25 changes: 15 additions & 10 deletions pulp_rpm/tests/functional/api/test_consume_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@


@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):
subprocess.run(("sudo", "dnf", "config-manager", "--add-repo", distribution.base_url))
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",
Expand Down Expand Up @@ -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,
Expand All @@ -205,32 +208,34 @@ 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
assert "gpgcheck=1\n" in content


@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"
3 changes: 2 additions & 1 deletion pulp_rpm/tests/functional/api/test_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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,
Expand Down Expand Up @@ -301,7 +302,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"):
Expand Down
3 changes: 2 additions & 1 deletion pulp_rpm/tests/functional/api/test_fips_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Loading
Loading