Skip to content

Commit

Permalink
cloud: top-level key validation skip check
Browse files Browse the repository at this point in the history
The "schema" subcommand was introduced in cloud-init 22.2 (see
cloud-init commit [0] ), which was released April 27, 2022. This means
older releases of Focal and Jammy, which are currently supported LTSes,
will fail this code path after we unstage cloud-init from the Subiquity
snap. Add a check to skip this validation if a newer version of
cloud-init is detected.

[0] 3bcffacb216d683241cf955e4f7f3e89431c1491
  • Loading branch information
Chris-Peterson444 committed Sep 16, 2024
1 parent 1e2bc9f commit 935897b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions subiquity/cloudinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def supports_recoverable_errors() -> bool:
return cloud_init_version() >= "23.4"


def supports_schema_subcommand() -> bool:
return cloud_init_version() >= "22.2"


def read_json_extended_status(stream):
try:
status = json.loads(stream)
Expand Down Expand Up @@ -167,6 +171,13 @@ async def validate_cloud_init_top_level_keys() -> None:
:raises CloudInitSchemaTopLevelKeyError: If cloud-init schema did not
validate successfully.
"""
if not supports_schema_subcommand():
log.debug(
"Host cloud-config doesn't support 'schema' subcommand. "
"Skipping top-level key cloud-config validation."
)
return None

causes: list[str] = await get_unknown_keys()

if causes:
Expand Down
30 changes: 30 additions & 0 deletions subiquity/tests/test_cloudinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,36 @@ async def test_get_schema_warn_on_timeout(self, log_mock, wait_for_mock):
log_mock.warning.assert_called()
self.assertEqual([], sources)

@parameterized.expand(
(
("20.2", True),
("22.1", True),
("22.2", False),
("23.0", False),
)
)
async def test_version_check_and_skip(self, version, should_skip):
"""Test that top-level key validation skipped on right versions.
The "schema" subcommand, which the top-level key validation relies
on, was added in cloud-init version 22.2. This test is to ensure
that it's skipped on older releases.
"""
with (
patch("subiquity.cloudinit.get_unknown_keys") as keys_mock,
patch("subiquity.cloudinit.cloud_init_version") as version_mock,
):
version_mock.return_value = version

if should_skip:
await validate_cloud_init_top_level_keys()
keys_mock.assert_not_called()

else:
keys_mock.return_value = [] # avoid raise condition
await validate_cloud_init_top_level_keys()
keys_mock.assert_called_once()


class TestCloudInitRandomStrings(SubiTestCase):
def test_passwd_constraints(self):
Expand Down

0 comments on commit 935897b

Please sign in to comment.