diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py index ecdb6d7a1c1..ba06380048e 100644 --- a/cloudinit/config/schema.py +++ b/cloudinit/config/schema.py @@ -1461,6 +1461,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() diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py index 428a2f86a32..f5a69a44d14 100644 --- a/tests/unittests/config/test_schema.py +++ b/tests/unittests/config/test_schema.py @@ -27,6 +27,7 @@ SchemaValidationError, annotated_cloudconfig_file, get_jsonschema_validator, + get_meta_doc, get_schema, get_schema_dir, handle_schema_args, @@ -2212,3 +2213,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