Skip to content

upcloud, digitalocean: recompute network_config when set to UNSET - #7072

Open
sundeep8967 wants to merge 2 commits into
canonical:mainfrom
sundeep8967:fix/upcloud-recompute-unset-network-config
Open

sundeep8967 wants to merge 2 commits into
canonical:mainfrom
sundeep8967:fix/upcloud-recompute-unset-network-config

Conversation

@sundeep8967

@sundeep8967 sundeep8967 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Problem

When updates.network.when: [boot] is configured, cloud-init calls update_metadata_if_supported() on boot, which clears cached network configuration by setting self._network_config = UNSET ("_unset").

In DataSourceUpCloud.network_config and DataSourceDigitalOcean.network_config, the check was a bare truthiness check (if self._network_config:). Because "_unset" is a non-empty string and evaluates to True, the methods returned the sentinel string directly instead of recomputing network configuration from metadata. On subsequent boots, this caused apply_network_config to crash with:

AttributeError: 'str' object has no attribute 'get'

Solution

  • Update DataSourceUpCloud.network_config to verify if self._network_config and self._network_config != sources.UNSET:, matching the pattern used in DataSourceHetzner.
  • Update DataSourceDigitalOcean.network_config to check self._network_config != sources.UNSET before returning cached network configuration.
  • Separate the regression test in tests/unittests/sources/test_upcloud.py into its own dedicated test method (test_network_config_unset_recomputes).
  • Add a dedicated unit test in tests/unittests/sources/test_digitalocean.py (test_network_config_unset_recomputes) verifying that network_config recomputes when _network_config is sources.UNSET.

Fixes #7067

Testing

  • Executed unit tests: pytest tests/unittests/sources/test_upcloud.py tests/unittests/sources/test_digitalocean.py
  • All 22 tests passed cleanly.
  • Full upstream CI matrix (18/18 checks) passed cleanly.

Comment thread tests/unittests/sources/test_upcloud.py Outdated
UC_METADATA.get("network").get("dns")[1] == dns.get("address")[1]
)

# GH-7067: Verify recomputation when _network_config is UNSET

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want a distinct unittest for this. It's not as discoverable when added to the middle of an existing test.

@blackboxsw blackboxsw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the unittest for this in test_upcloud.py.

As mentioned on #7067 it may be worth inclusion of the same sort of fix in DataSourceDigitalOcean.py, and explicit unittest for the same such condition.

@sundeep8967
sundeep8967 force-pushed the fix/upcloud-recompute-unset-network-config branch 3 times, most recently from 7fd32ef to d9392de Compare September 10, 2026 03:58
@sundeep8967 sundeep8967 changed the title DataSourceUpCloud: recompute network_config when set to UNSET upcloud, digitalocean: recompute network_config when set to UNSET Sep 10, 2026
@sundeep8967

sundeep8967 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @blackboxsw! Updated the implementation per your feedback:

  • Applied the sources.UNSET sentinel check to DataSourceDigitalOcean.network_config.
  • Separated the regression test in tests/unittests/sources/test_upcloud.py into a dedicated test method (test_network_config_unset_recomputes).
  • Added a dedicated unit test in tests/unittests/sources/test_digitalocean.py (test_network_config_unset_recomputes) verifying recomputation when _network_config is sources.UNSET.

@blackboxsw blackboxsw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good changeset and thank you for the unittest coverage @sundeep8967.
One minor nit on the import and we can land this.


from cloudinit import settings
from cloudinit import settings, sources
from cloudinit.sources import DataSourceDigitalOcean

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already importing DataSourceDigitalOcean from sources, lets just direct import UNSET here instead of the separate imprt line

@sundeep8967 sundeep8967 Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks

@blackboxsw blackboxsw self-assigned this Sep 17, 2026
@sundeep8967
sundeep8967 force-pushed the fix/upcloud-recompute-unset-network-config branch from d9392de to c03cce2 Compare September 17, 2026 18:38
When update_metadata_if_supported() is invoked on boot, it clears cached
network configuration by setting _network_config to UNSET ("_unset").
Because DataSourceUpCloud.network_config checked truthiness directly,
it returned the UNSET string sentinel instead of recomputing from
metadata, causing an AttributeError in apply_network_config.

Fixes canonicalGH-7067

Signed-off-by: sundeep8967 <sundeep8967@gmail.com>
The network_config property in DataSourceUpCloud and DataSourceDigitalOcean
used a bare truthiness check on _network_config. When
update_metadata_if_supported() sets _network_config = UNSET (the truthy
string "_unset"), the sentinel is returned directly instead of recomputing
network configuration, causing AttributeError: 'str' object has no attribute
'get' in apply_network_config on subsequent boots.

Fix DataSourceDigitalOcean.network_config to mirror the existing pattern in
DataSourceUpCloud by adding an explicit sources.UNSET sentinel check. Separate
the regression test for UpCloud into its own dedicated test method
(test_network_config_unset_recomputes) and add an equivalent test for
DataSourceDigitalOcean.

Fixes canonicalGH-7067

Signed-off-by: sundeep8967 <sundeep8967@gmail.com>
@sundeep8967
sundeep8967 force-pushed the fix/upcloud-recompute-unset-network-config branch from c03cce2 to 14ee8e1 Compare September 17, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataSourceUpCloud.network_config returns stale UNSET sentinel string instead of recomputing, crashing apply_network_config

2 participants