Skip to content

Commit

Permalink
fix: Don't break modules that use get_meta_doc() (#5953)
Browse files Browse the repository at this point in the history
get_meta_doc() is no longer used, but there may be custom modules that
still try to reference it. Don't break them.
  • Loading branch information
TheRealFalcon committed Jan 8, 2025
1 parent 168f821 commit f97e5fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cloudinit/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,26 @@ def handle_schema_args(name, args):
)


def get_meta_doc(*_args, **_kwargs) -> str:
"""Provide a stub for backwards compatibility.
This function is no longer used, but earlier versions of modules
required this function for documentation purposes. This is a stub so
that custom modules do not break on upgrade.
"""
lifecycle.log_with_downgradable_level(
logger=LOG,
version="24.4",
requested_level=logging.WARNING,
msg=(
"The 'get_meta_doc()' function is deprecated and will be removed "
"in a future version of cloud-init."
),
args=(),
)
return ""


def main():
"""Tool to validate schema of a cloud-config file or print schema docs."""
parser = get_parser()
Expand Down
12 changes: 12 additions & 0 deletions tests/unittests/config/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
SchemaValidationError,
annotated_cloudconfig_file,
get_jsonschema_validator,
get_meta_doc,
get_schema,
get_schema_dir,
handle_schema_args,
Expand Down Expand Up @@ -2278,3 +2279,14 @@ def test_handle_schema_args_unknown_header(
assert read_cfg_paths.call_args_list == [
mock.call(fetch_existing_datasource="trust")
]


class TestDeprecation:
def test_get_meta_doc_deprecation(self, caplog):
"""Test that calling get_meta_doc() emits deprecation.
Ensures that custom modules calling `get_meta_doc()` can still
function but receive deprecation warning.
"""
get_meta_doc("some", "random", "arguments", plus="kwargs")
assert "The 'get_meta_doc()' function is deprecated" in caplog.text

0 comments on commit f97e5fb

Please sign in to comment.