Merge pull request #689 from mwhudson/more-autoinstall-storage

two parts of the autoinstall storage spec i forgot about
This commit is contained in:
Michael Hudson-Doyle 2020-04-07 22:57:05 +12:00 committed by GitHub
commit 4bef0af3da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View File

@ -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'])
@ -172,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())

View File

@ -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 = []
@ -1301,6 +1302,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 +1328,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))
@ -1511,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":
@ -1675,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'''