Comment 4 for bug 1424710

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

There is actually a bigger problem here.

The update_hostname method gets the previous hostname (prev_hostname) by reading a value of prev_hostname_fn...or so you might think. But in fact, because of the way _read_hostname is implemented, this actual returns the *current* hostname on systemd based systems. This means that even if we patch _write_hostname to correctly write /var/lib/cloud/data/previous-hostname, that value will be ignored and cloud-init will *continue* to always update the hostname.

A fundamental problem with the code -- at least in 0.7.6 -- is that the base distros.Distro class doesn't provide a high enough level of abstraction. It assumes a file-based configuration for managing hostnames, and overloads functions like _read_hostname to perform multiple functions in ways that are pretty much guaranteed to fail.

I'm working on a band-aid that will resolve this problem, but the Distro class really needs to provide a high-level API that is well separated from the individual distribution drivers. In particular, the base class should probably *never* be reading or writing files outside of /var/lib/cloud.