Skip to content

Commit

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

Fixes canonicalGH-5520
Signed-off-by: Ani Sinha <[email protected]>
  • Loading branch information
ani-sinha authored and holmanb committed Aug 2, 2024
1 parent dfc0345 commit 602e2a2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cloudinit/config/cc_yum_add_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
n_repo_config[k] = v
repo_config = n_repo_config
missing_required = 0
req_fields = ["baseurl", "metalink"]
req_fields = ["baseurl", "metalink", "mirrorlist"]
for req_field in req_fields:
if req_field not in repo_config:
missing_required += 1
Expand Down
10 changes: 10 additions & 0 deletions cloudinit/config/schemas/schema-cloud-config-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3457,6 +3457,11 @@
"format": "uri",
"description": "Specifies a URL to a metalink file for the repomd.xml"
},
"mirrorlist": {
"type": "string",
"format": "uri",
"description": "Specifies a URL to a file containing a baseurls list"
},
"name": {
"type": "string",
"description": "Optional human-readable name of the yum repo."
Expand Down Expand Up @@ -3494,6 +3499,11 @@
"required": [
"metalink"
]
},
{
"required": [
"mirrorlist"
]
}
]
}
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,9 +11,10 @@ yum_repos:
# Any repository configuration options
# See: man yum.conf
#
# At least one of 'baseurl' or 'metalink' is required!
# At least one of 'baseurl' or 'metalink' or 'mirrorlist' 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
mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&
enabled: false
failovermethod: priority
gpgcheck: true
Expand Down
40 changes: 39 additions & 1 deletion tests/unittests/config/test_cc_yum_add_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ 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.
# At least one of baseurl or metalink or mirrorlist
# 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 Down Expand Up @@ -84,6 +85,43 @@ def test_metalink_config(self):
for k, v in expected[section].items():
self.assertEqual(parser.get(section, k), v)

def test_mirrorlist_config(self):
cfg = {
"yum_repos": {
"epel-testing": {
"name": "Extra Packages for Enterprise Linux 5 - Testing",
"mirrorlist": "http://mirrors.blah.org/metalink?repo=rhel-$releasever",
"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",
"mirrorlist": "http://mirrors.blah.org/metalink?repo=rhel-$releasever",
"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 602e2a2

Please sign in to comment.