From 60841784010c07dd154eaab41441a017a6311ef4 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 25 Jul 2019 14:31:39 +1200 Subject: [PATCH] fixes for editing existing ESPs for https://bugs.launchpad.net/subiquity/+bug/1837820 --- subiquity/ui/views/filesystem/partition.py | 13 ++++- .../views/filesystem/tests/test_partition.py | 51 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/subiquity/ui/views/filesystem/partition.py b/subiquity/ui/views/filesystem/partition.py index 546bd74f2..e4fcc1b3f 100644 --- a/subiquity/ui/views/filesystem/partition.py +++ b/subiquity/ui/views/filesystem/partition.py @@ -345,6 +345,11 @@ def __init__(self, parent, disk, partition=None): if partition.flag != "boot": initial.update(initial_data_for_fs(self.partition.fs())) + else: + if partition.fs() and partition.fs().mount(): + initial['mount'] = '/boot/efi' + else: + initial['mount'] = None if isinstance(disk, LVM_VolGroup): initial['name'] = partition.name lvm_names.remove(partition.name) @@ -465,8 +470,12 @@ def done(self, form): log.debug("Add Partition Result: {}".format(form.as_data())) data = form.as_data() if self.partition is not None and self.partition.flag == "boot": - data['fstype'] = self.partition.fs().fstype - data['mount'] = self.partition.fs().mount().path + if self.partition.original_fs() is None: + data['fstype'] = self.partition.fs().fstype + if self.partition.fs().mount() is not None: + data['mount'] = self.partition.fs().mount().path + else: + data['mount'] = None if isinstance(self.disk, LVM_VolGroup): handler = self.controller.logical_volume_handler else: diff --git a/subiquity/ui/views/filesystem/tests/test_partition.py b/subiquity/ui/views/filesystem/tests/test_partition.py index 8ea8d1a32..b44936c9c 100644 --- a/subiquity/ui/views/filesystem/tests/test_partition.py +++ b/subiquity/ui/views/filesystem/tests/test_partition.py @@ -170,6 +170,12 @@ def test_edit_boot_partition(self): fs = model.add_filesystem(partition, "fat32") model.add_mount(fs, '/boot/efi') view, stretchy = make_partition_view(model, disk, partition) + + self.assertFalse(stretchy.form.fstype.enabled) + self.assertEqual(stretchy.form.fstype.value, "fat32") + self.assertFalse(stretchy.form.mount.enabled) + self.assertEqual(stretchy.form.mount.value, "/boot/efi") + view_helpers.enter_data(stretchy.form, form_data) view_helpers.click(stretchy.form.done_btn.base_widget) expected_data = { @@ -181,6 +187,51 @@ def test_edit_boot_partition(self): view.controller.partition_disk_handler.assert_called_once_with( stretchy.disk, stretchy.partition, expected_data) + def test_edit_existing_unused_boot_partition(self): + model, disk = make_model_and_disk() + partition = model.add_partition(disk, 512*(2**20), "boot") + fs = model.add_filesystem(partition, "fat32") + partition._original_fs = fs + disk.preserve = partition.preserve = fs.preserve = True + view, stretchy = make_partition_view(model, disk, partition) + + self.assertTrue(stretchy.form.fstype.enabled) + self.assertEqual(stretchy.form.fstype.value, None) + self.assertFalse(stretchy.form.mount.enabled) + self.assertEqual(stretchy.form.mount.value, None) + + view_helpers.click(stretchy.form.done_btn.base_widget) + expected_data = { + 'fstype': None, + 'mount': None, + 'use_swap': False, + } + view.controller.partition_disk_handler.assert_called_once_with( + stretchy.disk, stretchy.partition, expected_data) + + def test_edit_existing_used_boot_partition(self): + model, disk = make_model_and_disk() + partition = model.add_partition(disk, 512*(2**20), "boot") + fs = model.add_filesystem(partition, "fat32") + partition._original_fs = fs + disk.preserve = partition.preserve = fs.preserve = True + model.add_mount(fs, '/boot/efi') + view, stretchy = make_partition_view(model, disk, partition) + + self.assertTrue(stretchy.form.fstype.enabled) + self.assertEqual(stretchy.form.fstype.value, None) + self.assertFalse(stretchy.form.mount.enabled) + self.assertEqual(stretchy.form.mount.value, '/boot/efi') + + view_helpers.click(stretchy.form.done_btn.base_widget) + expected_data = { + 'fstype': None, + 'mount': '/boot/efi', + 'use_swap': False, + } + view.controller.partition_disk_handler.assert_called_once_with( + stretchy.disk, stretchy.partition, expected_data) + def test_format_entire_unusual_filesystem(self): model, disk = make_model_and_disk() fs = model.add_filesystem(disk, "ntfs")