canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
3.01k stars 887 forks source link

fix: do not log ppid when ppid is undefined #5781

Closed hcartiaux closed 1 month ago

hcartiaux commented 1 month ago

This fixes a bug introduced in the function log_ppid by the commit 75add5c72aa575d373825deddcb685f725e290d8 which renders cloud-init unusable on all non-linux systems.

With this commit, cloud-init tried to log the ppid even if it was undefined, because ppid is only collected on linux distros. Here is the output of cloud-init 24.3 on OpenBSD:

Cloud-init v. 24.3 running 'init-local' at Thu, 03 Oct 2024 20:24:37 +0000. Up 39.569653034210205 seconds.
2024-10-03 20:24:38,050 - main.py[ERROR]: failed stage init-local
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/cloud_init-24.3-py3.10.egg/cloudinit/cmd/main.py", line 831, in status_wrapper
    ret = functor(name, args)
  File "/usr/local/lib/python3.10/site-packages/cloud_init-24.3-py3.10.egg/cloudinit/cmd/main.py", line 395, in main_init
    log_ppid(init.distro, bootstage_name)
  File "/usr/local/lib/python3.10/site-packages/cloud_init-24.3-py3.10.egg/cloudinit/cmd/main.py", line 112, in log_ppid
    LOG.info("PID [%s] started cloud-init '%s'.", ppid, bootstage_name)
UnboundLocalError: local variable 'ppid' referenced before assignment
failed run of stage init-local

This PR is an attempt to fix this issue by restoring the previous behavior of log_ppid from the commits dc7c48b9b3fbeb8548d796ae8f0e2b15246eb903 and 4abdd5a7066c322163579d8d91a44426ac705172

Proposed Commit Message

fix: do not log ppid when ppid is undefined

This fixes a bug introduced in 75add5c72aa575d373825deddcb685f725e290d8
which renders cloud-init unusable on all non-linux systems.

Merge type

hcartiaux commented 1 month ago

Note: this PR may be obsoleted by #5770

blackboxsw commented 1 month ago

@hcartiaux thank you much for your contribution to cloud-init here. I was surprised to discover this same bug while I was improving unittest coverage in my initial pass at limiting deprecated logs inside the log_ppid function. Given that the log_ppid function is removed per #5770. This is no longer an issue. Again, thank you for noticing and proposing a fix.