Skip to content

Commit

Permalink
generalize InstallController's handling of installs without apt
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhudson committed Jul 19, 2023
1 parent 008da97 commit 0b3a1c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
6 changes: 6 additions & 0 deletions subiquity/models/subiquity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
70 changes: 40 additions & 30 deletions subiquity/server/controllers/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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())

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 0b3a1c2

Please sign in to comment.