-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use cc_* module meta defintion over hardcoded vars (SC-888) #1385
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
+456
−428
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5b32940
Type hints to make life easier
TheRealFalcon bd2b4a6
Move module operations into its own file
TheRealFalcon 82e9a58
Update modules.py to validate on a module's meta
TheRealFalcon d087f2e
tests
TheRealFalcon e7f1eb1
Remove line that has been commented for years
TheRealFalcon 95fea7d
forgot to finish an f-string
TheRealFalcon 3fbe5e0
add test and fix module based on new test
TheRealFalcon efae7fe
addressing comments
TheRealFalcon 7a6727b
mypy fix
blackboxsw 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
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 |
|---|---|---|
| @@ -1,47 +0,0 @@ | ||
| # Copyright (C) 2008-2010 Canonical Ltd. | ||
| # Copyright (C) 2012 Hewlett-Packard Development Company, L.P. | ||
| # | ||
| # Author: Chuck Short <chuck.short@canonical.com> | ||
| # Author: Juerg Haefliger <juerg.haefliger@hp.com> | ||
| # | ||
| # This file is part of cloud-init. See LICENSE file for license information. | ||
|
|
||
| from cloudinit import log as logging | ||
| from cloudinit.settings import FREQUENCIES, PER_INSTANCE | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
| # This prefix is used to make it less | ||
| # of a chance that when importing | ||
| # we will not find something else with the same | ||
| # name in the lookup path... | ||
| MOD_PREFIX = "cc_" | ||
|
|
||
|
|
||
| def form_module_name(name): | ||
| canon_name = name.replace("-", "_") | ||
| if canon_name.lower().endswith(".py"): | ||
| canon_name = canon_name[0 : (len(canon_name) - 3)] | ||
| canon_name = canon_name.strip() | ||
| if not canon_name: | ||
| return None | ||
| if not canon_name.startswith(MOD_PREFIX): | ||
| canon_name = "%s%s" % (MOD_PREFIX, canon_name) | ||
| return canon_name | ||
|
|
||
|
|
||
| def fixup_module(mod, def_freq=PER_INSTANCE): | ||
| if not hasattr(mod, "frequency"): | ||
| setattr(mod, "frequency", def_freq) | ||
| else: | ||
| freq = mod.frequency | ||
| if freq and freq not in FREQUENCIES: | ||
| LOG.warning("Module %s has an unknown frequency %s", mod, freq) | ||
| if not hasattr(mod, "distros"): | ||
| setattr(mod, "distros", []) | ||
| if not hasattr(mod, "osfamilies"): | ||
| setattr(mod, "osfamilies", []) | ||
| return mod | ||
|
|
||
|
|
||
| # vi: ts=4 expandtab | ||
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
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 |
|---|---|---|
|
|
@@ -2,31 +2,35 @@ | |
| # | ||
| # This file is part of cloud-init. See LICENSE file for license information. | ||
|
|
||
| """Defer writing certain files""" | ||
| """Write Files Deferred: Defer writing certain files""" | ||
|
|
||
| from cloudinit import util | ||
| from cloudinit.config.cc_write_files import DEFAULT_DEFER, write_files | ||
|
|
||
| # meta is not used in this module, but it remains as code documentation | ||
| # | ||
| # id: cc_write_files_deferred' | ||
| # name: 'Write Deferred Files | ||
| # distros: ['all'], | ||
| # frequency: PER_INSTANCE, | ||
| # title: | ||
| # write certain files, whose creation as been deferred, during | ||
| # final stage | ||
| # description: | ||
| # This module is based on `'Write Files' <write-files>`__, and | ||
| # will handle all files from the write_files list, that have been | ||
| # marked as deferred and thus are not being processed by the | ||
| # write-files module. | ||
| # | ||
| # *Please note that his module is not exposed to the user through | ||
| # its own dedicated top-level directive.* | ||
|
|
||
| # Not exposed, because related modules should document this behaviour | ||
| __doc__ = None | ||
| from cloudinit.config.schema import MetaSchema | ||
| from cloudinit.distros import ALL_DISTROS | ||
| from cloudinit.settings import PER_INSTANCE | ||
|
|
||
| MODULE_DESCRIPTION = """\ | ||
| This module is based on `'Write Files' <write-files>`__, and | ||
| will handle all files from the write_files list, that have been | ||
| marked as deferred and thus are not being processed by the | ||
| write-files module. | ||
|
|
||
| *Please note that his module is not exposed to the user through | ||
| its own dedicated top-level directive.* | ||
| """ | ||
| meta: MetaSchema = { | ||
| "id": "cc_write_files_deferred", | ||
| "name": "Write Files Deferred", | ||
| "title": "Defer writing certain files", | ||
| "description": __doc__, | ||
| "distros": [ALL_DISTROS], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you feel excited about cleaning out cruft, we could also drop any |
||
| "frequency": PER_INSTANCE, | ||
| "examples": [], | ||
| } | ||
|
|
||
| # This module is undocumented in our schema docs | ||
| __doc__ = "" | ||
|
|
||
|
|
||
| def handle(name, cfg, _cloud, log, _args): | ||
|
|
@@ -44,6 +48,3 @@ def handle(name, cfg, _cloud, log, _args): | |
| ) | ||
| return | ||
| write_files(name, filtered_files) | ||
|
|
||
|
|
||
| # vi: ts=4 expandtab | ||
|
blackboxsw marked this conversation as resolved.
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to still have the local 'frequency' variable in case someone changes that value and doesn't notice this one in the future.