Module "Yum Add Repo" should not replace "-" with "_" in repo_id

Bug #1975818 reported by Andrej Moravcik
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Undecided
Unassigned

Bug Description

Hello.

there is no need to replace character "-" with "_" in repo id add using "Yum Add Repo" cloud-init module. All RHEL, EPEL or other vendor's repo ids contain "-" as word separator (eg. rhel-7-server-rpms, rhel-7-server-extras-rpms, rhel-7-server-optional-rpms, rhel-7-server-supplementary-rpm, epel-modular, docker-ce-stable, ...). This behavior breaks consistency with standard RHEL repo id naming.

In this case I used OpenStack, RHEL 8.5 with cloud-init-21.1-7.el8._5.3.

Cloud-init user-data.yaml looks like this:

yum_repos:
  rhel-8.5-appstream-mycloud:
    baseurl: <url>
    name: "repo name"
    enabled: True
    ...

On deployed Nova instance result is:

ls /etc/yum.repos.d/
rhel_8.6_appstream_mycloud.repo

head rhel_8.6_appstream_mycloud.repo
# created by cloud-init on ...
[rhel_8.6_appstream_mycloud]
baseurl = ...
...

Expected result was:

/etc/yum.repos.d/rhel-8.5-appstream-mycloud.repo

with content

[rhel-8.5-appstream-mycloud]
baseurl = ...

I looked into code and found this function, where I recommend to remove this line:

git diff
diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py
index f7357192..8face5bf 100644
--- a/cloudinit/config/cc_yum_add_repo.py
+++ b/cloudinit/config/cc_yum_add_repo.py
@@ -118,7 +118,6 @@ __doc__ = get_meta_doc(meta)

 def _canonicalize_id(repo_id):
- repo_id = repo_id.lower().replace("-", "_")
     repo_id = repo_id.replace(" ", "_")
     return repo_id

Revision history for this message
Andrej Moravcik (andrejmoravcik) wrote :

Sorry, there is mismatch in bug description, but the point is clear, I hope. Just replace 8.6 with 8.5.

Revision history for this message
Alberto Contreras (aciba) wrote (last edit ):

Reproduced with:

```sh
cat <<EOT > /tmp/user-data.yaml
#cloud-config
yum_repos:
  rhel-8.5-appstream-mycloud:
    baseurl: <url>
    name: "repo name"
    enabled: True
EOT

lxc launch images:fedora/36/cloud fedora --config=user.user-data="$(cat /tmp/user-data.yaml)"
lxc exec fedora -- cloud-init status --wait
lxc exec fedora -- cat /etc/yum.repos.d/rhel_8.5_appstream_mycloud.repo
```

I did not find an official source saying that repo ids must contain "-" as word separator, but it looks like they do. Therefore, I think it would be safe to remove that line and let users have more control over repo names.

Changed in cloud-init:
status: New → Confirmed
Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Confirmed → Fix Committed
Revision history for this message
Brett Holman (holmanb) wrote : Fixed in cloud-init version 22.3.

This bug is believed to be fixed in cloud-init in version 22.3. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.