Merge ~mwhudson/curtin:lp-1868177 into curtin:master

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: c3800f7bccc9e892224c0dfcfd750adaba7e5eb9
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~mwhudson/curtin:lp-1868177
Merge into: curtin:master
Diff against target: 216 lines (+25/-24)
5 files modified
curtin/block/__init__.py (+6/-7)
curtin/block/clear_holders.py (+2/-3)
examples/tests/uefi_basic.yaml (+4/-0)
tests/unittests/test_block.py (+2/-2)
tests/unittests/test_clear_holders.py (+11/-12)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
curtin developers Pending
Review via email: mp+399893@code.launchpad.net

Commit message

remove 'strict' arguments to block.wipe_volume and block.quick_zero

It was only passed by clear_holders._wipe_superblock and clear_holders
is all best effort anyway.

in particular, this should fix failures seen in subiquity error reports
when wiping very small (<1M) partitions.

LP: #1868177

Description of the change

i haven't tested this beyond running the unittests yet. I guess I should add some more of those too.

To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) wrote :

Definitely should add a less than 1MB partition in one of the vmtests
Comment below, I suggest that we drop the strict=true in clear_holders.py:_wipe_superblock() instead.

~mwhudson/curtin:lp-1868177 updated
bb8b718... by Michael Hudson-Doyle

remove strict argument to block.wipe_volume

It was only passed by clear_holders._wipe_superblock and clear_holders
is all best effort anyway.

in particular, this should fix failures seen in subiquity error reports
when wiping very small (<1M) partitions.

LP: #1868177

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Yes, that seems completely fair. Take another look?

~mwhudson/curtin:lp-1868177 updated
62bf639... by Michael Hudson-Doyle

remove strict argument from quick_zero too

c3800f7... by Michael Hudson-Doyle

add a tiny partition to a randomly selected vmtest

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Confirmed that the vmtest change makes a vmtest fail without the fix that passes with it

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

arm64 failure is that odd pylint race

Revision history for this message
Ryan Harper (raharper) wrote :

I think this is fine. I _was_ thinking to only remove the strict=True default in _wipe_superblock in clear-holders. However no where else is code calling with strict=true; if *something* external were using wipe_superblock and strict=true, so this is the minimal change I think:

(here's me wanting github style markdown in comments)
```
(crispyboi) curtin % git diff
diff --git a/curtin/block/clear_holders.py b/curtin/block/clear_holders.py
index c182d91a..ba026574 100644
--- a/curtin/block/clear_holders.py
+++ b/curtin/block/clear_holders.py
@@ -332,7 +332,7 @@ def wipe_superblock(device):
             time.sleep(wait)

-def _wipe_superblock(blockdev, exclusive=True, strict=True):
+def _wipe_superblock(blockdev, exclusive=True):
     """ No checks, just call wipe_volume """

     retries = [1, 3, 5, 7]
@@ -341,8 +341,7 @@ def _wipe_superblock(blockdev, exclusive=True, strict=True):
         LOG.debug('wiping %s attempt %s/%s',
                   blockdev, attempt + 1, len(retries))
         try:
- block.wipe_volume(blockdev, mode='superblock',
- exclusive=exclusive, strict=strict)
+ block.wipe_volume(blockdev, mode='superblock', exclusive=exclusive)
             LOG.debug('successfully wiped device %s on attempt %s/%s',
                       blockdev, attempt + 1, len(retries))
             return
```

So, I'll approve and leave it up to you if you want to do the minimal or the full removal that you have.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Are there any users of curtin-as-a-library beyond maas and subiquity? I'm not aware of any and if this change shakes any out of the tree I'd be interested to talk to them :)

Revision history for this message
Server Team CI bot (server-team-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/block/__init__.py b/curtin/block/__init__.py
2index 1b33002..2580a0d 100644
3--- a/curtin/block/__init__.py
4+++ b/curtin/block/__init__.py
5@@ -1203,7 +1203,7 @@ def wipe_file(path, reader=None, buflen=4 * 1024 * 1024, exclusive=True):
6 fp.write(pbuf)
7
8
9-def quick_zero(path, partitions=True, exclusive=True, strict=False):
10+def quick_zero(path, partitions=True, exclusive=True):
11 """
12 zero 1M at front, 1M at end, and 1M at front
13 if this is a block device and partitions is true, then
14@@ -1227,11 +1227,11 @@ def quick_zero(path, partitions=True, exclusive=True, strict=False):
15 for (pt, kname, ptnum) in pt_names:
16 LOG.debug('Wiping path: dev:%s kname:%s partnum:%s',
17 pt, kname, ptnum)
18- quick_zero(pt, partitions=False, strict=strict)
19+ quick_zero(pt, partitions=False)
20
21 LOG.debug("wiping 1M on %s at offsets %s", path, offsets)
22 return zero_file_at_offsets(path, offsets, buflen=buflen, count=count,
23- exclusive=exclusive, strict=strict)
24+ exclusive=exclusive)
25
26
27 def zero_file_at_offsets(path, offsets, buflen=1024, count=1024, strict=False,
28@@ -1286,7 +1286,7 @@ def zero_file_at_offsets(path, offsets, buflen=1024, count=1024, strict=False,
29 fp.write(buf)
30
31
32-def wipe_volume(path, mode="superblock", exclusive=True, strict=False):
33+def wipe_volume(path, mode="superblock", exclusive=True):
34 """wipe a volume/block device
35
36 :param path: a path to a block device
37@@ -1299,7 +1299,6 @@ def wipe_volume(path, mode="superblock", exclusive=True, strict=False):
38 volume and beginning and end of any partitions that are
39 known to be on this device.
40 :param exclusive: boolean to control how path is opened
41- :param strict: boolean to control when to raise errors on write failures
42 """
43 if mode == "pvremove":
44 # We need to use --force --force in case it's already in a volgroup and
45@@ -1317,9 +1316,9 @@ def wipe_volume(path, mode="superblock", exclusive=True, strict=False):
46 with open("/dev/urandom", "rb") as reader:
47 wipe_file(path, reader=reader.read, exclusive=exclusive)
48 elif mode == "superblock":
49- quick_zero(path, partitions=False, exclusive=exclusive, strict=strict)
50+ quick_zero(path, partitions=False, exclusive=exclusive)
51 elif mode == "superblock-recursive":
52- quick_zero(path, partitions=True, exclusive=exclusive, strict=strict)
53+ quick_zero(path, partitions=True, exclusive=exclusive)
54 else:
55 raise ValueError("wipe mode %s not supported" % mode)
56
57diff --git a/curtin/block/clear_holders.py b/curtin/block/clear_holders.py
58index c182d91..ba02657 100644
59--- a/curtin/block/clear_holders.py
60+++ b/curtin/block/clear_holders.py
61@@ -332,7 +332,7 @@ def wipe_superblock(device):
62 time.sleep(wait)
63
64
65-def _wipe_superblock(blockdev, exclusive=True, strict=True):
66+def _wipe_superblock(blockdev, exclusive=True):
67 """ No checks, just call wipe_volume """
68
69 retries = [1, 3, 5, 7]
70@@ -341,8 +341,7 @@ def _wipe_superblock(blockdev, exclusive=True, strict=True):
71 LOG.debug('wiping %s attempt %s/%s',
72 blockdev, attempt + 1, len(retries))
73 try:
74- block.wipe_volume(blockdev, mode='superblock',
75- exclusive=exclusive, strict=strict)
76+ block.wipe_volume(blockdev, mode='superblock', exclusive=exclusive)
77 LOG.debug('successfully wiped device %s on attempt %s/%s',
78 blockdev, attempt + 1, len(retries))
79 return
80diff --git a/examples/tests/uefi_basic.yaml b/examples/tests/uefi_basic.yaml
81index 1f49fa9..91a72ae 100644
82--- a/examples/tests/uefi_basic.yaml
83+++ b/examples/tests/uefi_basic.yaml
84@@ -1,6 +1,10 @@
85 showtrace: true
86
87 early_commands:
88+ # Create a small (512KiB) partition to test the fix for LP: #1868177.
89+ tinypartition: [
90+ "parted", /dev/disk/by-id/virtio-disk-a, "--script", "mklabel", "gpt",
91+ "mkpart", "primary", "4096s", "4096s", "5120s"]
92 # Recreate and test LP:1722322
93 # Make one disk dirty with an MBR and a storage configuration
94 # GPT and don't supply wipe: superblock. This will exercise
95diff --git a/tests/unittests/test_block.py b/tests/unittests/test_block.py
96index d96a4a8..519628a 100644
97--- a/tests/unittests/test_block.py
98+++ b/tests/unittests/test_block.py
99@@ -409,11 +409,11 @@ class TestWipeVolume(CiTestCase):
100 def test_wipe_superblock(self, mock_quick_zero):
101 block.wipe_volume(self.dev, mode='superblock')
102 mock_quick_zero.assert_called_with(self.dev, exclusive=True,
103- partitions=False, strict=False)
104+ partitions=False)
105 block.wipe_volume(self.dev, exclusive=True,
106 mode='superblock-recursive')
107 mock_quick_zero.assert_called_with(self.dev, exclusive=True,
108- partitions=True, strict=False)
109+ partitions=True)
110
111 @mock.patch('curtin.block.wipe_file')
112 def test_wipe_zero(self, mock_wipe_file):
113diff --git a/tests/unittests/test_clear_holders.py b/tests/unittests/test_clear_holders.py
114index d1c2590..48697b5 100644
115--- a/tests/unittests/test_clear_holders.py
116+++ b/tests/unittests/test_clear_holders.py
117@@ -142,8 +142,7 @@ class TestClearHolders(CiTestCase):
118 # 1. wipe the bcache device contents
119 m_block.wipe_volume.assert_called_with(self.test_blockdev,
120 mode='superblock',
121- exclusive=False,
122- strict=True)
123+ exclusive=False)
124 # 2. extract the backing device
125 m_bcache.get_backing_device.assert_called_with(self.test_blockdev)
126 m_bcache.sysfs_path.assert_has_calls([
127@@ -243,7 +242,7 @@ class TestClearHolders(CiTestCase):
128 clear_holders.shutdown_mdadm(self.test_syspath)
129
130 mock_wipe.assert_called_with(self.test_blockdev, exclusive=False,
131- mode='superblock', strict=True)
132+ mode='superblock')
133 mock_mdadm.set_sync_action.assert_has_calls([
134 mock.call(self.test_blockdev, action="idle"),
135 mock.call(self.test_blockdev, action="frozen")])
136@@ -281,7 +280,7 @@ class TestClearHolders(CiTestCase):
137 clear_holders.shutdown_mdadm(self.test_syspath)
138
139 mock_wipe.assert_called_with(self.test_blockdev, exclusive=False,
140- mode='superblock', strict=True)
141+ mode='superblock')
142 mock_mdadm.set_sync_action.assert_has_calls([
143 mock.call(self.test_blockdev, action="idle"),
144 mock.call(self.test_blockdev, action="frozen")])
145@@ -363,7 +362,7 @@ class TestClearHolders(CiTestCase):
146 clear_holders.wipe_superblock(self.test_syspath)
147 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
148 mock_block.wipe_volume.assert_called_with(
149- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
150+ self.test_blockdev, exclusive=True, mode='superblock')
151
152 @mock.patch('curtin.block.clear_holders.multipath')
153 @mock.patch('curtin.block.clear_holders.is_swap_device')
154@@ -391,7 +390,7 @@ class TestClearHolders(CiTestCase):
155 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
156 mock_zfs.zpool_export.assert_called_with('fake_pool')
157 mock_block.wipe_volume.assert_called_with(
158- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
159+ self.test_blockdev, exclusive=True, mode='superblock')
160
161 @mock.patch('curtin.block.clear_holders.multipath')
162 @mock.patch('curtin.block.clear_holders.is_swap_device')
163@@ -420,7 +419,7 @@ class TestClearHolders(CiTestCase):
164 self.assertEqual(0, mock_zfs.device_to_poolname.call_count)
165 self.assertEqual(0, mock_zfs.zpool_list.call_count)
166 mock_block.wipe_volume.assert_called_with(
167- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
168+ self.test_blockdev, exclusive=True, mode='superblock')
169
170 @mock.patch('curtin.block.clear_holders.udev')
171 @mock.patch('curtin.block.clear_holders.multipath')
172@@ -454,7 +453,7 @@ class TestClearHolders(CiTestCase):
173 clear_holders.wipe_superblock(self.test_syspath)
174 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
175 mock_block.wipe_volume.assert_called_with(
176- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
177+ self.test_blockdev, exclusive=True, mode='superblock')
178
179 @mock.patch('curtin.block.clear_holders.multipath')
180 @mock.patch('curtin.block.clear_holders.is_swap_device')
181@@ -482,7 +481,7 @@ class TestClearHolders(CiTestCase):
182 clear_holders.wipe_superblock(self.test_syspath)
183 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
184 mock_block.wipe_volume.assert_called_with(
185- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
186+ self.test_blockdev, exclusive=True, mode='superblock')
187 mock_block.get_sysfs_partitions.assert_has_calls(
188 [mock.call(self.test_syspath)] * 3)
189 mock_block.rescan_block_devices.assert_has_calls(
190@@ -515,7 +514,7 @@ class TestClearHolders(CiTestCase):
191 clear_holders.wipe_superblock(self.test_syspath)
192 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
193 mock_block.wipe_volume.assert_called_with(
194- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
195+ self.test_blockdev, exclusive=True, mode='superblock')
196 mock_block.get_sysfs_partitions.assert_has_calls(
197 [mock.call(self.test_syspath)] * 3)
198 mock_block.rescan_block_devices.assert_has_calls(
199@@ -577,7 +576,7 @@ class TestClearHolders(CiTestCase):
200 clear_holders.wipe_superblock(self.test_syspath)
201 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
202 mock_block.wipe_volume.assert_called_with(
203- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
204+ self.test_blockdev, exclusive=True, mode='superblock')
205
206 @mock.patch('curtin.block.clear_holders.zfs')
207 @mock.patch('curtin.block.clear_holders.get_holders')
208@@ -614,7 +613,7 @@ class TestClearHolders(CiTestCase):
209 mock_block.sysfs_to_devpath.assert_called_with(self.test_syspath)
210 mock_mpath.remove_partition.assert_called_with('mpatha-part1')
211 mock_block.wipe_volume.assert_called_with(
212- self.test_blockdev, exclusive=True, mode='superblock', strict=True)
213+ self.test_blockdev, exclusive=True, mode='superblock')
214
215 @mock.patch('curtin.block.clear_holders.LOG')
216 @mock.patch('curtin.block.clear_holders.block')

Subscribers

People subscribed via source and target branches