Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions cloudinit/config/cc_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
- ['snap', 'install', 'vlc']
- snap install vlc
- 'snap install vlc'
"""), dedent("""\
# You can use a list of assertions
snap:
assertions:
- signed_assertion_blob_here
- |
signed_assertion_blob_here
""")],
'frequency': PER_INSTANCE,
'type': 'object',
Expand All @@ -106,7 +113,8 @@
'additionalItems': False, # Reject items non-string
'minItems': 1,
'minProperties': 1,
'uniqueItems': True
'uniqueItems': True,
'additionalProperties': {'type': 'string'},
},
'commands': {
'type': ['object', 'array'], # Array of strings or dict
Expand Down Expand Up @@ -136,10 +144,6 @@
}
}

# TODO schema for 'assertions' and 'commands' are too permissive at the moment.
# Once python-jsonschema supports schema draft 6 add support for arbitrary
# object keys with 'patternProperties' constraint to validate string values.

__doc__ = get_schema_doc(schema) # Supplement python help()

SNAP_CMD = "snap"
Expand Down
14 changes: 14 additions & 0 deletions cloudinit/config/tests/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ def test_schema_when_commands_list_values_are_invalid_type(self, _):
" of the given schemas\n",
self.logs.getvalue())

@mock.patch('cloudinit.config.cc_snap.run_commands')
def test_schema_when_assertions_values_are_invalid_type(self, _):
"""Warnings when snap:assertions values are invalid type (e.g. int)"""
validate_cloudconfig_schema(
{'snap': {'assertions': [123]}}, schema)
validate_cloudconfig_schema(
{'snap': {'assertions': {'01': 123}}}, schema)
self.assertEqual(
"WARNING: Invalid config:\n"
"snap.assertions.0: 123 is not of type 'string'\n"
"WARNING: Invalid config:\n"
"snap.assertions.01: 123 is not of type 'string'\n",
self.logs.getvalue())

@mock.patch('cloudinit.config.cc_snap.add_assertions')
def test_warn_schema_assertions_is_not_list_or_dict(self, _):
"""Warn when snap:assertions config is not a list or dict."""
Expand Down