Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting mirrorlist in yum repository config #5522

Merged
merged 1 commit into from
Jul 18, 2024
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
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
Loading