From 0b3a1c2c6a56761b7425e5737fa08091d11514a5 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 19 Jul 2023 15:14:50 +1200 Subject: [PATCH] generalize InstallController's handling of installs without apt --- subiquity/models/subiquity.py | 6 +++ subiquity/server/controllers/install.py | 70 ++++++++++++++----------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index 03f83f18f..85e183e96 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -433,6 +433,12 @@ def _cloud_init_files(self): return files def configure_cloud_init(self): + if self.target is None: + # i.e. reset_partition_only + return + if self.source.current.variant == 'core': + # can probably be supported but requires changes + return for path, content, cmode in self._cloud_init_files(): path = os.path.join(self.target, path) os.makedirs(os.path.dirname(path), exist_ok=True) diff --git a/subiquity/server/controllers/install.py b/subiquity/server/controllers/install.py index 1178a28cb..420857de4 100644 --- a/subiquity/server/controllers/install.py +++ b/subiquity/server/controllers/install.py @@ -180,6 +180,10 @@ async def unmount_target(self, *, context, target): if not self.app.opts.dry_run: shutil.rmtree(target) + def supports_apt(self) -> bool: + return self.model.target is not None and \ + self.model.source.current.variant != 'core' + @with_context( description="configuring apt", level="INFO", childlevel="DEBUG") async def configure_apt(self, *, context): @@ -189,6 +193,8 @@ async def configure_apt(self, *, context): return await configurer.configure_for_install(context) async def setup_target(self, context): + if not self.supports_apt(): + return mirror = self.app.controllers.Mirror await mirror.final_apt_configurer.setup_target(context, self.tpath()) @@ -472,32 +478,34 @@ async def install(self, *, context): self.app.update_state(ApplicationState.RUNNING) - if not self.app.controllers.Filesystem.reset_partition_only: - for_install_path = await self.configure_apt(context=context) + if self.model.target is None: + for_install_path = None + elif self.supports_apt(): + for_install_path = 'cp://' + await self.configure_apt( + context=context) await self.app.hub.abroadcast(InstallerChannels.APT_CONFIGURED) - - if os.path.exists(self.model.target): - await self.unmount_target( - context=context, target=self.model.target) else: - for_install_path = '' + fsc = self.app.controllers.Filesystem + for_install_path = self.model.source.get_source(fsc._info.name) if self.app.controllers.Filesystem.reset_partition: self.app.package_installer.start_installing_pkg('efibootmgr') - await self.curtin_install( - context=context, source='cp://' + for_install_path) + if self.model.target is not None: + if os.path.exists(self.model.target): + await self.unmount_target( + context=context, target=self.model.target) - if not self.app.controllers.Filesystem.reset_partition_only: + await self.curtin_install(context=context, source=for_install_path) - self.app.update_state(ApplicationState.WAITING) + self.app.update_state(ApplicationState.WAITING) - await self.model.wait_postinstall() + await self.model.wait_postinstall() - self.app.update_state(ApplicationState.RUNNING) + self.app.update_state(ApplicationState.RUNNING) - await self.postinstall(context=context) + await self.postinstall(context=context) self.app.update_state(ApplicationState.DONE) except Exception: @@ -518,22 +526,24 @@ async def postinstall(self, *, context): {"autoinstall": self.app.make_autoinstall()}) write_file(autoinstall_path, autoinstall_config) await self.configure_cloud_init(context=context) - packages = await self.get_target_packages(context=context) - for package in packages: - await self.install_package(context=context, package=package) - if self.model.drivers.do_install: - with context.child( - "ubuntu-drivers-install", - "installing third-party drivers") as child: - ubuntu_drivers = self.app.controllers.Drivers.ubuntu_drivers - await ubuntu_drivers.install_drivers(root_dir=self.tpath(), - context=child) - - if self.model.network.has_network: - self.app.update_state(ApplicationState.UU_RUNNING) - policy = self.model.updates.updates - await self.run_unattended_upgrades(context=context, policy=policy) - await self.restore_apt_config(context=context) + if self.supports_apt(): + packages = await self.get_target_packages(context=context) + for package in packages: + await self.install_package(context=context, package=package) + if self.model.drivers.do_install: + with context.child( + "ubuntu-drivers-install", + "installing third-party drivers") as child: + udrivers = self.app.controllers.Drivers.ubuntu_drivers + await udrivers.install_drivers( + root_dir=self.tpath(), + context=child) + if self.model.network.has_network: + self.app.update_state(ApplicationState.UU_RUNNING) + policy = self.model.updates.updates + await self.run_unattended_upgrades( + context=context, policy=policy) + await self.restore_apt_config(context=context) if self.model.active_directory.do_join: hostname = self.model.identity.hostname if not hostname: