Merge ~ltrager/maas:lp1695229_2.2 into maas:2.2

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: a2fc6337e0c83fa1b98922ec656e53147756b47c
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1695229_2.2
Merge into: maas:2.2
Diff against target: 84 lines (+21/-6)
2 files modified
src/metadataserver/builtin_scripts/badblocks.py (+9/-2)
src/metadataserver/builtin_scripts/tests/test_badblocks.py (+12/-4)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+326704@code.launchpad.net

Commit message

Backport from master: Run badblocks using the physical blocksize of the disk.

By default badblocks always runs using a blocksize of 1024 and uses a 32bit int for the number of blocks it can test. For large disks the number of blocks exceeds the 32bit int limit and causes badblocks to fail. Many large uses use a larger physical blocksize which avoids hitting the 32bit int limit which helps avoid hitting LP:1695229.

To post a comment you must log in.
Revision history for this message
Lee Trager (ltrager) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/metadataserver/builtin_scripts/badblocks.py b/src/metadataserver/builtin_scripts/badblocks.py
index eba78ed..46e9111 100644
--- a/src/metadataserver/builtin_scripts/badblocks.py
+++ b/src/metadataserver/builtin_scripts/badblocks.py
@@ -48,10 +48,17 @@ class RunBadBlocks(Thread):
48 self.returncode = None48 self.returncode = None
4949
50 def run(self):50 def run(self):
51 blocksize = check_output(
52 ['sudo', '-n', 'blockdev', '--getbsz', self.drive['PATH']],
53 timeout=TIMEOUT, stderr=DEVNULL).strip()
51 if self.destructive:54 if self.destructive:
52 cmd = ['sudo', '-n', 'badblocks', '-v', '-w', self.drive['PATH']]55 cmd = [
56 'sudo', '-n', 'badblocks', '-b', blocksize, '-v', '-w',
57 self.drive['PATH']]
53 else:58 else:
54 cmd = ['sudo', '-n', 'badblocks', '-v', '-n', self.drive['PATH']]59 cmd = [
60 'sudo', '-n', 'badblocks', '-b', blocksize, '-v', '-n',
61 self.drive['PATH']]
55 # Run badblocks and capture its output. Once all threads have completed62 # Run badblocks and capture its output. Once all threads have completed
56 # output the results serially so output is proerly grouped.63 # output the results serially so output is proerly grouped.
57 with Popen(cmd, stdout=PIPE, stderr=STDOUT) as proc:64 with Popen(cmd, stdout=PIPE, stderr=STDOUT) as proc:
diff --git a/src/metadataserver/builtin_scripts/tests/test_badblocks.py b/src/metadataserver/builtin_scripts/tests/test_badblocks.py
index 6e08dde..6b3c922 100644
--- a/src/metadataserver/builtin_scripts/tests/test_badblocks.py
+++ b/src/metadataserver/builtin_scripts/tests/test_badblocks.py
@@ -127,6 +127,7 @@ class TestSmartCTL(MAASTestCase):
127 drive = self.make_drive(with_path=True)127 drive = self.make_drive(with_path=True)
128 run_bad_blocks = badblocks.RunBadBlocks(drive, True)128 run_bad_blocks = badblocks.RunBadBlocks(drive, True)
129 output = factory.make_string()129 output = factory.make_string()
130 self.patch(badblocks, 'check_output').return_value = '4096'
130 mock_popen = self.patch(badblocks, 'Popen')131 mock_popen = self.patch(badblocks, 'Popen')
131 mock_popen.return_value = Popen(['echo', '-n', output], stdout=PIPE)132 mock_popen.return_value = Popen(['echo', '-n', output], stdout=PIPE)
132133
@@ -137,13 +138,16 @@ class TestSmartCTL(MAASTestCase):
137 self.assertThat(138 self.assertThat(
138 mock_popen,139 mock_popen,
139 MockCalledOnceWith(140 MockCalledOnceWith(
140 ['sudo', '-n', 'badblocks', '-v', '-w', drive['PATH']],141 [
141 stdout=PIPE, stderr=STDOUT))142 'sudo', '-n', 'badblocks', '-b', '4096', '-v', '-w',
143 drive['PATH'],
144 ], stdout=PIPE, stderr=STDOUT))
142145
143 def test_run_nondestructive(self):146 def test_run_nondestructive(self):
144 drive = self.make_drive(with_path=True)147 drive = self.make_drive(with_path=True)
145 run_bad_blocks = badblocks.RunBadBlocks(drive, False)148 run_bad_blocks = badblocks.RunBadBlocks(drive, False)
146 output = factory.make_string()149 output = factory.make_string()
150 self.patch(badblocks, 'check_output').return_value = '4096'
147 mock_popen = self.patch(badblocks, 'Popen')151 mock_popen = self.patch(badblocks, 'Popen')
148 mock_popen.return_value = Popen(['echo', '-n', output], stdout=PIPE)152 mock_popen.return_value = Popen(['echo', '-n', output], stdout=PIPE)
149153
@@ -154,8 +158,10 @@ class TestSmartCTL(MAASTestCase):
154 self.assertThat(158 self.assertThat(
155 mock_popen,159 mock_popen,
156 MockCalledOnceWith(160 MockCalledOnceWith(
157 ['sudo', '-n', 'badblocks', '-v', '-n', drive['PATH']],161 [
158 stdout=PIPE, stderr=STDOUT))162 'sudo', '-n', 'badblocks', '-b', '4096', '-v', '-n',
163 drive['PATH'],
164 ], stdout=PIPE, stderr=STDOUT))
159165
160 def test_run_badblocks(self):166 def test_run_badblocks(self):
161 drive = {167 drive = {
@@ -166,6 +172,7 @@ class TestSmartCTL(MAASTestCase):
166 }172 }
167 self.patch(badblocks, 'list_drives').return_value = [drive]173 self.patch(badblocks, 'list_drives').return_value = [drive]
168 output = factory.make_string()174 output = factory.make_string()
175 self.patch(badblocks, 'check_output').return_value = '4096'
169 mock_popen = self.patch(badblocks, 'Popen')176 mock_popen = self.patch(badblocks, 'Popen')
170 mock_popen.return_value = Popen(['echo', '-n', output], stdout=PIPE)177 mock_popen.return_value = Popen(['echo', '-n', output], stdout=PIPE)
171 mock_print = self.patch(badblocks, 'print')178 mock_print = self.patch(badblocks, 'print')
@@ -192,6 +199,7 @@ class TestSmartCTL(MAASTestCase):
192 }199 }
193 self.patch(badblocks, 'list_drives').return_value = [drive]200 self.patch(badblocks, 'list_drives').return_value = [drive]
194 output = factory.make_string()201 output = factory.make_string()
202 self.patch(badblocks, 'check_output').return_value = '4096'
195 mock_popen = self.patch(badblocks, 'Popen')203 mock_popen = self.patch(badblocks, 'Popen')
196 mock_popen.return_value = Popen(204 mock_popen.return_value = Popen(
197 'echo -n %s; exit 1' % output, stdout=PIPE, shell=True)205 'echo -n %s; exit 1' % output, stdout=PIPE, shell=True)

Subscribers

People subscribed via source and target branches