mark formatted existing partions as ok_for_{raid,lvm_vg}

as we do not support removing an exisiting format, this is required to
be able to reuse these partitions!
This commit is contained in:
Michael Hudson-Doyle 2019-05-30 10:13:21 +12:00
parent e63204afa9
commit 83574fbc0b
2 changed files with 20 additions and 0 deletions

View File

@ -728,6 +728,8 @@ class Disk(_Device):
@property
def ok_for_raid(self):
if self._fs is not None:
if self._fs.preserve:
return self._fs._mount is None
return False
if self._constructed_device is not None:
return False
@ -811,6 +813,8 @@ class Partition(_Formattable):
if self.flag in ('boot', 'bios_grub', 'prep'):
return False
if self._fs is not None:
if self._fs.preserve:
return self._fs._mount is None
return False
if self._constructed_device is not None:
return False
@ -875,6 +879,8 @@ class Raid(_Device):
@property
def ok_for_raid(self):
if self._fs is not None:
if self._fs.preserve:
return self._fs._mount is None
return False
if self._constructed_device is not None:
return False

View File

@ -229,6 +229,20 @@ class TestFilesystemModel(unittest.TestCase):
dev3 = make_new_device()
make_partition(model, dev3)
self.assertFalse(getattr(dev3, attr))
# Empty existing devices are ok
dev4 = make_new_device()
dev4.preserve = True
self.assertTrue(getattr(dev4, attr))
# A dev with an existing filesystem is ok (there is no
# way to remove the format)
dev5 = make_new_device()
dev5.preserve = True
fs = model.add_filesystem(dev5, 'ext4')
fs.preserve = True
self.assertTrue(dev5.ok_for_raid)
# But a existing, *mounted* filesystem is not.
model.add_mount(fs, '/')
self.assertFalse(dev5.ok_for_raid)
def test_disk_ok_for_xxx(self):
model = make_model()