diff --git a/snapcraft.yaml b/snapcraft.yaml index 928098a2f..c21fdea56 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -64,7 +64,7 @@ parts: plugin: python source-type: git source: https://git.launchpad.net/curtin - source-commit: 47c222681c81110a185497a64749f23596e29b16 + source-commit: 1fc717df52ec15f616d26fff3c10bff181599b30 build-packages: - shared-mime-info - zlib1g-dev diff --git a/subiquity/server/apt.py b/subiquity/server/apt.py index 469984013..e4b27243c 100644 --- a/subiquity/server/apt.py +++ b/subiquity/server/apt.py @@ -18,6 +18,7 @@ import logging import os import shutil +import subprocess import tempfile from typing import List, Optional, Union @@ -34,6 +35,10 @@ log = logging.getLogger('subiquity.server.apt') +class OverlayCleanupError(Exception): + """ Exception to raise when an overlay could not be cleaned up. """ + + class _MountBase: def p(self, *args: str) -> str: @@ -245,7 +250,10 @@ async def overlay(self): # Mountpoint object and (thanks to attr.s) make sure that it # compares equal to the one we discarded earlier. # But really, there should be better ways to handle this. - await self.unmount(Mountpoint(mountpoint=overlay.mountpoint)) + try: + await self.unmount(Mountpoint(mountpoint=overlay.mountpoint)) + except subprocess.CalledProcessError as exc: + raise OverlayCleanupError from exc async def cleanup(self): for m in reversed(self._mounts): diff --git a/subiquity/server/controllers/drivers.py b/subiquity/server/controllers/drivers.py index ade96456c..77cbb2aee 100644 --- a/subiquity/server/controllers/drivers.py +++ b/subiquity/server/controllers/drivers.py @@ -21,6 +21,7 @@ from subiquity.common.apidef import API from subiquity.common.types import DriversPayload, DriversResponse +from subiquity.server.apt import OverlayCleanupError from subiquity.server.controller import SubiquityController from subiquity.server.types import InstallerChannels from subiquity.server.ubuntu_drivers import ( @@ -83,16 +84,19 @@ async def _list_drivers(self, context): await self.configured() return apt = self.app.controllers.Mirror.apt_configurer - async with apt.overlay() as d: - try: - # Make sure ubuntu-drivers is available. - await self.ubuntu_drivers.ensure_cmd_exists(d.mountpoint) - except CommandNotFoundError: - self.drivers = [] - else: - self.drivers = await self.ubuntu_drivers.list_drivers( - root_dir=d.mountpoint, - context=context) + try: + async with apt.overlay() as d: + try: + # Make sure ubuntu-drivers is available. + await self.ubuntu_drivers.ensure_cmd_exists(d.mountpoint) + except CommandNotFoundError: + self.drivers = [] + else: + self.drivers = await self.ubuntu_drivers.list_drivers( + root_dir=d.mountpoint, + context=context) + except OverlayCleanupError: + log.exception("Failed to cleanup overlay. Continuing anyway.") log.debug("Available drivers to install: %s", self.drivers) if not self.drivers: await self.configured()