summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Falcon <TheRealFalcon@users.noreply.github.com>2020-05-08 16:38:51 -0500
committerGitHub <noreply@github.com>2020-05-08 17:38:51 -0400
commit34b868020254106af8c79ffb85e04e294b19e44f (patch)
tree7b7e285f0b9c13a7d9551d61ec5ef0b38b6e3263
parentb24b376fabd54e4dc96ffc1b90a984addf42fc4c (diff)
downloadcloud-init-git-34b868020254106af8c79ffb85e04e294b19e44f.tar.gz
Add test to ensure docs examples are valid cloud-init configs (#355)
Also update all examples to include the cloud-config header if they don't have it LP: #1876414
-rw-r--r--doc/examples/cloud-config-apt.txt1
-rw-r--r--doc/examples/cloud-config-datasources.txt2
-rw-r--r--doc/examples/cloud-config-disk-setup.txt1
-rw-r--r--doc/examples/cloud-config-landscape.txt1
-rw-r--r--doc/examples/cloud-config-rsyslog.txt1
-rw-r--r--tests/unittests/test_handler/test_schema.py33
6 files changed, 32 insertions, 7 deletions
diff --git a/doc/examples/cloud-config-apt.txt b/doc/examples/cloud-config-apt.txt
index ec10ae94..5a56cd1b 100644
--- a/doc/examples/cloud-config-apt.txt
+++ b/doc/examples/cloud-config-apt.txt
@@ -1,3 +1,4 @@
+#cloud-config
# apt_pipelining (configure Acquire::http::Pipeline-Depth)
# Default: disables HTTP pipelining. Certain web servers, such
# as S3 do not pipeline properly (LP: #948461).
diff --git a/doc/examples/cloud-config-datasources.txt b/doc/examples/cloud-config-datasources.txt
index e5780472..13bb687c 100644
--- a/doc/examples/cloud-config-datasources.txt
+++ b/doc/examples/cloud-config-datasources.txt
@@ -1,3 +1,5 @@
+#cloud-config
+
# Documentation on data sources configuration options
datasource:
# Ec2
diff --git a/doc/examples/cloud-config-disk-setup.txt b/doc/examples/cloud-config-disk-setup.txt
index 6b7112cb..5c6de77e 100644
--- a/doc/examples/cloud-config-disk-setup.txt
+++ b/doc/examples/cloud-config-disk-setup.txt
@@ -1,3 +1,4 @@
+#cloud-config
# Cloud-init supports the creation of simple partition tables and file systems
# on devices.
diff --git a/doc/examples/cloud-config-landscape.txt b/doc/examples/cloud-config-landscape.txt
index d7ff8ef8..88be57ce 100644
--- a/doc/examples/cloud-config-landscape.txt
+++ b/doc/examples/cloud-config-landscape.txt
@@ -1,3 +1,4 @@
+#cloud-config
# Landscape-client configuration
#
# Anything under the top 'landscape: client' entry
diff --git a/doc/examples/cloud-config-rsyslog.txt b/doc/examples/cloud-config-rsyslog.txt
index 8113272d..d28dd38e 100644
--- a/doc/examples/cloud-config-rsyslog.txt
+++ b/doc/examples/cloud-config-rsyslog.txt
@@ -1,3 +1,4 @@
+#cloud-config
## the rsyslog module allows you to configure the systems syslog.
## configuration of syslog is under the top level cloud-config
## entry 'rsyslog'.
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py
index ae3838d8..071b98bc 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -1,5 +1,5 @@
# This file is part of cloud-init. See LICENSE file for license information.
-
+import cloudinit
from cloudinit.config.schema import (
CLOUD_CONFIG_HEADER, SchemaValidationError, annotated_cloudconfig_file,
get_schema_doc, get_schema, validate_cloudconfig_file,
@@ -12,6 +12,7 @@ from copy import copy
import os
import pytest
from io import StringIO
+from pathlib import Path
from textwrap import dedent
from yaml import safe_load
@@ -114,13 +115,12 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
class TestCloudConfigExamples:
-
- SCHEMA = get_schema()
- PARAMS = [
+ schema = get_schema()
+ params = [
(schema["id"], example)
- for schema in SCHEMA["allOf"] for example in schema["examples"]]
+ for schema in schema["allOf"] for example in schema["examples"]]
- @pytest.mark.parametrize("schema_id,example", PARAMS)
+ @pytest.mark.parametrize("schema_id,example", params)
@skipUnlessJsonSchema()
def test_validateconfig_schema_of_example(self, schema_id, example):
""" For a given example in a config module we test if it is valid
@@ -128,7 +128,7 @@ class TestCloudConfigExamples:
"""
config_load = safe_load(example)
validate_cloudconfig_schema(
- config_load, TestCloudConfigExamples.SCHEMA, strict=True)
+ config_load, self.schema, strict=True)
class ValidateCloudConfigFileTest(CiTestCase):
@@ -447,4 +447,23 @@ class CloudTestsIntegrationTest(CiTestCase):
if errors:
raise AssertionError(', '.join(errors))
+
+def _get_schema_doc_examples():
+ examples_dir = Path(
+ cloudinit.__file__).parent.parent / 'doc' / 'examples'
+ assert examples_dir.is_dir()
+
+ all_text_files = (f for f in examples_dir.glob('cloud-config*.txt')
+ if not f.name.startswith('cloud-config-archive'))
+ return all_text_files
+
+
+class TestSchemaDocExamples:
+ schema = get_schema()
+
+ @pytest.mark.parametrize("example_path", _get_schema_doc_examples())
+ @skipUnlessJsonSchema()
+ def test_schema_doc_examples(self, example_path):
+ validate_cloudconfig_file(str(example_path), self.schema)
+
# vi: ts=4 expandtab syntax=python