From d4820497e7f2c613a328509d0f5f0f049a9dcf3f Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 10 Oct 2023 16:29:53 +0200 Subject: [PATCH] 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 --- subiquity/server/controllers/filesystem.py | 1 + .../controllers/tests/test_filesystem.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index b792426c..9995e4e9 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -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 diff --git a/subiquity/server/controllers/tests/test_filesystem.py b/subiquity/server/controllers/tests/test_filesystem.py index d3888bb5..4321601d 100644 --- a/subiquity/server/controllers/tests/test_filesystem.py +++ b/subiquity/server/controllers/tests/test_filesystem.py @@ -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 = [