-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Include fails silently and new feature flag functionality #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
OddBloke
merged 1 commit into
canonical:master
from
TheRealFalcon:include-fails-silently
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # This file is part of cloud-init. See LICENSE file for license information. | ||
| """ | ||
| Feature flags are used as a way to easily toggle configuration | ||
| **at build time**. They are provided to accommodate feature deprecation and | ||
| downstream configuration changes. | ||
|
|
||
| Currently used upstream values for feature flags are set in | ||
| ``cloudinit/features.py``. Overrides to these values (typically via quilt | ||
| patch) can be placed | ||
| in a file called ``feature_overrides.py`` in the same directory. Any value | ||
| set in ``feature_overrides.py`` will override the original value set | ||
| in ``features.py``. | ||
|
|
||
| Each flag should include a short comment regarding the reason for | ||
| the flag and intended lifetime. | ||
|
|
||
| Tests are required for new feature flags, and tests must verify | ||
| all valid states of a flag, not just the default state. | ||
| """ | ||
|
|
||
| ERROR_ON_USER_DATA_FAILURE = True | ||
| """ | ||
| If there is a failure in obtaining user data (i.e., #include or | ||
| decompress fails), old behavior is to log a warning and proceed. | ||
| After the 20.2 release, we instead raise an exception. | ||
| This flag can be removed after Focal is no longer supported | ||
| """ | ||
|
|
||
| try: | ||
| # pylint: disable=wildcard-import | ||
| from cloudinit.feature_overrides import * # noqa | ||
| except ImportError: | ||
| pass | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # This file is part of cloud-init. See LICENSE file for license information. | ||
| # pylint: disable=no-member,no-name-in-module | ||
| """ | ||
| This file is for testing the feature flag functionality itself, | ||
| NOT for testing any individual feature flag | ||
| """ | ||
| import pytest | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import cloudinit | ||
|
|
||
|
|
||
| @pytest.yield_fixture() | ||
| def create_override(request): | ||
|
OddBloke marked this conversation as resolved.
|
||
| """ | ||
| Create a feature overrides file and do some module wizardry to make | ||
| it seem like we're importing the features file for the first time. | ||
|
|
||
| After creating the override file with the values passed by the test, | ||
| we need to reload cloudinit.features | ||
| to get all of the current features (including the overridden ones). | ||
| Once the test is complete, we remove the file we created and set | ||
| features and feature_overrides modules to how they were before | ||
| the test started | ||
| """ | ||
| override_path = Path(cloudinit.__file__).parent / 'feature_overrides.py' | ||
| if override_path.exists(): | ||
| raise Exception("feature_overrides.py unexpectedly exists! " | ||
| "Remove it to run this test.") | ||
| with override_path.open('w') as f: | ||
| for key, value in request.param.items(): | ||
| f.write('{} = {}\n'.format(key, value)) | ||
|
|
||
| sys.modules.pop('cloudinit.features', None) | ||
|
|
||
| yield | ||
|
|
||
| override_path.unlink() | ||
|
OddBloke marked this conversation as resolved.
|
||
| sys.modules.pop('cloudinit.feature_overrides', None) | ||
|
|
||
|
|
||
| class TestFeatures: | ||
|
OddBloke marked this conversation as resolved.
|
||
| def test_feature_without_override(self): | ||
| from cloudinit.features import ERROR_ON_USER_DATA_FAILURE | ||
| assert ERROR_ON_USER_DATA_FAILURE is True | ||
|
|
||
| @pytest.mark.parametrize('create_override', | ||
| [{'ERROR_ON_USER_DATA_FAILURE': False}], | ||
| indirect=True) | ||
| def test_feature_with_override(self, create_override): | ||
| from cloudinit.features import ERROR_ON_USER_DATA_FAILURE | ||
| assert ERROR_ON_USER_DATA_FAILURE is False | ||
|
|
||
| @pytest.mark.parametrize('create_override', | ||
| [{'SPAM': True}], | ||
| indirect=True) | ||
| def test_feature_only_in_override(self, create_override): | ||
| from cloudinit.features import SPAM | ||
| assert SPAM is True | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.