From f29ee64f76e353757e1db7a6501e29e65d953c95 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 1 Apr 2019 20:46:46 +1300 Subject: [PATCH] Relax constraints on what can be deleted slightly Allow a compound device (i.e. VG or raid) to be deleted if none of its partitions are mounted or part of another device. This makes it a lot easier to remove existing devices that probing for existing partitions / compound devices can find. --- subiquity/models/filesystem.py | 48 ++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index bf7d3297..e897a7d3 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -356,6 +356,35 @@ class _Device(_Formattable, ABC): return True return False + @property + def _can_DELETE(self): + mounted_partitions = 0 + for p in self._partitions: + if p.fs() and p.fs().mount(): + mounted_partitions += 1 + elif p.constructed_device(): + cd = p.constructed_device() + return _( + "Cannot delete {selflabel} as partition {partnum} is part " + "of the {cdtype} {cdname}.").format( + selflabel=self.label, + partnum=p._number, + cdtype=cd.desc(), + cdname=cd.label, + ) + if mounted_partitions > 1: + return _( + "Cannot delete {selflabel} because it has {count} mounted " + "partitions.").format( + selflabel=self.label, + count=mounted_partitions) + elif mounted_partitions == 1: + return _( + "Cannot delete {selflabel} because it has 1 mounted partition." + ).format(selflabel=self.label) + else: + return _generic_can_DELETE(self) + @attr.s(cmp=False) class Disk(_Device): @@ -574,15 +603,6 @@ class Raid(_Device): self._constructed_device is None) _can_REMOVE = property(_generic_can_REMOVE) - @property - def _can_DELETE(self): - if len(self._partitions) > 0: - return _( - "Cannot delete {selflabel} because it has partitions.").format( - selflabel=self.label) - else: - return _generic_can_DELETE(self) - @property def ok_for_raid(self): if self._fs is not None: @@ -647,16 +667,6 @@ class LVM_VolGroup(_Device): _can_CREATE_LV = Disk._can_PARTITION - @property - def _can_DELETE(self): - if len(self._partitions) > 0: - return _( - "Cannot delete {selflabel} because it has logical " - "volumes.").format( - selflabel=self.label) - else: - return _generic_can_DELETE(self) - ok_for_raid = False ok_for_lvm_vg = False