From f08830cd71a5f62966f554e2a879f2a579ca3f60 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 20 Jul 2023 16:58:10 +1200 Subject: [PATCH] fix autoinstalling core boot classic and add integration and unit tests --- examples/autoinstall/hybrid.yaml | 10 +++++++ scripts/runtests.sh | 13 +++++++++ subiquity/server/controllers/filesystem.py | 11 +++---- .../controllers/tests/test_filesystem.py | 29 +++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 examples/autoinstall/hybrid.yaml diff --git a/examples/autoinstall/hybrid.yaml b/examples/autoinstall/hybrid.yaml new file mode 100644 index 00000000..e6dee173 --- /dev/null +++ b/examples/autoinstall/hybrid.yaml @@ -0,0 +1,10 @@ +version: 1 +source: + id: src-mandatory +storage: + layout: + name: hybrid +identity: + hostname: ai-test + password: "$y$j9T$UdY22v4Kexn/AZcIzBSUc0$2DnuvWDSwoDCFPlbk1ghZeT2qFrEBKY1bpFQoexHdw7" + username: ubuntu diff --git a/scripts/runtests.sh b/scripts/runtests.sh index fd2e3023..893471e3 100755 --- a/scripts/runtests.sh +++ b/scripts/runtests.sh @@ -267,6 +267,19 @@ python3 scripts/check-yaml-fields.py "$tmpdir"/var/log/installer/autoinstall-use 'autoinstall.source.id="ubuntu-server-minimal"' grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades: SUCCESS: downloading and installing security updates' $tmpdir/subiquity-server-debug.log +clean +LANG=C.UTF-8 timeout --foreground 60 \ + python3 -m subiquity.cmd.tui \ + --dry-run \ + --output-base "$tmpdir" \ + --machine-config examples/machines/simple.json \ + --autoinstall examples/autoinstall/hybrid.yaml \ + --dry-run-config examples/dry-run-configs/tpm.yaml \ + --bootloader uefi \ + --kernel-cmdline autoinstall \ + --source-catalog examples/sources/tpm.yaml +validate + clean LANG=C.UTF-8 timeout --foreground 60 \ python3 -m subiquity.cmd.tui \ diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index 72f12dd4..4d951394 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -1145,12 +1145,13 @@ class FilesystemController(SubiquityController, FilesystemManipulator): if name == 'hybrid': # this check is conceptually unnecessary but results in a # much cleaner error message... + core_boot_caps = set() for variation in self._variation_info.values(): if not variation.is_valid(): continue if variation.is_core_boot_classic(): - break - else: + core_boot_caps.update(variation.capability_info.allowed) + if not core_boot_caps: raise Exception( "can only use name: hybrid when installing core boot " "classic") @@ -1160,15 +1161,15 @@ class FilesystemController(SubiquityController, FilesystemManipulator): encrypted = layout.get('encrypted', None) GC = GuidedCapability if encrypted is None: - if GC.CORE_BOOT_ENCRYPTED in self._info.capabilities or \ - GC.CORE_BOOT_PREFER_ENCRYPTED in self._info.capabilities: + if GC.CORE_BOOT_ENCRYPTED in core_boot_caps or \ + GC.CORE_BOOT_PREFER_ENCRYPTED in core_boot_caps: capability = GC.CORE_BOOT_ENCRYPTED else: capability = GC.CORE_BOOT_UNENCRYPTED elif encrypted: capability = GC.CORE_BOOT_ENCRYPTED else: - if self._info.capabilities == { + if core_boot_caps == { GuidedCapability.CORE_BOOT_ENCRYPTED} and \ not encrypted: raise Exception("cannot install this model unencrypted") diff --git a/subiquity/server/controllers/tests/test_filesystem.py b/subiquity/server/controllers/tests/test_filesystem.py index df202118..f70c3092 100644 --- a/subiquity/server/controllers/tests/test_filesystem.py +++ b/subiquity/server/controllers/tests/test_filesystem.py @@ -1226,6 +1226,35 @@ class TestCoreBootInstallMethods(IsolatedAsyncioTestCase): self.assertEqual(request.action, snapdapi.SystemAction.INSTALL) self.assertEqual(request.step, snapdapi.SystemActionStep.FINISH) + async def test_from_sample_data_autoinstall(self): + # calling this a unit test is definitely questionable. but it + # runs much more quickly than the integration test! + self.fsc.model = model = make_model(Bootloader.UEFI) + disk = make_disk(model) + self.app.base_model.source.current.variations = { + 'default': CatalogEntryVariation( + path='', size=1, snapd_system_label='prefer-encrypted'), + } + + self.app.dr_cfg.systems_dir_exists = True + + await self.fsc._examine_systems_task.start() + await self.fsc._examine_systems_task.wait() + self.fsc.start() + + await self.fsc.run_autoinstall_guided({'name': 'hybrid'}) + + self.assertEqual(model.storage_version, 2) + + partition_count = len([ + structure + for structure in self.fsc._info.system.volumes['pc'].structure + if structure.role != snapdapi.Role.MBR + ]) + self.assertEqual( + partition_count, + len(disk.partitions())) + async def test_from_sample_data_defective(self): self.fsc.model = model = make_model(Bootloader.UEFI) make_disk(model)