Skip to content

Commit

Permalink
cc-extract: don't unnecessarily access data
Browse files Browse the repository at this point in the history
We currently don't have plans to do anything with the _data_ of the
keys that fail to validate by cloud-init; and trying to access this
data has the potential to crash the installer if it doesn't exist,
at least at the top level (LP: #2062988).
  • Loading branch information
Chris-Peterson444 committed Apr 29, 2024
1 parent 65f8ef5 commit 3c2d8fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion subiquity/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,13 @@ async def _extract_autoinstall_from_cloud_config(
# of the schema validation error, otherwise continue

# Filter only the bad keys
# Intentionally (key, None) ! Have a good plan (and reason) for
# getting the data of a key. It is not guaranteed that the
# offending keys to be top-level (or in?) in the combined config.
# LP: #2062988

potential_autoinstall: dict[str, Any] = dict(
((key, cloud_cfg[key]) for key in bad_keys)
((key, None) for key in bad_keys)
)
autoinstall, other = self.filter_autoinstall(potential_autoinstall)

Expand Down
16 changes: 16 additions & 0 deletions subiquity/server/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,22 @@ async def test_autoinstall_from_cloud_config(self, cloud_cfg, expected, throws):

self.assertEqual(cfg, expected)

async def test_cloud_config_extract_KeyError(self):
"""Test autoinstall extract from cloud config resilient to missing data."""

self.server.base_schema = SubiquityServer.base_schema
self.pseudo_load_controllers()

with patch("subiquity.server.server.validate_cloud_init_schema") as val_mock:
val_mock.side_effect = CloudInitSchemaValidationError(
keys=["broadcast", "foobar"],
)

# Don't throw on keys that error but aren't in the combined config
cfg = await self.server._extract_autoinstall_from_cloud_config(cloud_cfg={})

self.assertEqual(cfg, {})

async def test_autoinstall_validation__top_level_autoinstall(self):
"""Test allow autoinstall as top-level key"""

Expand Down

0 comments on commit 3c2d8fe

Please sign in to comment.