Merge ~smoser/cloud-init:bug/1764264-schema-runcmd-is-not-unique into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Chad Smith
Approved revision: 65ad8752dc214d3d7fba31a7f7a8e7fbcc48118a
Merge reported by: Chad Smith
Merged at revision: 6811926fdb991ad02ad9c0134c1d4bbe82ef87e1
Proposed branch: ~smoser/cloud-init:bug/1764264-schema-runcmd-is-not-unique
Merge into: cloud-init:master
Diff against target: 177 lines (+82/-7)
7 files modified
cloudinit/config/cc_bootcmd.py (+0/-1)
cloudinit/config/cc_runcmd.py (+0/-1)
cloudinit/config/cc_snap.py (+0/-1)
cloudinit/config/cc_ubuntu_advantage.py (+0/-1)
cloudinit/config/tests/test_snap.py (+36/-0)
tests/unittests/test_handler/test_handler_bootcmd.py (+23/-1)
tests/unittests/test_handler/test_handler_runcmd.py (+23/-2)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Chad Smith Approve
Review via email: mp+343575@code.launchpad.net

Commit message

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

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) wrote :

This is good, better to be flexible in the event users need to run the same command multiple times. As you mentioned in irc apt-get update may frequently show up multiple times.

Revision history for this message
Chad Smith (chad.smith) :
review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:65ad8752dc214d3d7fba31a7f7a8e7fbcc48118a
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1028/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1028/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=6811926f

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/config/cc_bootcmd.py b/cloudinit/config/cc_bootcmd.py
index 233da1e..db64f0a 100644
--- a/cloudinit/config/cc_bootcmd.py
+++ b/cloudinit/config/cc_bootcmd.py
@@ -63,7 +63,6 @@ schema = {
63 'additionalProperties': False,63 'additionalProperties': False,
64 'minItems': 1,64 'minItems': 1,
65 'required': [],65 'required': [],
66 'uniqueItems': True
67 }66 }
68 }67 }
69}68}
diff --git a/cloudinit/config/cc_runcmd.py b/cloudinit/config/cc_runcmd.py
index 539cbd5..b6f6c80 100644
--- a/cloudinit/config/cc_runcmd.py
+++ b/cloudinit/config/cc_runcmd.py
@@ -66,7 +66,6 @@ schema = {
66 'additionalProperties': False,66 'additionalProperties': False,
67 'minItems': 1,67 'minItems': 1,
68 'required': [],68 'required': [],
69 'uniqueItems': True
70 }69 }
71 }70 }
72}71}
diff --git a/cloudinit/config/cc_snap.py b/cloudinit/config/cc_snap.py
index 34a53fd..a7a0321 100644
--- a/cloudinit/config/cc_snap.py
+++ b/cloudinit/config/cc_snap.py
@@ -110,7 +110,6 @@ schema = {
110 'additionalItems': False, # Reject non-string & non-list110 'additionalItems': False, # Reject non-string & non-list
111 'minItems': 1,111 'minItems': 1,
112 'minProperties': 1,112 'minProperties': 1,
113 'uniqueItems': True
114 },113 },
115 'squashfuse_in_container': {114 'squashfuse_in_container': {
116 'type': 'boolean'115 'type': 'boolean'
diff --git a/cloudinit/config/cc_ubuntu_advantage.py b/cloudinit/config/cc_ubuntu_advantage.py
index 16b1868..29d18c9 100644
--- a/cloudinit/config/cc_ubuntu_advantage.py
+++ b/cloudinit/config/cc_ubuntu_advantage.py
@@ -87,7 +87,6 @@ schema = {
87 'additionalItems': False, # Reject non-string & non-list87 'additionalItems': False, # Reject non-string & non-list
88 'minItems': 1,88 'minItems': 1,
89 'minProperties': 1,89 'minProperties': 1,
90 'uniqueItems': True
91 }90 }
92 },91 },
93 'additionalProperties': False, # Reject keys not in schema92 'additionalProperties': False, # Reject keys not in schema
diff --git a/cloudinit/config/tests/test_snap.py b/cloudinit/config/tests/test_snap.py
index c5b4a9d..492d2d4 100644
--- a/cloudinit/config/tests/test_snap.py
+++ b/cloudinit/config/tests/test_snap.py
@@ -340,6 +340,42 @@ class TestSchema(CiTestCase):
340 {'snap': {'assertions': {'01': 'also valid'}}}, schema)340 {'snap': {'assertions': {'01': 'also valid'}}}, schema)
341 self.assertEqual('', self.logs.getvalue())341 self.assertEqual('', self.logs.getvalue())
342342
343 def test_duplicates_are_fine_array_array(self):
344 """Duplicated commands array/array entries are allowed."""
345 byebye = ["echo", "bye"]
346 try:
347 cfg = {'snap': {'commands': [byebye, byebye]}}
348 validate_cloudconfig_schema(cfg, schema, strict=True)
349 except schema.SchemaValidationError as e:
350 self.fail("command entries can be duplicate.")
351
352 def test_duplicates_are_fine_array_string(self):
353 """Duplicated commands array/string entries are allowed."""
354 byebye = "echo bye"
355 try:
356 cfg = {'snap': {'commands': [byebye, byebye]}}
357 validate_cloudconfig_schema(cfg, schema, strict=True)
358 except schema.SchemaValidationError as e:
359 self.fail("command entries can be duplicate.")
360
361 def test_duplicates_are_fine_dict_array(self):
362 """Duplicated commands dict/array entries are allowed."""
363 byebye = ["echo", "bye"]
364 try:
365 cfg = {'snap': {'commands': {'00': byebye, '01': byebye}}}
366 validate_cloudconfig_schema(cfg, schema, strict=True)
367 except schema.SchemaValidationError as e:
368 self.fail("command entries can be duplicate.")
369
370 def test_duplicates_are_fine_dict_string(self):
371 """Duplicated commands dict/string entries are allowed."""
372 byebye = "echo bye"
373 try:
374 cfg = {'snap': {'commands': {'00': byebye, '01': byebye}}}
375 validate_cloudconfig_schema(cfg, schema, strict=True)
376 except schema.SchemaValidationError as e:
377 self.fail("command entries can be duplicate.")
378
343379
344class TestHandle(CiTestCase):380class TestHandle(CiTestCase):
345381
diff --git a/tests/unittests/test_handler/test_handler_bootcmd.py b/tests/unittests/test_handler/test_handler_bootcmd.py
index 29fc25e..c3abedd 100644
--- a/tests/unittests/test_handler/test_handler_bootcmd.py
+++ b/tests/unittests/test_handler/test_handler_bootcmd.py
@@ -1,6 +1,6 @@
1# This file is part of cloud-init. See LICENSE file for license information.1# This file is part of cloud-init. See LICENSE file for license information.
22
3from cloudinit.config import cc_bootcmd3from cloudinit.config import cc_bootcmd, schema
4from cloudinit.sources import DataSourceNone4from cloudinit.sources import DataSourceNone
5from cloudinit import (distros, helpers, cloud, util)5from cloudinit import (distros, helpers, cloud, util)
6from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema6from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema
@@ -138,4 +138,26 @@ class TestBootcmd(CiTestCase):
138 self.logs.getvalue())138 self.logs.getvalue())
139139
140140
141class TestSchema(CiTestCase):
142 """Directly test schema rather than through handle."""
143
144 def test_duplicates_are_fine_array_array(self):
145 """Duplicated array entries are allowed."""
146 try:
147 byebye = ["echo", "bye"]
148 schema.validate_cloudconfig_schema(
149 {'bootcmd': [byebye, byebye]}, cc_bootcmd.schema, strict=True)
150 except schema.SchemaValidationError as e:
151 self.fail("runcmd entries as list are allowed to be duplicates.")
152
153 def test_duplicates_are_fine_array_string(self):
154 """Duplicated array entries entries are allowed in values of array."""
155 try:
156 byebye = "echo bye"
157 schema.validate_cloudconfig_schema(
158 {'bootcmd': [byebye, byebye]}, cc_bootcmd.schema, strict=True)
159 except schema.SchemaValidationError as e:
160 self.fail("runcmd entries are allowed to be duplicates.")
161
162
141# vi: ts=4 expandtab163# 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 dbbb271..ee1981d 100644
--- a/tests/unittests/test_handler/test_handler_runcmd.py
+++ b/tests/unittests/test_handler/test_handler_runcmd.py
@@ -1,10 +1,10 @@
1# This file is part of cloud-init. See LICENSE file for license information.1# This file is part of cloud-init. See LICENSE file for license information.
22
3from cloudinit.config import cc_runcmd3from cloudinit.config import cc_runcmd, schema
4from cloudinit.sources import DataSourceNone4from cloudinit.sources import DataSourceNone
5from cloudinit import (distros, helpers, cloud, util)5from cloudinit import (distros, helpers, cloud, util)
6from cloudinit.tests.helpers import (6from cloudinit.tests.helpers import (
7 FilesystemMockingTestCase, skipUnlessJsonSchema)7 CiTestCase, FilesystemMockingTestCase, skipUnlessJsonSchema)
88
9import logging9import logging
10import os10import os
@@ -99,4 +99,25 @@ class TestRuncmd(FilesystemMockingTestCase):
99 self.assertEqual(0o700, stat.S_IMODE(file_stat.st_mode))99 self.assertEqual(0o700, stat.S_IMODE(file_stat.st_mode))
100100
101101
102class TestSchema(CiTestCase):
103 """Directly test schema rather than through handle."""
104
105 def test_duplicates_are_fine_array(self):
106 """Duplicated array entries are allowed."""
107 try:
108 byebye = ["echo", "bye"]
109 schema.validate_cloudconfig_schema(
110 {'runcmd': [byebye, byebye]}, cc_runcmd.schema, strict=True)
111 except schema.SchemaValidationError as e:
112 self.fail("runcmd entries as list are allowed to be duplicates.")
113
114 def test_duplicates_are_fine_string(self):
115 """Duplicated string entries are allowed."""
116 try:
117 byebye = "echo bye"
118 schema.validate_cloudconfig_schema(
119 {'runcmd': [byebye, byebye]}, cc_runcmd.schema, strict=True)
120 except schema.SchemaValidationError as e:
121 self.fail("runcmd entries are allowed to be duplicates.")
122
102# vi: ts=4 expandtab123# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches