canonical / canonical/cloud-init
DataSourceUpCloud.network_config returns stale UNSET sentinel string instead of recomputing, crashing apply_network_config
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 1.1k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
# Bug report
When `updates.network.when: [boot]` is configured, `cloud-init` calls `update_metadata_if_supported()` on every boot, which sets `self._network_config = UNSET ("_unset")` to force recomputation. `DataSourceUpCloud.network_config` only checks `if self._network_config:` — since `"_unset"` is truthy, it returns the sentinel string directly instead of recomputing from metadata.
## Steps to reproduce the problem
1. Configure `updates: {network: {when: [boot]}}` in host that uses UpCloud datasource
2. Reboot
3. Review `cloud-init.service` logs, it shows following Python error (see cloud-init logs later on)
## Environment details
- Cloud-init version: 22.4.2 (reviewed v26.2 and found the same faulty code logic there too)
- Operating System Distribution: Debian
- Cloud provider, platform or installer type: UpCloud
## cloud-init logs
```
2026-09-02 08:53:49,826 - util.py[DEBUG]: failed stage init
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 767, in status_wrapper
ret = functor(name, args)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 433, in main_init
init.apply_network_config(bring_up=bring_up_interfaces)
File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 924, in apply_network_config
self.distro.networking.wait_for_physdevs(netcfg)
File "/usr/lib/python3/dist-packages/cloudinit/distros/networking.py", line 142, in wait_for_physdevs
physdevs = self.extract_physdevs(netcfg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/distros/networking.py", line 46, in extract_physdevs
return net.extract_physdevs(netcfg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tuomas.kukkamaa/debug_netcfg.py", line 25, in _patched_extract_physdevs
return _orig_extract_physdevs(netcfg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/net/__init__.py", line 654, in extract_physdevs
version = netcfg.get("version")
^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'
```
Contributor guide
Research direction
Start at DataSourceUpCloud.network_config and trace the update_metadata_if_supported() path that is followed before apply_network_config. Reproduce the boot update scenario, then add regression coverage showing that network_config returns recomputed metadata rather than the UNSET string and that apply_network_config no longer receives a string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100