summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorBrett Holman <bholman.devel@gmail.com>2021-12-06 15:27:12 -0700
committerGitHub <noreply@github.com>2021-12-06 15:27:12 -0700
commitbedac77e9348e7a54c0ec364fb61df90cd893972 (patch)
tree73a0ddaada5ceb256e22c053fec50db82671d14c /cloudinit/util.py
parentf428ed1611bdb685598832dd42495f0bcda40ec4 (diff)
downloadvyos-cloud-init-bedac77e9348e7a54c0ec364fb61df90cd893972.tar.gz
vyos-cloud-init-bedac77e9348e7a54c0ec364fb61df90cd893972.zip
Add Strict Metaschema Validation (#1101)
Improve schema validation. This adds strict validation of config module definitions at testing time, with plumbing included for future runtime validation. This eliminates a class of bugs resulting from schemas that have definitions that are incorrect, but get interpreted by jsonschema as "additionalProperties" that are therefore ignored. - Add strict meta-schema for jsonschema unit test validation - Separate schema from module metadata structure - Improve type annotations for various functions and data types Cleanup: - Remove unused jsonschema "required" elements - Eliminate manual memoization in schema.py:get_schema(), reference module.__doc__ directly
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 2045a6ab..1b462a38 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -347,7 +347,7 @@ def extract_usergroup(ug_pair):
return (u, g)
-def find_modules(root_dir):
+def find_modules(root_dir) -> dict:
entries = dict()
for fname in glob.glob(os.path.join(root_dir, "*.py")):
if not os.path.isfile(fname):
@@ -2751,4 +2751,19 @@ def get_proc_ppid(pid):
ppid = int(parts[3])
return ppid
+
+def error(msg, rc=1, fmt='Error:\n{}', sys_exit=False):
+ """
+ Print error to stderr and return or exit
+
+ @param msg: message to print
+ @param rc: return code (default: 1)
+ @param fmt: format string for putting message in (default: 'Error:\n {}')
+ @param sys_exit: exit when called (default: false)
+ """
+ print(fmt.format(msg), file=sys.stderr)
+ if sys_exit:
+ sys.exit(rc)
+ return rc
+
# vi: ts=4 expandtab