canonical / cloud-init

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

`failed stage modules-final` when using `package_reboot_if_required: true` in cloud-init.yaml on Ubuntu Noble LXD VMs #5849

Open rajannpatel opened 3 weeks ago

rajannpatel commented 3 weeks ago

Bug report

Using package_upgrade: true in cloud-init.yaml on Ubuntu Noble LXD VMs causes Python errors in cloud-init-output.log.

Steps to reproduce the problem

cloud-init.yaml file:

#cloud-config

# `apt upgrade`
package_upgrade: true

# restart if necessary
package_reboot_if_required: true
lxc launch ubuntu:24.04 test --config=user.user-data="$(cat cloud-init.yaml)" --vm
lxc exec test -- tail -f /var/log/cloud-init-output.log

This issue is specific to --vm, and does not appear when using system containers in LXD.

Environment details

cloud-init logs

cloud-init-output.log:

2024-10-31 11:03:18,695 - cc_package_update_upgrade_install.py[WARNING]: Rebooting after upgrade or install per /var/run/reboot-required
Cloud-init 24.3.1-0ubuntu0~24.04.2 received SIGTERM, exiting...
  Filename: /usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py
  Function: _fire_reboot
  Line number: 55
    Filename: /usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py
    Function: handle
    Line number: 114
      Filename: /usr/lib/python3/dist-packages/cloudinit/helpers.py
      Function: run
      Line number: 156
2024-10-31 11:03:18,822 - util.py[ERROR]: Cloud-init 24.3.1-0ubuntu0~24.04.2 received SIGTERM, exiting...
  Filename: /usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py
  Function: _fire_reboot
  Line number: 55
    Filename: /usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py
    Function: handle
    Line number: 114
      Filename: /usr/lib/python3/dist-packages/cloudinit/helpers.py
      Function: run
      Line number: 156
2024-10-31 11:03:18,824 - main.py[ERROR]: failed stage modules-final
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 831, in status_wrapper
    ret = functor(name, args)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 673, in main_modules
    return run_module_section(mods, name, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 160, in run_module_section
    (which_ran, failures) = mods.run_section(full_section_name)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/config/modules.py", line 367, in run_section
    return self._run_modules(active_mods)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/config/modules.py", line 286, in _run_modules
    ran, _r = cc.run(
              ^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cloud.py", line 71, in run
    return self._runners.run(name, functor, args, freq, clear_on_fail)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/helpers.py", line 156, in run
    results = functor(**args)
              ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py", line 114, in handle
    _fire_reboot()
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py", line 55, in _fire_reboot
    time.sleep(wait_time)
  File "/usr/lib/python3/dist-packages/cloudinit/signal_handler.py", line 48, in _handle_exit
    sys.exit(rc)
SystemExit: 1
failed run of stage modules-final
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 831, in status_wrapper
    ret = functor(name, args)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 673, in main_modules
    return run_module_section(mods, name, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 160, in run_module_section
    (which_ran, failures) = mods.run_section(full_section_name)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/config/modules.py", line 367, in run_section
    return self._run_modules(active_mods)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/config/modules.py", line 286, in _run_modules
    ran, _r = cc.run(
              ^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cloud.py", line 71, in run
    return self._runners.run(name, functor, args, freq, clear_on_fail)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/helpers.py", line 156, in run
    results = functor(**args)
              ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py", line 114, in handle
    _fire_reboot()
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py", line 55, in _fire_reboot
    time.sleep(wait_time)
  File "/usr/lib/python3/dist-packages/cloudinit/signal_handler.py", line 48, in _handle_exit
    sys.exit(rc)
SystemExit: 1
------------------------------------------------------------
TheRealFalcon commented 3 weeks ago

Thanks for the bug report. I can reproduce the behavior. The package_reboot_if_required: true causes cloud-init to issue a reboot which then kills the cloud-init process, leading to cloud-init logging the error.

JamesColeman-LW commented 1 week ago

Hello,

I think the following bug I reported at MaaS is related, sharing in-case it is.

https://bugs.launchpad.net/maas/+bug/2089185