DataSourceUpCloud: recompute network_config when set to UNSET - #7072
Open
sundeep8967 wants to merge 1 commit into
Open
DataSourceUpCloud: recompute network_config when set to UNSET#7072sundeep8967 wants to merge 1 commit into
sundeep8967 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
updates.network.when: [boot]is configured,cloud-initcallsupdate_metadata_if_supported()on boot, which clears cached network configuration by settingself._network_config = UNSET("_unset").In
DataSourceUpCloud.network_config, the check wasif self._network_config:. Because"_unset"is a non-empty string and evaluates toTrue, the method returned the sentinel string directly instead of recomputing network configuration from metadata. This causedapply_network_configto crash with:Solution
DataSourceUpCloud.network_configto verifyif self._network_config and self._network_config != sources.UNSET:, matching the pattern used by other datasources.tests/unittests/sources/test_upcloud.pyverifying that when_network_configis set tosources.UNSET,ds.network_configrecomputes and returns a valid configuration dictionary.Fixes #7067
Testing
pytest tests/unittests/sources/test_upcloud.py