Merge lp:~jamesodhunt/ubuntu/vivid/ubuntu-core-upgrader/bug-1435774 into lp:ubuntu/vivid/ubuntu-core-upgrader

Proposed by James Hunt
Status: Work in progress
Proposed branch: lp:~jamesodhunt/ubuntu/vivid/ubuntu-core-upgrader/bug-1435774
Merge into: lp:ubuntu/vivid/ubuntu-core-upgrader
Diff against target: 147 lines (+74/-10)
3 files modified
debian/changelog (+6/-0)
ubuntucoreupgrader/tests/test_upgrader.py (+56/-0)
ubuntucoreupgrader/upgrader.py (+12/-10)
To merge this branch: bzr merge lp:~jamesodhunt/ubuntu/vivid/ubuntu-core-upgrader/bug-1435774
Reviewer Review Type Date Requested Status
Timo Jyrinki Needs Resubmitting
Ubuntu branches Pending
Review via email: mp+256562@code.launchpad.net

Description of the change

* Reformat "other" if fsck is unable to repair it (LP: #1435774).

To post a comment you must log in.
Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

This should be resubmitted to xenial if still needed.

review: Needs Resubmitting

Unmerged revisions

30. By James Hunt

Reformat "other" if fsck is unable to repair it (LP: #1435774).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2015-04-16 14:42:14 +0000
+++ debian/changelog 2015-04-16 19:42:51 +0000
@@ -1,3 +1,9 @@
1ubuntu-core-upgrader (0.7.11) UNRELEASED; urgency=medium
2
3 * Reformat "other" if fsck is unable to repair it (LP: #1435774).
4
5 -- James Hunt <james.hunt@ubuntu.com> Thu, 16 Apr 2015 20:12:43 +0100
6
1ubuntu-core-upgrader (0.7.10) vivid; urgency=medium7ubuntu-core-upgrader (0.7.10) vivid; urgency=medium
28
3 * ubuntucoreupgrader/upgrader.py: _cmd_mount(): Don't sync partitions9 * ubuntucoreupgrader/upgrader.py: _cmd_mount(): Don't sync partitions
410
=== modified file 'ubuntucoreupgrader/tests/test_upgrader.py'
--- ubuntucoreupgrader/tests/test_upgrader.py 2015-04-16 14:42:14 +0000
+++ ubuntucoreupgrader/tests/test_upgrader.py 2015-04-16 19:42:51 +0000
@@ -425,5 +425,61 @@
425425
426 shutil.rmtree(cache_dir)426 shutil.rmtree(cache_dir)
427427
428 @patch('ubuntucoreupgrader.upgrader.get_mount_details')
429 @patch('ubuntucoreupgrader.upgrader.remount')
430 @patch('ubuntucoreupgrader.upgrader.mount')
431 @patch('ubuntucoreupgrader.upgrader.fsck')
432 @patch('ubuntucoreupgrader.upgrader.mkfs')
433 @patch('ubuntucoreupgrader.upgrader.unmount')
434 def test_remount_rootfs_with_good_fsck(self, mock_umount, mock_mkfs,
435 mock_fsck, mock_mount,
436 mock_remount, mock_mount_details):
437 MOCK_FS_TUPLE = ("device", "fstype", "label")
438 mock_mount_details.return_value = MOCK_FS_TUPLE
439 mock_fsck.return_value = True
440
441 args = ['cmdfile']
442 options = parse_args(args=args)
443 commands = make_commands([self.TARFILE])
444
445 upgrader = Upgrader(options, commands, [])
446 upgrader.TIMESTAMP_FILE = '/dev/null'
447 upgrader.MOUNTPOINT_CMD = "true"
448 upgrader.remount_rootfs(writable=True)
449
450 self.assertTrue(mock_fsck.called)
451
452 # fsck succeeded, so mkfs should not be called
453 self.assertFalse(mock_mkfs.called)
454
455 @patch('ubuntucoreupgrader.upgrader.get_mount_details')
456 @patch('ubuntucoreupgrader.upgrader.remount')
457 @patch('ubuntucoreupgrader.upgrader.mount')
458 @patch('ubuntucoreupgrader.upgrader.fsck')
459 @patch('ubuntucoreupgrader.upgrader.mkfs')
460 @patch('ubuntucoreupgrader.upgrader.unmount')
461 def test_remount_rootfs_with_bad_fsck(self, mock_umount, mock_mkfs,
462 mock_fsck, mock_mount,
463 mock_remount, mock_mount_details):
464 MOCK_FS_TUPLE = ("device", "fstype", "label")
465 mock_mount_details.return_value = MOCK_FS_TUPLE
466
467 # arrange for fsck to fail
468 mock_fsck.return_value = False
469
470 args = ['cmdfile']
471 options = parse_args(args=args)
472 commands = make_commands([self.TARFILE])
473
474 upgrader = Upgrader(options, commands, [])
475 upgrader.TIMESTAMP_FILE = '/dev/null'
476 upgrader.MOUNTPOINT_CMD = "true"
477 upgrader.remount_rootfs(writable=True)
478
479 self.assertTrue(mock_fsck.called)
480
481 # fsck failed, so "other" should have been reformatted
482 self.assertTrue(mock_mkfs.called)
483
428if __name__ == "__main__":484if __name__ == "__main__":
429 unittest.main()485 unittest.main()
430486
=== modified file 'ubuntucoreupgrader/upgrader.py'
--- ubuntucoreupgrader/upgrader.py 2015-04-16 14:42:14 +0000
+++ ubuntucoreupgrader/upgrader.py 2015-04-16 19:42:51 +0000
@@ -145,11 +145,10 @@
145def fsck(device):145def fsck(device):
146 '''146 '''
147 Run fsck(8) on specified device.147 Run fsck(8) on specified device.
148 Returns True on success, else False.
148 '''149 '''
149 assert (os.path.exists(device))150 assert (os.path.exists(device))
150151
151 failed = False
152
153 cmd = '/sbin/fsck'152 cmd = '/sbin/fsck'
154 args = []153 args = []
155154
@@ -171,23 +170,22 @@
171 ret = proc.wait()170 ret = proc.wait()
172171
173 if ret == 0:172 if ret == 0:
174 return173 return True
175174
176 stdout, stderr = proc.communicate()175 stdout, stderr = proc.communicate()
177176
178 # fsck's return code 1 means: "Filesystem errors corrected"177 # fsck's return code 1 means: "Filesystem errors corrected"
179 # (aka a warning - FS is consistent [now]).178 # (aka a warning - FS is consistent [now]).
180 failed = False if ret == 1 else True179 success = True if ret == 1 else False
181180
182 log.error('{} returned {} ({}): {}, {}'181 log.error('{} returned {} ({}): {}, {}'
183 .format(args,182 .format(args,
184 ret,183 ret,
185 "failed" if failed else "warning",184 "failed" if not success else "warning",
186 stdout,185 stdout,
187 stderr))186 stderr))
188187
189 if failed:188 return success
190 sys.exit(1)
191189
192190
193def mkfs(device, fs_type, label):191def mkfs(device, fs_type, label):
@@ -738,15 +736,19 @@
738 target = self.get_mount_target()736 target = self.get_mount_target()
739737
740 if writable:738 if writable:
741 root, _, _ = get_mount_details(target)739 device, fstype, label = get_mount_details(target)
742740
743 # ro->rw so need to fsck first.741 # ro->rw so need to fsck first.
744 unmount(target)742 unmount(target)
745743
746 # needs to be mounted writable, so check it first!744 # needs to be mounted writable, so check it first!
747 fsck(root)745 if not fsck(device):
746 log.warning('fsck for device {} (fstype {}, label {} failed) '
747 '- reformatting'
748 .format(device, fstype, label))
749 mkfs(device, fstype, label)
748750
749 mount(root, target, "rw")751 mount(device, target, "rw")
750 else:752 else:
751 # rw->ro so no fsck required.753 # rw->ro so no fsck required.
752 remount(target, "ro")754 remount(target, "ro")

Subscribers

People subscribed via source and target branches

to all changes: