Merge pull request #1985 from Chris-Peterson444/cloud-init-schema-failure-lp-2062988
cc-extract: don't unnecessarily access data
This commit is contained in:
commit
eb155c363c
|
@ -783,12 +783,18 @@ class SubiquityServer(Application):
|
||||||
log=log,
|
log=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Raise AutoinstallError if we found any autoinstall as a cause
|
# Use filter_autoinstall on bad_keys to find potential autoinstall
|
||||||
# of the schema validation error, otherwise continue
|
# keys as the cause of the schema validation error. If so,
|
||||||
|
# raise AutoinstallError; else continue.
|
||||||
|
#
|
||||||
|
# Intentionally not attempting to extract bad key data since it is
|
||||||
|
# not guaranteed that the offending keys will be top-level (or
|
||||||
|
# even in?) in the combined config. Although still constructing
|
||||||
|
# a dict since filter_autoinstall expects a dict.
|
||||||
|
# LP: #2062988
|
||||||
|
|
||||||
# Filter only the bad keys
|
potential_autoinstall: dict[str, None] = dict(
|
||||||
potential_autoinstall: dict[str, Any] = dict(
|
((key, None) for key in bad_keys)
|
||||||
((key, cloud_cfg[key]) for key in bad_keys)
|
|
||||||
)
|
)
|
||||||
autoinstall, other = self.filter_autoinstall(potential_autoinstall)
|
autoinstall, other = self.filter_autoinstall(potential_autoinstall)
|
||||||
|
|
||||||
|
|
|
@ -456,6 +456,22 @@ class TestAutoinstallValidation(SubiTestCase):
|
||||||
|
|
||||||
self.assertEqual(cfg, expected)
|
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):
|
async def test_autoinstall_validation__top_level_autoinstall(self):
|
||||||
"""Test allow autoinstall as top-level key"""
|
"""Test allow autoinstall as top-level key"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue