Bug 2182407
| Summary: | cloud-init strips new line from "/etc/hostname" when processing "/var/lib/cloud/data/previous-hostname" | |||
|---|---|---|---|---|
| Product: | Red Hat Enterprise Linux 8 | Reporter: | Marian Jankular <mjankula> | |
| Component: | cloud-init | Assignee: | Ani Sinha <anisinha> | |
| Status: | CLOSED ERRATA | QA Contact: | xiachen | |
| Severity: | medium | Docs Contact: | ||
| Priority: | unspecified | |||
| Version: | 8.7 | CC: | andavis, anisinha, bdas, eesposit, eterrell, huzhao, jgreguske, jmaloy, xiachen, xiliang, yacao | |
| Target Milestone: | rc | Keywords: | Triaged | |
| Target Release: | --- | Flags: | pm-rhel:
mirror+
|
|
| Hardware: | Unspecified | |||
| OS: | Unspecified | |||
| Whiteboard: | ||||
| Fixed In Version: | cloud-init-23.1.1-3.el8 | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | ||
| Clone Of: | ||||
| : | 2184608 (view as bug list) | Environment: | ||
| Last Closed: | 2023-11-14 15:31:09 UTC | Type: | Bug | |
| Regression: | --- | Mount Type: | --- | |
| Documentation: | --- | CRM: | ||
| Verified Versions: | Category: | --- | ||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | ||
| Cloudforms Team: | --- | Target Upstream Version: | ||
| Embargoed: | ||||
| Bug Depends On: | ||||
| Bug Blocks: | 2184608 | |||
|
Description
Marian Jankular
2023-03-28 14:58:57 UTC
Although the problem doesn't have a serious influence, it is there. Set QA_ACK+.
I added some test codes to /usr/lib/python3.9/site-packages/cloudinit/distros/__init__.py
if sys_hostname and prev_hostname and sys_hostname != prev_hostname:
LOG.info(sys_hostname) #test code
LOG.info(prev_hostname) #test code
LOG.info(
"%s differs from %s, assuming user maintained hostname.",
prev_hostname_fn,
sys_fn,
)
return
and then reboot the instance, we can see that LOG.info(sys_hostname) output with newline, but LOG.info(prev_hostname) does not contain newline.
2023-03-30 08:55:29,843 - subp.py[DEBUG]: Running command ['hostname'] with allowed return codes [0] (shell=False, capture=True)
2023-03-30 08:55:29,845 - __init__.py[INFO]: xiachen-test-vm
2023-03-30 08:55:29,845 - __init__.py[INFO]: xiachen-test-vm
2023-03-30 08:55:29,845 - __init__.py[INFO]: /var/lib/cloud/data/previous-hostname differs from /etc/hostname, assuming user maintained hostname.
------------------------------------------------------
And I tested ubuntu, it doesn't have this problem.
-------------
ubuntu@xiachen-test-ubuntu:~$ cat /etc/hostname
xiachen-test-ubuntu
ubuntu@xiachen-test-ubuntu:~$ cat /var/lib/cloud/data/previous-hostname
xiachen-test-ubuntu
ubuntu@xiachen-test-ubuntu:~$
-------------
Comparing to other distros, like ubuntu or debian, the differences are functions of read/write_hostname in /usr/lib/python3.9/site-packages/cloudinit/distros/rhel.py,
when read_hostname using command 'hostname' which contains newline, but it doesn't write newline to /var/lib/cloud/data/previous-hostname.
There is a Parser 'cloudinit.distros.parsers.hostname' that deals with how to work with /etc/hostname format, maybe we could also import and use it.
Upstream ticket: https://bugs.launchpad.net/cloud-init/+bug/2015043 reply to Ani Sinha from comment #5) > (In reply to Marian Jankular from comment #4) > > Created attachment 1955398 [details] > > cloud-init log > > > > not sure if the patch fixes the issue as i have installed new rpm on my > > reproducer (rhel8.7) > > > > 1, initial hostname - mj-rhel87 > > 2, reboot > > 3, cloud init reported that hostname and previous hostname differs > > ~~~ > > [root@mj-rhel87 ~]# cat /var/lib/cloud/data/previous-hostname > > mj-rhel87[root@mj-rhel87 ~]# hostnamectl set-hostname mj-rhel87-new > > ~~~ > > > > 4, changed hostname to mj-rhel87-new > > 5, reboot > > 6, cloud-init reported that hostname and previous hostname differs > > ~~~ > > [root@mj-rhel87-new ~]# cat /var/lib/cloud/data/previous-hostname > > mj-rhel87[root@mj-rhel87hostnamectl set-hostname mj-rhel87-new-new > > ~~~ > > > > 7, reboot > > 8, cloud-init reported that hostname and previous hostname differs > > ~~~ > > [root@mj-rhel87-new-new ~]# cat /var/lib/cloud/data/previous-hostname > > mj-rhel87[root@mj-rhel87-new-new ~]# rpm -qa | grep cloud-init > > cloud-init-22.1-6.el8.2.anisinha202303311339.noarch > > ~~~ > > > > i would say the /var/lib/cloud/data/previous-hostname should change in my > > case right? > > I had to delete previous-hostname for it to get regenerated. In your case, > it seems cloud-init is not updating the file at all, so you don't know if it > works or not. Delete "previous-hostname" and then install the updated rpm > and check. I see this code in update_hostname() and this explains it: # If something else has changed the hostname after we set it # initially, we should not overwrite those changes (we should # only be setting the hostname once per instance) if sys_hostname and prev_hostname and sys_hostname != prev_hostname: LOG.info( "%s differs from %s, assuming user maintained hostname.", prev_hostname_fn, sys_fn, ) return This means subsequent changes to hostname would not update previous-hostname :( However, if you use cloud-init config to change the hostname, I think the file will be updated: https://cloudinit.readthedocs.io/en/latest/reference/modules.html#set-hostname Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (Moderate: cloud-init security, bug fix, and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2023:6943 |