summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-03-14 10:41:46 -0600
committerChad Smith <chad.smith@canonical.com>2018-03-14 10:41:46 -0600
commit76460b63f9c310c7de4e5f0c11d1525bedd277e1 (patch)
treeed5ec6c4a5500e1800e093f8c66029b489e76908 /tests
parentf891df345afa57c0c7734e8f04cca9a3d5881778 (diff)
downloadvyos-cloud-init-76460b63f9c310c7de4e5f0c11d1525bedd277e1.tar.gz
vyos-cloud-init-76460b63f9c310c7de4e5f0c11d1525bedd277e1.zip
tests: Centralize and re-use skipTest based on json schema presense.
This just centralizes a hunk of duplicated code and uses it from the new location.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler/test_handler_bootcmd.py12
-rw-r--r--tests/unittests/test_handler/test_handler_ntp.py18
-rw-r--r--tests/unittests/test_handler/test_handler_resizefs.py14
-rw-r--r--tests/unittests/test_handler/test_handler_runcmd.py14
-rw-r--r--tests/unittests/test_handler/test_schema.py21
5 files changed, 23 insertions, 56 deletions
diff --git a/tests/unittests/test_handler/test_handler_bootcmd.py b/tests/unittests/test_handler/test_handler_bootcmd.py
index 09d4c681..29fc25e4 100644
--- a/tests/unittests/test_handler/test_handler_bootcmd.py
+++ b/tests/unittests/test_handler/test_handler_bootcmd.py
@@ -3,17 +3,11 @@
from cloudinit.config import cc_bootcmd
from cloudinit.sources import DataSourceNone
from cloudinit import (distros, helpers, cloud, util)
-from cloudinit.tests.helpers import CiTestCase, mock, skipIf
+from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema
import logging
import tempfile
-try:
- import jsonschema
- assert jsonschema # avoid pyflakes error F401: import unused
- _missing_jsonschema_dep = False
-except ImportError:
- _missing_jsonschema_dep = True
LOG = logging.getLogger(__name__)
@@ -72,7 +66,7 @@ class TestBootcmd(CiTestCase):
"Input to shellify was type 'int'. Expected list or tuple.",
str(context_manager.exception))
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_handler_schema_validation_warns_non_array_type(self):
"""Schema validation warns of non-array type for bootcmd key.
@@ -88,7 +82,7 @@ class TestBootcmd(CiTestCase):
self.logs.getvalue())
self.assertIn('Failed to shellify', self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, 'No python-jsonschema dependency')
+ @skipUnlessJsonSchema()
def test_handler_schema_validation_warns_non_array_item_type(self):
"""Schema validation warns of non-array or string bootcmd items.
diff --git a/tests/unittests/test_handler/test_handler_ntp.py b/tests/unittests/test_handler/test_handler_ntp.py
index 28a8455d..695897c0 100644
--- a/tests/unittests/test_handler/test_handler_ntp.py
+++ b/tests/unittests/test_handler/test_handler_ntp.py
@@ -3,7 +3,8 @@
from cloudinit.config import cc_ntp
from cloudinit.sources import DataSourceNone
from cloudinit import (distros, helpers, cloud, util)
-from cloudinit.tests.helpers import FilesystemMockingTestCase, mock, skipIf
+from cloudinit.tests.helpers import (
+ FilesystemMockingTestCase, mock, skipUnlessJsonSchema)
import os
@@ -24,13 +25,6 @@ NTP={% for host in servers|list + pools|list %}{{ host }} {% endfor -%}
{% endif -%}
"""
-try:
- import jsonschema
- assert jsonschema # avoid pyflakes error F401: import unused
- _missing_jsonschema_dep = False
-except ImportError:
- _missing_jsonschema_dep = True
-
class TestNtp(FilesystemMockingTestCase):
@@ -312,7 +306,7 @@ class TestNtp(FilesystemMockingTestCase):
content)
self.assertNotIn('Invalid config:', self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_ntp_handler_schema_validation_warns_non_string_item_type(self):
"""Ntp schema validation warns of non-strings in pools or servers.
@@ -333,7 +327,7 @@ class TestNtp(FilesystemMockingTestCase):
content = stream.read()
self.assertEqual("servers ['valid', None]\npools [123]\n", content)
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_ntp_handler_schema_validation_warns_of_non_array_type(self):
"""Ntp schema validation warns of non-array pools or servers types.
@@ -354,7 +348,7 @@ class TestNtp(FilesystemMockingTestCase):
content = stream.read()
self.assertEqual("servers non-array\npools 123\n", content)
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_ntp_handler_schema_validation_warns_invalid_key_present(self):
"""Ntp schema validation warns of invalid keys present in ntp config.
@@ -378,7 +372,7 @@ class TestNtp(FilesystemMockingTestCase):
"servers []\npools ['0.mycompany.pool.ntp.org']\n",
content)
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_ntp_handler_schema_validation_warns_of_duplicates(self):
"""Ntp schema validation warns of duplicates in servers or pools.
diff --git a/tests/unittests/test_handler/test_handler_resizefs.py b/tests/unittests/test_handler/test_handler_resizefs.py
index 5aa3c498..c2a7f9fb 100644
--- a/tests/unittests/test_handler/test_handler_resizefs.py
+++ b/tests/unittests/test_handler/test_handler_resizefs.py
@@ -7,21 +7,13 @@ from collections import namedtuple
import logging
import textwrap
-from cloudinit.tests.helpers import (CiTestCase, mock, skipIf, util,
- wrap_and_call)
+from cloudinit.tests.helpers import (
+ CiTestCase, mock, skipUnlessJsonSchema, util, wrap_and_call)
LOG = logging.getLogger(__name__)
-try:
- import jsonschema
- assert jsonschema # avoid pyflakes error F401: import unused
- _missing_jsonschema_dep = False
-except ImportError:
- _missing_jsonschema_dep = True
-
-
class TestResizefs(CiTestCase):
with_logs = True
@@ -76,7 +68,7 @@ class TestResizefs(CiTestCase):
'DEBUG: Skipping module named cc_resizefs, resizing disabled\n',
self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_handle_schema_validation_logs_invalid_resize_rootfs_value(self):
"""The handle reports json schema violations as a warning.
diff --git a/tests/unittests/test_handler/test_handler_runcmd.py b/tests/unittests/test_handler/test_handler_runcmd.py
index 374c1d31..dbbb2717 100644
--- a/tests/unittests/test_handler/test_handler_runcmd.py
+++ b/tests/unittests/test_handler/test_handler_runcmd.py
@@ -3,19 +3,13 @@
from cloudinit.config import cc_runcmd
from cloudinit.sources import DataSourceNone
from cloudinit import (distros, helpers, cloud, util)
-from cloudinit.tests.helpers import FilesystemMockingTestCase, skipIf
+from cloudinit.tests.helpers import (
+ FilesystemMockingTestCase, skipUnlessJsonSchema)
import logging
import os
import stat
-try:
- import jsonschema
- assert jsonschema # avoid pyflakes error F401: import unused
- _missing_jsonschema_dep = False
-except ImportError:
- _missing_jsonschema_dep = True
-
LOG = logging.getLogger(__name__)
@@ -56,7 +50,7 @@ class TestRuncmd(FilesystemMockingTestCase):
' /var/lib/cloud/instances/iid-datasource-none/scripts/runcmd',
self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_handler_schema_validation_warns_non_array_type(self):
"""Schema validation warns of non-array type for runcmd key.
@@ -71,7 +65,7 @@ class TestRuncmd(FilesystemMockingTestCase):
self.logs.getvalue())
self.assertIn('Failed to shellify', self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, 'No python-jsonschema dependency')
+ @skipUnlessJsonSchema()
def test_handler_schema_validation_warns_non_array_item_type(self):
"""Schema validation warns of non-array or string runcmd items.
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py
index df67a0e0..1ecb6c68 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -6,7 +6,7 @@ from cloudinit.config.schema import (
validate_cloudconfig_schema, main)
from cloudinit.util import subp, write_file
-from cloudinit.tests.helpers import CiTestCase, mock, skipIf
+from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema
from copy import copy
import os
@@ -14,13 +14,6 @@ from six import StringIO
from textwrap import dedent
from yaml import safe_load
-try:
- import jsonschema
- assert jsonschema # avoid pyflakes error F401: import unused
- _missing_jsonschema_dep = False
-except ImportError:
- _missing_jsonschema_dep = True
-
class GetSchemaTest(CiTestCase):
@@ -73,7 +66,7 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
with_logs = True
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_validateconfig_schema_non_strict_emits_warnings(self):
"""When strict is False validate_cloudconfig_schema emits warnings."""
schema = {'properties': {'p1': {'type': 'string'}}}
@@ -82,7 +75,7 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
"Invalid config:\np1: -1 is not of type 'string'\n",
self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_validateconfig_schema_emits_warning_on_missing_jsonschema(self):
"""Warning from validate_cloudconfig_schema when missing jsonschema."""
schema = {'properties': {'p1': {'type': 'string'}}}
@@ -92,7 +85,7 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
'Ignoring schema validation. python-jsonschema is not present',
self.logs.getvalue())
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_validateconfig_schema_strict_raises_errors(self):
"""When strict is True validate_cloudconfig_schema raises errors."""
schema = {'properties': {'p1': {'type': 'string'}}}
@@ -102,7 +95,7 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
"Cloud config schema errors: p1: -1 is not of type 'string'",
str(context_mgr.exception))
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_validateconfig_schema_honors_formats(self):
"""With strict True, validate_cloudconfig_schema errors on format."""
schema = {
@@ -153,7 +146,7 @@ class ValidateCloudConfigFileTest(CiTestCase):
self.config_file),
str(context_mgr.exception))
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_validateconfig_file_sctricty_validates_schema(self):
"""validate_cloudconfig_file raises errors on invalid schema."""
schema = {
@@ -376,7 +369,7 @@ class CloudTestsIntegrationTest(CiTestCase):
raises Warnings or errors on invalid cloud-config schema.
"""
- @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency")
+ @skipUnlessJsonSchema()
def test_all_integration_test_cloud_config_schema(self):
"""Validate schema of cloud_tests yaml files looking for warnings."""
schema = get_schema()