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
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-04-16 14:42:14 +0000
3+++ debian/changelog 2015-04-16 19:42:51 +0000
4@@ -1,3 +1,9 @@
5+ubuntu-core-upgrader (0.7.11) UNRELEASED; urgency=medium
6+
7+ * Reformat "other" if fsck is unable to repair it (LP: #1435774).
8+
9+ -- James Hunt <james.hunt@ubuntu.com> Thu, 16 Apr 2015 20:12:43 +0100
10+
11 ubuntu-core-upgrader (0.7.10) vivid; urgency=medium
12
13 * ubuntucoreupgrader/upgrader.py: _cmd_mount(): Don't sync partitions
14
15=== modified file 'ubuntucoreupgrader/tests/test_upgrader.py'
16--- ubuntucoreupgrader/tests/test_upgrader.py 2015-04-16 14:42:14 +0000
17+++ ubuntucoreupgrader/tests/test_upgrader.py 2015-04-16 19:42:51 +0000
18@@ -425,5 +425,61 @@
19
20 shutil.rmtree(cache_dir)
21
22+ @patch('ubuntucoreupgrader.upgrader.get_mount_details')
23+ @patch('ubuntucoreupgrader.upgrader.remount')
24+ @patch('ubuntucoreupgrader.upgrader.mount')
25+ @patch('ubuntucoreupgrader.upgrader.fsck')
26+ @patch('ubuntucoreupgrader.upgrader.mkfs')
27+ @patch('ubuntucoreupgrader.upgrader.unmount')
28+ def test_remount_rootfs_with_good_fsck(self, mock_umount, mock_mkfs,
29+ mock_fsck, mock_mount,
30+ mock_remount, mock_mount_details):
31+ MOCK_FS_TUPLE = ("device", "fstype", "label")
32+ mock_mount_details.return_value = MOCK_FS_TUPLE
33+ mock_fsck.return_value = True
34+
35+ args = ['cmdfile']
36+ options = parse_args(args=args)
37+ commands = make_commands([self.TARFILE])
38+
39+ upgrader = Upgrader(options, commands, [])
40+ upgrader.TIMESTAMP_FILE = '/dev/null'
41+ upgrader.MOUNTPOINT_CMD = "true"
42+ upgrader.remount_rootfs(writable=True)
43+
44+ self.assertTrue(mock_fsck.called)
45+
46+ # fsck succeeded, so mkfs should not be called
47+ self.assertFalse(mock_mkfs.called)
48+
49+ @patch('ubuntucoreupgrader.upgrader.get_mount_details')
50+ @patch('ubuntucoreupgrader.upgrader.remount')
51+ @patch('ubuntucoreupgrader.upgrader.mount')
52+ @patch('ubuntucoreupgrader.upgrader.fsck')
53+ @patch('ubuntucoreupgrader.upgrader.mkfs')
54+ @patch('ubuntucoreupgrader.upgrader.unmount')
55+ def test_remount_rootfs_with_bad_fsck(self, mock_umount, mock_mkfs,
56+ mock_fsck, mock_mount,
57+ mock_remount, mock_mount_details):
58+ MOCK_FS_TUPLE = ("device", "fstype", "label")
59+ mock_mount_details.return_value = MOCK_FS_TUPLE
60+
61+ # arrange for fsck to fail
62+ mock_fsck.return_value = False
63+
64+ args = ['cmdfile']
65+ options = parse_args(args=args)
66+ commands = make_commands([self.TARFILE])
67+
68+ upgrader = Upgrader(options, commands, [])
69+ upgrader.TIMESTAMP_FILE = '/dev/null'
70+ upgrader.MOUNTPOINT_CMD = "true"
71+ upgrader.remount_rootfs(writable=True)
72+
73+ self.assertTrue(mock_fsck.called)
74+
75+ # fsck failed, so "other" should have been reformatted
76+ self.assertTrue(mock_mkfs.called)
77+
78 if __name__ == "__main__":
79 unittest.main()
80
81=== modified file 'ubuntucoreupgrader/upgrader.py'
82--- ubuntucoreupgrader/upgrader.py 2015-04-16 14:42:14 +0000
83+++ ubuntucoreupgrader/upgrader.py 2015-04-16 19:42:51 +0000
84@@ -145,11 +145,10 @@
85 def fsck(device):
86 '''
87 Run fsck(8) on specified device.
88+ Returns True on success, else False.
89 '''
90 assert (os.path.exists(device))
91
92- failed = False
93-
94 cmd = '/sbin/fsck'
95 args = []
96
97@@ -171,23 +170,22 @@
98 ret = proc.wait()
99
100 if ret == 0:
101- return
102+ return True
103
104 stdout, stderr = proc.communicate()
105
106 # fsck's return code 1 means: "Filesystem errors corrected"
107 # (aka a warning - FS is consistent [now]).
108- failed = False if ret == 1 else True
109+ success = True if ret == 1 else False
110
111 log.error('{} returned {} ({}): {}, {}'
112 .format(args,
113 ret,
114- "failed" if failed else "warning",
115+ "failed" if not success else "warning",
116 stdout,
117 stderr))
118
119- if failed:
120- sys.exit(1)
121+ return success
122
123
124 def mkfs(device, fs_type, label):
125@@ -738,15 +736,19 @@
126 target = self.get_mount_target()
127
128 if writable:
129- root, _, _ = get_mount_details(target)
130+ device, fstype, label = get_mount_details(target)
131
132 # ro->rw so need to fsck first.
133 unmount(target)
134
135 # needs to be mounted writable, so check it first!
136- fsck(root)
137+ if not fsck(device):
138+ log.warning('fsck for device {} (fstype {}, label {} failed) '
139+ '- reformatting'
140+ .format(device, fstype, label))
141+ mkfs(device, fstype, label)
142
143- mount(root, target, "rw")
144+ mount(device, target, "rw")
145 else:
146 # rw->ro so no fsck required.
147 remount(target, "ro")

Subscribers

People subscribed via source and target branches

to all changes: