summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-04-18 20:37:07 -0600
committerChad Smith <chad.smith@canonical.com>2018-04-18 20:37:07 -0600
commit6811926fdb991ad02ad9c0134c1d4bbe82ef87e1 (patch)
treeb90a1a50f7ac52e050ac006d88e6be75948ded21 /tests/unittests/test_handler
parent6d48d265a0548a2dc23e587f2a335d4e38e8db90 (diff)
downloadvyos-cloud-init-6811926fdb991ad02ad9c0134c1d4bbe82ef87e1.tar.gz
vyos-cloud-init-6811926fdb991ad02ad9c0134c1d4bbe82ef87e1.zip
Schema: do not warn on duplicate items in commands.
runcmd, bootcmd, snap/commands, ubuntu-advantage/commands would log warning (and fail if strict) on duplicate values in the commands. But those should be allowed. Example, it is perfectly valid to do: runcmd: ['sleep 1', 'sleep 1'] LP: #1764264
Diffstat (limited to 'tests/unittests/test_handler')
-rw-r--r--tests/unittests/test_handler/test_handler_bootcmd.py24
-rw-r--r--tests/unittests/test_handler/test_handler_runcmd.py25
2 files changed, 46 insertions, 3 deletions
diff --git a/tests/unittests/test_handler/test_handler_bootcmd.py b/tests/unittests/test_handler/test_handler_bootcmd.py
index 29fc25e4..c3abedde 100644
--- a/tests/unittests/test_handler/test_handler_bootcmd.py
+++ b/tests/unittests/test_handler/test_handler_bootcmd.py
@@ -1,6 +1,6 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from cloudinit.config import cc_bootcmd
+from cloudinit.config import cc_bootcmd, schema
from cloudinit.sources import DataSourceNone
from cloudinit import (distros, helpers, cloud, util)
from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema
@@ -138,4 +138,26 @@ class TestBootcmd(CiTestCase):
self.logs.getvalue())
+class TestSchema(CiTestCase):
+ """Directly test schema rather than through handle."""
+
+ def test_duplicates_are_fine_array_array(self):
+ """Duplicated array entries are allowed."""
+ try:
+ byebye = ["echo", "bye"]
+ schema.validate_cloudconfig_schema(
+ {'bootcmd': [byebye, byebye]}, cc_bootcmd.schema, strict=True)
+ except schema.SchemaValidationError as e:
+ self.fail("runcmd entries as list are allowed to be duplicates.")
+
+ def test_duplicates_are_fine_array_string(self):
+ """Duplicated array entries entries are allowed in values of array."""
+ try:
+ byebye = "echo bye"
+ schema.validate_cloudconfig_schema(
+ {'bootcmd': [byebye, byebye]}, cc_bootcmd.schema, strict=True)
+ except schema.SchemaValidationError as e:
+ self.fail("runcmd entries are allowed to be duplicates.")
+
+
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_handler/test_handler_runcmd.py b/tests/unittests/test_handler/test_handler_runcmd.py
index dbbb2717..ee1981d1 100644
--- a/tests/unittests/test_handler/test_handler_runcmd.py
+++ b/tests/unittests/test_handler/test_handler_runcmd.py
@@ -1,10 +1,10 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from cloudinit.config import cc_runcmd
+from cloudinit.config import cc_runcmd, schema
from cloudinit.sources import DataSourceNone
from cloudinit import (distros, helpers, cloud, util)
from cloudinit.tests.helpers import (
- FilesystemMockingTestCase, skipUnlessJsonSchema)
+ CiTestCase, FilesystemMockingTestCase, skipUnlessJsonSchema)
import logging
import os
@@ -99,4 +99,25 @@ class TestRuncmd(FilesystemMockingTestCase):
self.assertEqual(0o700, stat.S_IMODE(file_stat.st_mode))
+class TestSchema(CiTestCase):
+ """Directly test schema rather than through handle."""
+
+ def test_duplicates_are_fine_array(self):
+ """Duplicated array entries are allowed."""
+ try:
+ byebye = ["echo", "bye"]
+ schema.validate_cloudconfig_schema(
+ {'runcmd': [byebye, byebye]}, cc_runcmd.schema, strict=True)
+ except schema.SchemaValidationError as e:
+ self.fail("runcmd entries as list are allowed to be duplicates.")
+
+ def test_duplicates_are_fine_string(self):
+ """Duplicated string entries are allowed."""
+ try:
+ byebye = "echo bye"
+ schema.validate_cloudconfig_schema(
+ {'runcmd': [byebye, byebye]}, cc_runcmd.schema, strict=True)
+ except schema.SchemaValidationError as e:
+ self.fail("runcmd entries are allowed to be duplicates.")
+
# vi: ts=4 expandtab