summaryrefslogtreecommitdiff
path: root/tests/unittests/config
diff options
context:
space:
mode:
authorBrett Holman <bholman.devel@gmail.com>2022-01-06 15:33:18 -0700
committerGitHub <noreply@github.com>2022-01-06 15:33:18 -0700
commit3e64acda13c826074a502d37b9e11e07d4238bc6 (patch)
tree4ed7cab2d004d2ce4f9426963bd4d52709aaf09f /tests/unittests/config
parentfef532d7d6e8932b1b91eb0fc811335d55a79257 (diff)
downloadvyos-cloud-init-3e64acda13c826074a502d37b9e11e07d4238bc6.tar.gz
vyos-cloud-init-3e64acda13c826074a502d37b9e11e07d4238bc6.zip
Don't throw exceptions for empty cloud config (#1130)
Warn during boot when an empty config is provided. Likewise, `cloud-init devel schema --annotate` should not throw exception, return something meaningful instead.
Diffstat (limited to 'tests/unittests/config')
-rw-r--r--tests/unittests/config/test_schema.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py
index fb5b891d..822efe5a 100644
--- a/tests/unittests/config/test_schema.py
+++ b/tests/unittests/config/test_schema.py
@@ -546,6 +546,31 @@ class AnnotatedCloudconfigFileTest(CiTestCase):
content, annotated_cloudconfig_file({}, content, schema_errors=[])
)
+ def test_annotated_cloudconfig_file_with_non_dict_cloud_config(self):
+ """Error when empty non-dict cloud-config is provided.
+
+ OurJSON validation when user-data is None type generates a bunch
+ schema validation errors of the format:
+ ('', "None is not of type 'object'"). Ignore those symptoms and
+ report the general problem instead.
+ """
+ content = b"\n\n\n"
+ expected = "\n".join(
+ [
+ content.decode(),
+ "# Errors: -------------",
+ "# E1: Cloud-config is not a YAML dict.\n\n",
+ ]
+ )
+ self.assertEqual(
+ expected,
+ annotated_cloudconfig_file(
+ None,
+ content,
+ schema_errors=[("", "None is not of type 'object'")],
+ ),
+ )
+
def test_annotated_cloudconfig_file_schema_annotates_and_adds_footer(self):
"""With schema_errors, error lines are annotated and a footer added."""
content = dedent(
@@ -658,6 +683,19 @@ class TestMain:
_out, err = capsys.readouterr()
assert "Error:\nConfigfile NOT_A_FILE does not exist\n" == err
+ def test_main_invalid_flag_combo(self, capsys):
+ """Main exits non-zero when invalid flag combo used."""
+ myargs = ["mycmd", "--annotate", "--docs", "DOES_NOT_MATTER"]
+ with mock.patch("sys.argv", myargs):
+ with pytest.raises(SystemExit) as context_manager:
+ main()
+ assert 1 == context_manager.value.code
+ _, err = capsys.readouterr()
+ assert (
+ "Error:\nInvalid flag combination. "
+ "Cannot use --annotate with --docs\n" == err
+ )
+
def test_main_prints_docs(self, capsys):
"""When --docs parameter is provided, main generates documentation."""
myargs = ["mycmd", "--docs", "all"]