decide whether to let curtin create a swapfile when rendering config

https://bugs.launchpad.net/subiquity/+bug/1927103 reports a regression
where a subiquity-installed system has a swapfile even if a swap
partition has been explicitly configured.

The reason this broke is that previously subiquity tracked whether a
swap file should be allowed or not by keeping track of whether a swap
partition was mounted in add_mount / remove_mount. But since the
client/server split, those methods aren't called in the server process
any more.

Just get rid of all the cleverness and call _should_add_swapfile when
rendering the curtin config.
This commit is contained in:
Michael Hudson-Doyle 2021-05-11 11:02:33 +12:00
parent 541b483fb9
commit 0ecccecee6
2 changed files with 3 additions and 10 deletions

View File

@ -1411,8 +1411,6 @@ class FilesystemModel(object):
self._actions = self._actions_from_config( self._actions = self._actions_from_config(
status.config, status.config,
status.blockdev) status.blockdev)
self.swap = None
self.grub = None
def _make_matchers(self, match): def _make_matchers(self, match):
matchers = [] matchers = []
@ -1684,6 +1682,8 @@ class FilesystemModel(object):
} }
if self.swap is not None: if self.swap is not None:
config['swap'] = self.swap config['swap'] = self.swap
elif not self._should_add_swapfile():
config['swap'] = {'swap': 0}
if self.grub is not None: if self.grub is not None:
config['grub'] = self.grub config['grub'] = self.grub
return config return config
@ -1858,17 +1858,10 @@ class FilesystemModel(object):
raise Exception("%s is already mounted", fs) raise Exception("%s is already mounted", fs)
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):
self._remove(mount) self._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'''

View File

@ -314,7 +314,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
meth(disk) meth(disk)
elif 'config' in self.ai_data: elif 'config' in self.ai_data:
self.model.apply_autoinstall_config(self.ai_data['config']) self.model.apply_autoinstall_config(self.ai_data['config'])
self.model.grub = self.ai_data.get('grub', {}) self.model.grub = self.ai_data.get('grub')
self.model.swap = self.ai_data.get('swap') self.model.swap = self.ai_data.get('swap')
def start(self): def start(self):