summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-04-20 20:25:48 -0400
committerScott Moser <smoser@brickies.net>2018-04-20 20:25:48 -0400
commit5037252ca5dc54c6d978b23dba063ac5fabc98fa (patch)
treed39ee7c87b9d471a10a300766570a838c04cbc24 /cloudinit/config
parent4952a8545b61ceb2fe26a933d2f64020d0281703 (diff)
downloadvyos-cloud-init-5037252ca5dc54c6d978b23dba063ac5fabc98fa.tar.gz
vyos-cloud-init-5037252ca5dc54c6d978b23dba063ac5fabc98fa.zip
schema: in validation, raise ImportError if strict but no jsonschema.
validate_cloudconfig_schema with strict=True would not actually validate if there was no jsonschema available. That seems kind of strange. The change here is to make it raise an exception if strict was passed in. And then to fix the one test that needed a skipIfJsonSchema wrapper.
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/tests/test_snap.py41
-rw-r--r--cloudinit/config/tests/test_ubuntu_advantage.py30
2 files changed, 43 insertions, 28 deletions
diff --git a/cloudinit/config/tests/test_snap.py b/cloudinit/config/tests/test_snap.py
index 492d2d46..34c80f1e 100644
--- a/cloudinit/config/tests/test_snap.py
+++ b/cloudinit/config/tests/test_snap.py
@@ -9,7 +9,7 @@ from cloudinit.config.cc_snap import (
from cloudinit.config.schema import validate_cloudconfig_schema
from cloudinit import util
from cloudinit.tests.helpers import (
- CiTestCase, mock, wrap_and_call, skipUnlessJsonSchema)
+ CiTestCase, SchemaTestCaseMixin, mock, wrap_and_call, skipUnlessJsonSchema)
SYSTEM_USER_ASSERTION = """\
@@ -245,9 +245,10 @@ class TestRunCommands(CiTestCase):
@skipUnlessJsonSchema()
-class TestSchema(CiTestCase):
+class TestSchema(CiTestCase, SchemaTestCaseMixin):
with_logs = True
+ schema = schema
def test_schema_warns_on_snap_not_as_dict(self):
"""If the snap configuration is not a dict, emit a warning."""
@@ -342,39 +343,27 @@ class TestSchema(CiTestCase):
def test_duplicates_are_fine_array_array(self):
"""Duplicated commands array/array entries are allowed."""
- byebye = ["echo", "bye"]
- try:
- cfg = {'snap': {'commands': [byebye, byebye]}}
- validate_cloudconfig_schema(cfg, schema, strict=True)
- except schema.SchemaValidationError as e:
- self.fail("command entries can be duplicate.")
+ self.assertSchemaValid(
+ {'commands': [["echo", "bye"], ["echo" "bye"]]},
+ "command entries can be duplicate.")
def test_duplicates_are_fine_array_string(self):
"""Duplicated commands array/string entries are allowed."""
- byebye = "echo bye"
- try:
- cfg = {'snap': {'commands': [byebye, byebye]}}
- validate_cloudconfig_schema(cfg, schema, strict=True)
- except schema.SchemaValidationError as e:
- self.fail("command entries can be duplicate.")
+ self.assertSchemaValid(
+ {'commands': ["echo bye", "echo bye"]},
+ "command entries can be duplicate.")
def test_duplicates_are_fine_dict_array(self):
"""Duplicated commands dict/array entries are allowed."""
- byebye = ["echo", "bye"]
- try:
- cfg = {'snap': {'commands': {'00': byebye, '01': byebye}}}
- validate_cloudconfig_schema(cfg, schema, strict=True)
- except schema.SchemaValidationError as e:
- self.fail("command entries can be duplicate.")
+ self.assertSchemaValid(
+ {'commands': {'00': ["echo", "bye"], '01': ["echo", "bye"]}},
+ "command entries can be duplicate.")
def test_duplicates_are_fine_dict_string(self):
"""Duplicated commands dict/string entries are allowed."""
- byebye = "echo bye"
- try:
- cfg = {'snap': {'commands': {'00': byebye, '01': byebye}}}
- validate_cloudconfig_schema(cfg, schema, strict=True)
- except schema.SchemaValidationError as e:
- self.fail("command entries can be duplicate.")
+ self.assertSchemaValid(
+ {'commands': {'00': "echo bye", '01': "echo bye"}},
+ "command entries can be duplicate.")
class TestHandle(CiTestCase):
diff --git a/cloudinit/config/tests/test_ubuntu_advantage.py b/cloudinit/config/tests/test_ubuntu_advantage.py
index f2a59faf..f1beeff8 100644
--- a/cloudinit/config/tests/test_ubuntu_advantage.py
+++ b/cloudinit/config/tests/test_ubuntu_advantage.py
@@ -7,7 +7,8 @@ from cloudinit.config.cc_ubuntu_advantage import (
handle, maybe_install_ua_tools, run_commands, schema)
from cloudinit.config.schema import validate_cloudconfig_schema
from cloudinit import util
-from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema
+from cloudinit.tests.helpers import (
+ CiTestCase, mock, SchemaTestCaseMixin, skipUnlessJsonSchema)
# Module path used in mocks
@@ -105,9 +106,10 @@ class TestRunCommands(CiTestCase):
@skipUnlessJsonSchema()
-class TestSchema(CiTestCase):
+class TestSchema(CiTestCase, SchemaTestCaseMixin):
with_logs = True
+ schema = schema
def test_schema_warns_on_ubuntu_advantage_not_as_dict(self):
"""If ubuntu-advantage configuration is not a dict, emit a warning."""
@@ -169,6 +171,30 @@ class TestSchema(CiTestCase):
{'ubuntu-advantage': {'commands': {'01': 'also valid'}}}, schema)
self.assertEqual('', self.logs.getvalue())
+ def test_duplicates_are_fine_array_array(self):
+ """Duplicated commands array/array entries are allowed."""
+ self.assertSchemaValid(
+ {'commands': [["echo", "bye"], ["echo" "bye"]]},
+ "command entries can be duplicate.")
+
+ def test_duplicates_are_fine_array_string(self):
+ """Duplicated commands array/string entries are allowed."""
+ self.assertSchemaValid(
+ {'commands': ["echo bye", "echo bye"]},
+ "command entries can be duplicate.")
+
+ def test_duplicates_are_fine_dict_array(self):
+ """Duplicated commands dict/array entries are allowed."""
+ self.assertSchemaValid(
+ {'commands': {'00': ["echo", "bye"], '01': ["echo", "bye"]}},
+ "command entries can be duplicate.")
+
+ def test_duplicates_are_fine_dict_string(self):
+ """Duplicated commands dict/string entries are allowed."""
+ self.assertSchemaValid(
+ {'commands': {'00': "echo bye", '01': "echo bye"}},
+ "command entries can be duplicate.")
+
class TestHandle(CiTestCase):