canonical / canonical/cloud-init

update_hostname module fails on CentOS/RHEL with systemd

Open
#3,076 6 comments 0 reactions 0 assignees View on GitHub
incomplete launchpad
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

This bug was originally filed in Launchpad as [LP: #1736174](https://bugs.launchpad.net/cloud-init/+bug/1736174)

Launchpad details

affected_projects = []

assignee = None
assignee_name = None
date_closed = None
date_created = 2017-12-04T15:23:50.481473+00:00
date_fix_committed = 2019-07-19T21:02:04.300315+00:00
date_fix_released = 2019-07-19T21:02:04.300315+00:00
id = 1736174
importance = medium
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1736174
milestone = None
owner = albeauregard
owner_name = Albert Beauregard
private = False
status = incomplete
submitter = albeauregard
submitter_name = Albert Beauregard
tags = ['centos', 'rhel']
duplicates = []

_Launchpad user **Albert Beauregard(albeauregard)** wrote on 2017-12-04T15:23:50.481473+00:00_

Cloud provider: OpenStack

#cloud-config
hostname: somehostname.somedomain
fqdn: somehostname.somedomain

__init__.py[INFO]: /var/lib/cloud/data/previous-hostname differs from /etc/hostname, assuming user maintained hostname.

Error message is a little bit misleading, since when uses_systemd(), /etc/hostname isn't actually read, instead, the result of util.subp(['hostname']) is used.

Also, this comparison/test will never succeed, because when uses_systemd() and filename.endswitch('/previous-hostname'), the return is stripped of cr/lf, however, the result of util.subp(['hostname']) will contain a lf, and it is not being stripped:

(from rhel.py)
if self.uses_systemd() and filename.endswith('/previous-hostname'):
return util.load_file(filename).strip()
elif self.uses_systemd():
(out, _err) = util.subp(['hostname'])
if len(out):
return out
else:
return default

The simplest solution appears to be to add .strip() to return out; but this fix may have other implications.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.