From 30030ef3ebe5f96bf740b033d5fb82620c250700 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 7 Apr 2020 21:23:03 +1200 Subject: [PATCH 1/2] handle a disk match in a layout --- subiquity/controllers/filesystem.py | 11 ++++++----- subiquity/models/filesystem.py | 30 ++++++++++++++++------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 3b83f98d..8701e4f4 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -156,12 +156,13 @@ class FilesystemController(SubiquityController): break log.debug("self.ai_data = %s", self.ai_data) if 'layout' in self.ai_data: + layout = self.ai_data['layout'] with self.context.child("applying_autoinstall"): - meth = getattr( - self, "guided_" + self.ai_data['layout']['name']) - disks = self.model.all_disks() - disks.sort(key=lambda x: x.size) - meth(disks[-1]) + meth = getattr(self, "guided_" + layout['name']) + disk = self.model.disk_for_match( + self.model.all_disks(), + layout.get("match", {'size': 'largest'})) + meth(disk) elif 'config' in self.ai_data: with self.context.child("applying_autoinstall"): self.model.apply_autoinstall_config(self.ai_data['config']) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index ce0d6d03..aa91a714 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -1301,6 +1301,21 @@ class FilesystemModel(object): return matchers + def disk_for_match(self, disks, match): + matchers = self._make_matchers(match) + candidates = [] + for candidate in disks: + for matcher in matchers: + if not matcher(candidate): + break + else: + candidates.append(candidate) + if match.get('size') == 'largest': + candidates.sort(key=lambda d: d.size, reverse=True) + if candidates: + return candidates[0] + return None + def apply_autoinstall_config(self, ai_config): disks = self.all_disks() for action in ai_config: @@ -1312,19 +1327,8 @@ class FilesystemModel(object): disk = self._one(type='disk', path=action['path']) else: match = action.pop('match', {}) - matchers = self._make_matchers(match) - candidates = [] - for candidate in disks: - for matcher in matchers: - if not matcher(candidate): - break - else: - candidates.append(candidate) - if match.get('size') == 'largest': - candidates.sort(key=lambda d: d.size, reverse=True) - if candidates: - disk = candidates[0] - else: + disk = self.disk_for_match(disks, match) + if disk is None: action['match'] = match if disk is None: raise Exception("{} matched no disk".format(action)) From 5d48da58415e3283cecee7829ed13d12f1d439ea Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 7 Apr 2020 21:23:27 +1200 Subject: [PATCH 2/2] allow autoinstall file to control swapfile creation --- subiquity/controllers/filesystem.py | 2 +- subiquity/models/filesystem.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 8701e4f4..64f30527 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -173,7 +173,7 @@ class FilesystemController(SubiquityController): for action in self.model._actions: if action['id'] == device: self.model.grub_install_device = action - # Should handle 'swap' here too. + self.model.swap = self.ai_data.get('swap') def start(self): self._start_task = schedule_task(self._start()) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index aa91a714..0780eeb3 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -1270,6 +1270,7 @@ class FilesystemModel(object): self._orig_config = [] self._actions = [] self.grub_install_device = None + self.swap = None def _make_matchers(self, match): matchers = [] @@ -1515,8 +1516,8 @@ class FilesystemModel(object): 'config': self._render_actions(), }, } - if not self._should_add_swapfile(): - config['swap'] = {'size': 0} + if self.swap is not None: + config['swap'] = self.swap if self.grub_install_device: dev = self.grub_install_device if dev.type == "partition": @@ -1679,11 +1680,18 @@ class FilesystemModel(object): raise Exception("%s is already mounted") m = Mount(m=self, device=fs, path=path) self._actions.append(m) + # Adding a swap partition or mounting btrfs at / suppresses + # the swapfile. + if not self._should_add_swapfile(): + self.swap = {'swap': 0} return m def remove_mount(self, mount): _remove_backlinks(mount) self._actions.remove(mount) + # Removing a mount might make it ok to add a swapfile again. + if self._should_add_swapfile(): + self.swap = None def needs_bootloader_partition(self): '''true if no disk have a boot partition, and one is needed'''