summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorlucasmoura <lucas.moura@canonical.com>2020-05-13 17:45:01 -0300
committerGitHub <noreply@github.com>2020-05-13 14:45:01 -0600
commit2e32c40a607250bc9e713c0daf360dc6617f4420 (patch)
treed1109d88a2fd02a1fbdfe01ed19448539444ddb7 /tests/unittests
parentc8f20b31cd57443b1bef17579dfceca432420c94 (diff)
downloadvyos-cloud-init-2e32c40a607250bc9e713c0daf360dc6617f4420.tar.gz
vyos-cloud-init-2e32c40a607250bc9e713c0daf360dc6617f4420.zip
Add schema to apt configure config (#357)
Create a schema object for the `apt_configure` module and validate this schema in the `handle` function of the module. There are some considerations regarding this PR: * The `primary` and `security` keys have the exact same properties. I tried to eliminate this redundancy by moving their properties to a common place and then just referencing it for both security and primary. Similar to what is documented here: https://json-schema.org/understanding-json-schema/structuring.html under the `Reuse` paragraph. However, this approach does not work, because the `#` pointer goes to the beginning of the file, which is a python module instead of a json file, not allowing the pointer to find the correct definition. What I did was to create a separate dict for the mirror config and reuse it for primary and security, but maybe there are better approaches to do that. * There was no documentation for the config `debconf_selections`. I tried to infer what it supposed to do by looking at the code and the `debconf-set-selections` manpage, but my description may not be accurate or complete. * Add a _parse_description function to schema.py to render multi-line preformatted content instead of squashing all whitespace LP: #1858884
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_handler/test_schema.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py
index 071b98bc..e19d13b8 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -24,6 +24,7 @@ class GetSchemaTest(CiTestCase):
schema = get_schema()
self.assertCountEqual(
[
+ 'cc_apt_configure',
'cc_bootcmd',
'cc_locale',
'cc_ntp',
@@ -289,6 +290,41 @@ class GetSchemaDocTest(CiTestCase):
"""),
get_schema_doc(full_schema))
+ def test_get_schema_doc_properly_parse_description(self):
+ """get_schema_doc description properly formatted"""
+ full_schema = copy(self.required_schema)
+ full_schema.update(
+ {'properties': {
+ 'p1': {
+ 'type': 'string',
+ 'description': dedent("""\
+ This item
+ has the
+ following options:
+
+ - option1
+ - option2
+ - option3
+
+ The default value is
+ option1""")
+ }
+ }}
+ )
+
+ self.assertIn(
+ dedent("""
+ **Config schema**:
+ **p1:** (string) This item has the following options:
+
+ - option1
+ - option2
+ - option3
+
+ The default value is option1
+ """),
+ get_schema_doc(full_schema))
+
def test_get_schema_doc_raises_key_errors(self):
"""get_schema_doc raises KeyErrors on missing keys."""
for key in self.required_schema: