Merge ~powersj/cloud-init:fix-arch-hostname into cloud-init:master

Proposed by Joshua Powers
Status: Merged
Merged at revision: 85c984c3c74b0a8751698e20915b89756580b09f
Proposed branch: ~powersj/cloud-init:fix-arch-hostname
Merge into: cloud-init:master
Diff against target: 13 lines (+1/-1)
1 file modified
cloudinit/distros/arch.py (+1/-1)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+327913@code.launchpad.net

Commit message

archlinux: fix set hostname

cloud-init fails to set the hostname on Arch Linux becuase that
_write_hostname passes conf instead of str(conf) to util.write_file.

LP: #1705306

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:7cb9df67d9820fa7e885e82dfbe0d5ba62bd58da
https://jenkins.ubuntu.com/server/job/cloud-init-ci/79/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: CentOS 6 & 7: Build & Test
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/79/rebuild

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

summary: add 'omode' to the write_file call
  util.write_file(out_fn, str(conf), mode=0o644, omode="w")

Reasoning:
write_file does an 'open' by default with 'wb' (binary mode).
The, if the mode is binary, it will try to encode the contents which is why
we see the failure.

Your change works because you're passing a string now, which *does* have
.encode(), but it'd be better to avoid write_file's magic and pass a
string as well as open in string mode so no .encode() or .decode() had
to happen.

in its calls to 'encode_text' or 'decode_text', write_file is doing more magic
then it should. Ultimately it'd be better if the caller provided correct
modes and data, which is what we're doing here.

review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

I'm just going to make that under your name, and pull it..

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/distros/arch.py b/cloudinit/distros/arch.py
2index 75d4620..8a9c359 100644
3--- a/cloudinit/distros/arch.py
4+++ b/cloudinit/distros/arch.py
5@@ -119,7 +119,7 @@ class Distro(distros.Distro):
6 if not conf:
7 conf = HostnameConf('')
8 conf.set_hostname(your_hostname)
9- util.write_file(out_fn, conf, 0o644)
10+ util.write_file(out_fn, str(conf), 0o644)
11
12 def _read_system_hostname(self):
13 sys_hostname = self._read_hostname(self.hostname_conf_fn)

Subscribers

People subscribed via source and target branches