Skip to content

Commit

Permalink
Support metalink in yum repository config (canonical#5444)
Browse files Browse the repository at this point in the history
'metalink' config can be specified instead or along with 'baseurl' in the yum
repository config. Add support for specifying metalink instead of 'baseurl'.

Fixes canonicalGH-5359

Signed-off-by: Ani Sinha <anisinha@redhat.com>
Co-authored-by: Ben Gray <ben.gray@clearcapital.com>
  • Loading branch information
ani-sinha and Ben Gray authored Jun 27, 2024
1 parent 8470af0 commit 5250260
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
24 changes: 11 additions & 13 deletions cloudinit/config/cc_yum_add_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,22 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
n_repo_config[k] = v
repo_config = n_repo_config
missing_required = 0
for req_field in ["baseurl"]:
req_fields = ["baseurl", "metalink"]
for req_field in req_fields:
if req_field not in repo_config:
LOG.warning(
"Repository %s does not contain a %s"
" configuration 'required' entry",
repo_id,
req_field,
)
missing_required += 1
if not missing_required:
repo_configs[canon_repo_id] = repo_config
repo_locations[canon_repo_id] = repo_fn_pth
else:

if missing_required == len(req_fields):
LOG.warning(
"Repository %s is missing %s required fields, skipping!",
"Repository %s should contain atleast one of the"
" following configuration entries: %s, skipping!",
repo_id,
missing_required,
", ".join(req_fields),
)
else:
repo_configs[canon_repo_id] = repo_config
repo_locations[canon_repo_id] = repo_fn_pth

for (c_repo_id, path) in repo_locations.items():
repo_blob = _format_repository_config(
c_repo_id, repo_configs.get(c_repo_id)
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/cloud-config-yum-repo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ yum_repos:
# Any repository configuration options
# See: man yum.conf
#
# This one is required!
# At least one of 'baseurl' or 'metalink' is required!
baseurl: http://download.fedoraproject.org/pub/epel/testing/5/$basearch
metalink: https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled: false
failovermethod: priority
gpgcheck: true
Expand Down
38 changes: 38 additions & 0 deletions tests/unittests/config/test_cc_yum_add_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_bad_config(self):
"yum_repos": {
"epel-testing": {
"name": "Extra Packages for Enterprise Linux 5 - Testing",
# At least one of baseurl or metalink must be present.
# Missing this should cause the repo not to be written
# 'baseurl': 'http://blah.org/pub/epel/testing/5/$barch',
"enabled": False,
Expand All @@ -46,6 +47,43 @@ def test_bad_config(self):
IOError, util.load_text_file, "/etc/yum.repos.d/epel_testing.repo"
)

def test_metalink_config(self):
cfg = {
"yum_repos": {
"epel-testing": {
"name": "Extra Packages for Enterprise Linux 5 - Testing",
"metalink": "http://blah.org/pub/epel/testing/5/$basearch",
"enabled": False,
"gpgcheck": True,
"gpgkey": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL",
"failovermethod": "priority",
},
},
}
self.patchUtils(self.tmp)
self.patchOS(self.tmp)
cc_yum_add_repo.handle("yum_add_repo", cfg, None, [])
contents = util.load_text_file("/etc/yum.repos.d/epel-testing.repo")
parser = configparser.ConfigParser()
parser.read_string(contents)
expected = {
"epel-testing": {
"name": "Extra Packages for Enterprise Linux 5 - Testing",
"failovermethod": "priority",
"gpgkey": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL",
"enabled": "0",
"metalink": "http://blah.org/pub/epel/testing/5/$basearch",
"gpgcheck": "1",
}
}
for section in expected:
self.assertTrue(
parser.has_section(section),
"Contains section {0}".format(section),
)
for k, v in expected[section].items():
self.assertEqual(parser.get(section, k), v)

def test_write_config(self):
cfg = {
"yum_repos": {
Expand Down

0 comments on commit 5250260

Please sign in to comment.