Skip to content

DataSourceUpCloud: recompute network_config when set to UNSET - #7072

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

DataSourceUpCloud: recompute network_config when set to UNSET#7072
sundeep8967 wants to merge 1 commit into
canonical:mainfrom
sundeep8967:fix/upcloud-recompute-unset-network-config

Conversation

@sundeep8967

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, the check was if self._network_config:. Because "_unset" is a non-empty string and evaluates to True, the method returned the sentinel string directly instead of recomputing network configuration from metadata. 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 by other datasources.
  • Add unit test in tests/unittests/sources/test_upcloud.py verifying that when _network_config is set to sources.UNSET, ds.network_config recomputes and returns a valid configuration dictionary.

Fixes #7067

Testing

  • Executed unit tests with pytest tests/unittests/sources/test_upcloud.py
  • All 7 tests passed cleanly.

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>
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

1 participant