Merge ~raharper/curtin:fix/no-by-id-grub-debconf into curtin:master

Proposed by Ryan Harper
Status: Merged
Approved by: Chad Smith
Approved revision: 56361669c20a0002b68390f2b2b8a11e1dd563ad
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/curtin:fix/no-by-id-grub-debconf
Merge into: curtin:master
Diff against target: 36 lines (+14/-0)
2 files modified
curtin/block/__init__.py (+2/-0)
tests/unittests/test_block.py (+12/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+389670@code.launchpad.net

Commit message

block: disk_to_byid_path handle missing /dev/disk/by-id directory

If a system has disks without any persistent indentifier (like serial)
then udev won't create any /dev/disk/by-id symlinks. This can happen
in VMs which do not provide serial numbers by default (e.g. virtio).

If /dev/disk/by-id did not exist then os.listdir on that path would
raise a FileNotFoundException and prevented disk_to_byid_path from
returning None (or the correct path).

This is fixed by checking if the target prefix exists and if not
return an empty dict.

LP: #1876258

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

+1! LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/curtin/block/__init__.py b/curtin/block/__init__.py
index a422264..10b8b9e 100644
--- a/curtin/block/__init__.py
+++ b/curtin/block/__init__.py
@@ -853,6 +853,8 @@ def _get_dev_disk_by_prefix(prefix):
853 '/dev/sda1': '/dev/disk/<prefix>/virtio-aaaa-part1',853 '/dev/sda1': '/dev/disk/<prefix>/virtio-aaaa-part1',
854 }854 }
855 """855 """
856 if not os.path.exists(prefix):
857 return {}
856 return {858 return {
857 os.path.realpath(bypfx): bypfx859 os.path.realpath(bypfx): bypfx
858 for bypfx in [os.path.join(prefix, path)860 for bypfx in [os.path.join(prefix, path)
diff --git a/tests/unittests/test_block.py b/tests/unittests/test_block.py
index c62c153..78e331d 100644
--- a/tests/unittests/test_block.py
+++ b/tests/unittests/test_block.py
@@ -179,6 +179,18 @@ class TestBlock(CiTestCase):
179 byid_path = block.disk_to_byid_path('/dev/sdb')179 byid_path = block.disk_to_byid_path('/dev/sdb')
180 self.assertEqual(mapping.get('/dev/sdb'), byid_path)180 self.assertEqual(mapping.get('/dev/sdb'), byid_path)
181181
182 @mock.patch("curtin.block.os.path.exists")
183 def test__get_dev_disk_by_prefix_returns_empty_dict(self, m_exists):
184 """ _get_disk_by_prefix returns empty dict prefix dir does not exit """
185 m_exists.return_value = False
186 self.assertEqual({}, block._get_dev_disk_by_prefix("/dev/disk/by-id"))
187
188 @mock.patch("curtin.block.os.path.exists")
189 def test_disk_to_byid_returns_none_if_disk_byid_missing(self, m_exists):
190 """ disk_to_byid path returns None if /dev/disk/by-id is missing """
191 m_exists.return_value = False
192 self.assertEqual(None, block.disk_to_byid_path('/dev/sdb'))
193
182194
183class TestSysBlockPath(CiTestCase):195class TestSysBlockPath(CiTestCase):
184 @mock.patch("curtin.block.get_blockdev_for_partition")196 @mock.patch("curtin.block.get_blockdev_for_partition")

Subscribers

People subscribed via source and target branches