filesystem: do not keep the variation info when the source changes

When the source changes, the available variations should change as well.
If we keep the old variations in the
FilesystemController._variations_info dictionary, we end up with a crash
later in the install.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-10-10 16:29:53 +02:00
parent 65612edc0b
commit d4820497e7
2 changed files with 31 additions and 0 deletions

View File

@ -404,6 +404,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
return info
async def _examine_systems(self):
self._variation_info.clear()
catalog_entry = self.app.base_model.source.current
for name, variation in catalog_entry.variations.items():
system = None

View File

@ -369,6 +369,36 @@ class TestSubiquityControllerFilesystem(IsolatedAsyncioTestCase):
await self.fsc._pre_shutdown()
mock_run.assert_called_once_with(["mountpoint", "/target"])
async def test_examine_systems(self):
# In LP: #2037723 and other similar reports, the user selects the
# source 'ubuntu-desktop-minimal' first and then switches to
# 'ubuntu-desktop'. The variations of those two sources are different.
# Upon switching to the new source, we forgot to discard the old
# variations. This lead to a crash further in the install.
self.fsc.model = model = make_model(Bootloader.UEFI)
make_disk(model)
self.app.base_model.source.current.type = "fsimage"
self.app.base_model.source.current.variations = {
"minimal": CatalogEntryVariation(path="", size=1),
}
self.app.dr_cfg = DRConfig()
self.app.dr_cfg.systems_dir_exists = True
await self.fsc._examine_systems()
self.assertEqual(len(self.fsc._variation_info), 1)
self.assertEqual(self.fsc._variation_info["minimal"].name, "minimal")
self.app.base_model.source.current.variations = {
"default": CatalogEntryVariation(path="", size=1),
}
await self.fsc._examine_systems()
self.assertEqual(len(self.fsc._variation_info), 1)
self.assertEqual(self.fsc._variation_info["default"].name, "default")
class TestGuided(IsolatedAsyncioTestCase):
boot_expectations = [