Skip to content

Commit

Permalink
Always remove format when removing or formatting a device (#1796710)
Browse files Browse the repository at this point in the history
The device might contain a format unsupported by Blivet so the
type would be None and one extra wipefs call shouldn't be
a problem.
  • Loading branch information
vojtechtrefny committed Jul 31, 2020
1 parent 4a072e1 commit dcb5418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 2 additions & 3 deletions blivetgui/blivet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def delete_device(self, blivet_device, delete_parents):
return result

try:
if blivet_device.format.type and not blivet_device.format_immutable:
if not blivet_device.format_immutable:
ac_fmt = blivet.deviceaction.ActionDestroyFormat(blivet_device)
self.storage.devicetree.actions.add(ac_fmt)
actions.append(ac_fmt)
Expand Down Expand Up @@ -707,8 +707,7 @@ def format_device(self, user_input):

fmt_actions = []

if user_input.edit_device.format.type is not None:
fmt_actions.append(blivet.deviceaction.ActionDestroyFormat(user_input.edit_device))
fmt_actions.append(blivet.deviceaction.ActionDestroyFormat(user_input.edit_device))

if user_input.filesystem:
fmt_actions.extend(self._create_format(user_input, user_input.edit_device))
Expand Down
11 changes: 8 additions & 3 deletions tests/blivetutils_tests/test_10_disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ def test_30_raw_format(self):
actions = self.format_device(device=blivet_disk, fstype=fs)

# check scheduled actions
self.assertEqual(len(actions), 1)
self.assertIsInstance(actions[0], blivet.deviceaction.ActionCreateFormat)
self.assertEqual(len(actions), 2)
self.assertIsInstance(actions[0], blivet.deviceaction.ActionDestroyFormat)
self.assertIsInstance(actions[1], blivet.deviceaction.ActionCreateFormat)

self.assertEqual(actions[0].device, blivet_disk)
self.assertTrue(actions[0].is_create)
self.assertTrue(actions[0].is_destroy)
self.assertTrue(actions[0].is_format)

self.assertEqual(actions[1].device, blivet_disk)
self.assertTrue(actions[1].is_create)
self.assertTrue(actions[1].is_format)

# check that the device has been changed
blivet_disk = self.get_blivet_device(self.vdevs[0])
self.assertEqual(blivet_disk.format.type, fs)
Expand Down

0 comments on commit dcb5418

Please sign in to comment.