Skip to content

Commit

Permalink
Added to the distribution generate_repo_config field.
Browse files Browse the repository at this point in the history
closes #2985
  • Loading branch information
ipanova committed Sep 19, 2023
1 parent ecd6850 commit c9301db
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES/2985.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added to the distribution generate_repo_config field specifying whether Pulp should generate
``*.repo`` files. Defaults to False.
19 changes: 18 additions & 1 deletion docs/workflows/use_pulp_repo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Download GET response:
Install a package from Pulp
---------------------------
Download the config.repo file from the server at distribution's
If available, download the config.repo file from the server at distribution's
base_path and store it in /etc/yum.repos.d::

curl http://localhost:24816/pulp/content/foo/config.repo > /etc/yum.repos.d/foo.repo
Expand All @@ -54,6 +54,23 @@ Now use dnf to install a package::

sudo dnf install walrus

If config.repo file is not served by the distribution, it is necessary to manually set up the
configuration for the repository. One may initialize the configuration by leveraging the utility
``dnf config-manager`` like shown below. Afterwards, the user should be able to install the packages
by running dnf install packages.

.. code:: shell
BASE_URL=$(pulp rpm distribution show --name "${DIST_NAME}" | jq -r '.base_url')
BASE_PATH=$(pulp rpm distribution show --name "${DIST_NAME}" | jq -r '.base_path')
sudo dnf config-manager --add-repo "${BASE_URL}"
sudo dnf config-manager --save \
--setopt=*"${BASE_PATH}".gpgcheck=0 \
--setopt=*"${BASE_PATH}".repo_gpgcheck=0 \
sudo dnf install walrus
List and Install applicable Advisories
--------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.4 on 2023-09-06 14:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("rpm", "0052_modulemd_digest"),
]

operations = [
migrations.AddField(
model_name="rpmdistribution",
name="generate_repo_config",
field=models.BooleanField(default=False),
),
]
6 changes: 4 additions & 2 deletions pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,11 @@ class RpmDistribution(Distribution, AutoAddObjPermsMixin):
repository_config_file_name = "config.repo"
INVALID_REPO_ID_CHARS = r"[^\w\-_.:]"

generate_repo_config = models.BooleanField(default=False)

def content_handler(self, path):
"""Serve config.repo and repomd.xml.key."""
if path == self.repository_config_file_name:
if self.generate_repo_config and path == self.repository_config_file_name:
repository, publication = self.get_repository_and_publication()
if not publication:
return
Expand Down Expand Up @@ -504,7 +506,7 @@ def content_headers_for(self, path):
def content_handler_list_directory(self, rel_path):
"""Return the extra dir entries."""
retval = set()
if rel_path == "":
if self.generate_repo_config and rel_path == "":
retval.add(self.repository_config_file_name)
return retval

Expand Down
7 changes: 6 additions & 1 deletion pulp_rpm/app/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,14 @@ class RpmDistributionSerializer(DistributionSerializer):
queryset=Publication.objects.exclude(complete=False),
allow_null=True,
)
generate_repo_config = serializers.BooleanField(
default=False,
required=False,
help_text=_("An option specifying whether Pulp should generate *.repo files."),
)

class Meta:
fields = DistributionSerializer.Meta.fields + ("publication",)
fields = DistributionSerializer.Meta.fields + ("publication", "generate_repo_config")
model = RpmDistribution


Expand Down
22 changes: 18 additions & 4 deletions pulp_rpm/tests/functional/api/test_consume_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _create_distribution(
gpgcheck=None,
repo_gpgcheck=None,
has_signing_service=False,
generate_repo_config=False,
repo_body=None,
url=RPM_UNSIGNED_FIXTURE_URL,
policy="on_demand",
Expand All @@ -81,7 +82,9 @@ def _create_distribution(
pub_body["repo_gpgcheck"] = repo_gpgcheck
publication = rpm_publication_factory(**pub_body)

return rpm_distribution_factory(publication=publication.pulp_href)
return rpm_distribution_factory(
publication=publication.pulp_href, generate_repo_config=generate_repo_config
)

return _create_distribution

Expand Down Expand Up @@ -177,26 +180,35 @@ def test_publish_signed_repo_metadata(
"gpgcheck": [0, 1],
"repo_gpgcheck": [0, 1],
"has_signing_service": [True, False],
"generate_repo_config": [True, False],
}
func_params = itertools.product(*test_options.values())


@pytest.mark.parallel
@pytest.mark.parametrize("gpgcheck,repo_gpgcheck,has_signing_service", func_params)
@pytest.mark.parametrize(
"gpgcheck,repo_gpgcheck,has_signing_service,generate_repo_config", func_params
)
def test_config_dot_repo(
gpgcheck,
repo_gpgcheck,
has_signing_service,
generate_repo_config,
rpm_metadata_signing_service,
create_distribution,
http_get,
):
"""Test if the generated config.repo has the right content."""
if has_signing_service and rpm_metadata_signing_service is None:
pytest.skip("Need a signing service for this test")
if not generate_repo_config:
pytest.skip("Generation of config.repo file was disabled")

distribution = create_distribution(
gpgcheck=gpgcheck, repo_gpgcheck=repo_gpgcheck, has_signing_service=has_signing_service
gpgcheck=gpgcheck,
repo_gpgcheck=repo_gpgcheck,
has_signing_service=has_signing_service,
generate_repo_config=generate_repo_config,
)
content = http_get(f"{distribution.base_url}config.repo").decode("utf-8")

Expand All @@ -215,7 +227,9 @@ def test_repomd_headers(
http_get_headers,
):
"""Test if repomd.xml is returned with Cache-control: no-cache header."""
distribution = create_distribution(gpgcheck=1, repo_gpgcheck=1, has_signing_service=True)
distribution = create_distribution(
gpgcheck=1, repo_gpgcheck=1, has_signing_service=True, generate_repo_config=True
)
assert (
http_get_headers(f"{distribution.base_url}repodata/repomd.xml").get("Cache-control", "")
== "no-cache"
Expand Down
8 changes: 3 additions & 5 deletions pulp_rpm/tests/functional/api/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,8 @@ def test_directory_layout_distribute_with_modules(generate_distribution, http_ge
# Trailing '/' is present for easier check
assert "Packages/" in repository_root_items
assert "repodata/" in repository_root_items
assert "config.repo" in repository_root_items
# Only these three items should be present
assert len(repository_root_items) == 3
assert len(repository_root_items) == 2


@pytest.mark.parallel
Expand All @@ -757,10 +756,9 @@ def test_directory_layout_distribute_with_treeinfo(generate_distribution, http_g
assert directory in repository_root_items

assert "repodata/" in repository_root_items
assert "config.repo" in repository_root_items
# assert how many items are present altogether
# here is '+2' for 'repodata' and 'config.repo'
assert len(repository_root_items) == len(RPM_KICKSTART_REPOSITORY_ROOT_CONTENT) + 2
# here is '+1' for 'repodata'
assert len(repository_root_items) == len(RPM_KICKSTART_REPOSITORY_ROOT_CONTENT) + 1


@pytest.fixture(scope="class")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def setup_empty_distribution(
):
repo = rpm_repository_factory()
publication = rpm_publication_factory(repository=repo.pulp_href)
distribution = rpm_distribution_factory(publication=publication.pulp_href)
distribution = rpm_distribution_factory(
publication=publication.pulp_href, generate_repo_config=True
)

return repo, publication, distribution

Expand Down

0 comments on commit c9301db

Please sign in to comment.