/var/lib/cloud/data/upgraded-network file touched after apt install cloudinit

Bug #2012044 reported by wenao
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Triaged
Low
Unassigned

Bug Description

We have a ubuntu 22.04 instance with cloudinit installed in the source code(python setup.py install), after executing the “apt install cloud-init” command,file /var/lib/cloud/data/upgraded-network has been created, and we create the image with this instance, the new instance with this image will not configure network.

We have conducted a preliminary investigation and found that there is a function(disable_network_config_on_upgrade) in the cloudinit installation script to determine the previous cloudinit version and compare it with the 0.7.7 version. If it is lower than the 0.9 version, this flag file will be created. "I don't know where this variable oldver was passed in, but when this variable is empty, this dpkg --compare-versions judgment will succeed, so we want there have a check for oldver

root@ubuntu22uefi:~# cloud-init --version
/usr/local/bin/cloud-init 19.1.19

after "apt install cloudinit"

root@ubuntu22uefi:~# ls -al /var/lib/cloud/data/upgraded-network
-rw-r--r-- 1 root root 19 Mar 17 16:27 /var/lib/cloud/data/upgraded-network
root@ubuntu22uefi:~# cat /var/lib/cloud/data/upgraded-network
dpkg upgrade from

root@ubuntu22uefi:~# cat cloud-init-22.4.2/debian/cloud-init.postinst
...
disable_network_config_on_upgrade() {
    local oldver="$1" last_without_net="0.7.7~bzr1182-0ubuntu1"
    if [ ! -f /var/lib/cloud/instance/obj.pkl ]; then
        # this is a fresh system not one that has been booted.
        return 0
    fi
    if dpkg --compare-versions "$oldver" le "$last_without_net"; then
        echo "dpkg upgrade from $oldver" > /var/lib/cloud/data/upgraded-network
    fi
}
...

Revision history for this message
James Falcon (falcojr) wrote :

"I don't know where this variable oldver was passed in"
It is the version of the previous package installed. See:
https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html#details-of-configuration

The post-install script can only know about the previous packaged version installed. Since the old version is from a source install, it's seeing the old version as nothing.

This is something that can potentially be modified, but in general I wouldn't recommend going from source install to package install. Is there a reason you can't start with a package install?

As a workaround, you can "rm /var/lib/cloud/data/upgraded-network".

Changed in cloud-init (Ubuntu):
status: New → Triaged
importance: Undecided → Low
Revision history for this message
wenao (wenaojinkang) wrote :

some of the customers we serve use source code to install,
and we now solve this problem by deleting files /var/lib/cloud/data/upgraded-network.
we found that only the ubuntu installation package has this judgment, and Debian Centos and others do not. we expect this installation script to be compatible with this situation(start with source install)

Revision history for this message
Chad Smith (chad.smith) wrote :

Patches welcome on this if we don't get to it soon enough, the upstream code that represents this file is here[1]
The postinstall logic will either need to be a bit smarter in to either early return from disable_network_config_on_upgrade if [ -z ${oldver} ]. Or disable_network_config_on_upgrade should probably only be invoked within a scope of a conditional like `if [ "$1" = "upgrade" ]; then` instead or `if [ "$1" = "configure" ]; then`

We can happily help steer folks to a improve out postinst here if so desired.
Our contributing docs are here[2]

references:
[1] https://github.com/canonical/cloud-init/blob/ubuntu/devel/debian/cloud-init.postinst
[2] https://cloudinit.readthedocs.io/en/latest/development/contributing.html#contributing

Revision history for this message
wenao (wenaojinkang) wrote :

hello, Sorry for replying so late
i have submitted a PR request about fix this, please have a review, thanks.

https://github.com/canonical/cloud-init/pull/4325/files

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.