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 break
log.debug("self.ai_data = %s", self.ai_data) log.debug("self.ai_data = %s", self.ai_data)
if 'layout' in self.ai_data: if 'layout' in self.ai_data:
layout = self.ai_data['layout']
with self.context.child("applying_autoinstall"): with self.context.child("applying_autoinstall"):
meth = getattr( meth = getattr(self, "guided_" + layout['name'])
self, "guided_" + self.ai_data['layout']['name']) disk = self.model.disk_for_match(
disks = self.model.all_disks() self.model.all_disks(),
disks.sort(key=lambda x: x.size) layout.get("match", {'size': 'largest'}))
meth(disks[-1]) meth(disk)
elif 'config' in self.ai_data: elif 'config' in self.ai_data:
with self.context.child("applying_autoinstall"): with self.context.child("applying_autoinstall"):
self.model.apply_autoinstall_config(self.ai_data['config']) self.model.apply_autoinstall_config(self.ai_data['config'])
@ -172,7 +173,7 @@ class FilesystemController(SubiquityController):
for action in self.model._actions: for action in self.model._actions:
if action['id'] == device: if action['id'] == device:
self.model.grub_install_device = action self.model.grub_install_device = action
# Should handle 'swap' here too. self.model.swap = self.ai_data.get('swap')
def start(self): def start(self):
self._start_task = schedule_task(self._start()) self._start_task = schedule_task(self._start())

View File

@ -1270,6 +1270,7 @@ class FilesystemModel(object):
self._orig_config = [] self._orig_config = []
self._actions = [] self._actions = []
self.grub_install_device = None self.grub_install_device = None
self.swap = None
def _make_matchers(self, match): def _make_matchers(self, match):
matchers = [] matchers = []
@ -1301,17 +1302,7 @@ class FilesystemModel(object):
return matchers return matchers
def apply_autoinstall_config(self, ai_config): def disk_for_match(self, disks, match):
disks = self.all_disks()
for action in ai_config:
if action['type'] == 'disk':
disk = None
if 'serial' in action:
disk = self._one(type='disk', serial=action['serial'])
elif 'path' in action:
disk = self._one(type='disk', path=action['path'])
else:
match = action.pop('match', {})
matchers = self._make_matchers(match) matchers = self._make_matchers(match)
candidates = [] candidates = []
for candidate in disks: for candidate in disks:
@ -1323,8 +1314,22 @@ class FilesystemModel(object):
if match.get('size') == 'largest': if match.get('size') == 'largest':
candidates.sort(key=lambda d: d.size, reverse=True) candidates.sort(key=lambda d: d.size, reverse=True)
if candidates: if candidates:
disk = candidates[0] return candidates[0]
return None
def apply_autoinstall_config(self, ai_config):
disks = self.all_disks()
for action in ai_config:
if action['type'] == 'disk':
disk = None
if 'serial' in action:
disk = self._one(type='disk', serial=action['serial'])
elif 'path' in action:
disk = self._one(type='disk', path=action['path'])
else: else:
match = action.pop('match', {})
disk = self.disk_for_match(disks, match)
if disk is None:
action['match'] = match action['match'] = match
if disk is None: if disk is None:
raise Exception("{} matched no disk".format(action)) raise Exception("{} matched no disk".format(action))
@ -1511,8 +1516,8 @@ class FilesystemModel(object):
'config': self._render_actions(), 'config': self._render_actions(),
}, },
} }
if not self._should_add_swapfile(): if self.swap is not None:
config['swap'] = {'size': 0} config['swap'] = self.swap
if self.grub_install_device: if self.grub_install_device:
dev = self.grub_install_device dev = self.grub_install_device
if dev.type == "partition": if dev.type == "partition":
@ -1675,11 +1680,18 @@ class FilesystemModel(object):
raise Exception("%s is already mounted") raise Exception("%s is already mounted")
m = Mount(m=self, device=fs, path=path) m = Mount(m=self, device=fs, path=path)
self._actions.append(m) 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 return m
def remove_mount(self, mount): def remove_mount(self, mount):
_remove_backlinks(mount) _remove_backlinks(mount)
self._actions.remove(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): def needs_bootloader_partition(self):
'''true if no disk have a boot partition, and one is needed''' '''true if no disk have a boot partition, and one is needed'''