curtin-dev team mailing list archive
-
curtin-dev team
-
Mailing list archive
-
Message #00765
[Merge] ~raharper/curtin:fix/no-by-id-grub-debconf into curtin:master
Ryan Harper has proposed merging ~raharper/curtin:fix/no-by-id-grub-debconf into curtin:master.
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
Requested reviews:
curtin developers (curtin-dev): curtin-dev
Related bugs:
Bug #1876258 in curtin: "ubuntu 20.04 pxe installation fails with no such file or directory /dev/disk/by-id exception"
https://bugs.launchpad.net/curtin/+bug/1876258
For more details, see:
https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/389670
--
Your team curtin developers is requested to review the proposed merge of ~raharper/curtin:fix/no-by-id-grub-debconf into curtin:master.
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):
'/dev/sda1': '/dev/disk/<prefix>/virtio-aaaa-part1',
}
"""
+ if not os.path.exists(prefix):
+ return {}
return {
os.path.realpath(bypfx): bypfx
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):
byid_path = block.disk_to_byid_path('/dev/sdb')
self.assertEqual(mapping.get('/dev/sdb'), byid_path)
+ @mock.patch("curtin.block.os.path.exists")
+ def test__get_dev_disk_by_prefix_returns_empty_dict(self, m_exists):
+ """ _get_disk_by_prefix returns empty dict prefix dir does not exit """
+ m_exists.return_value = False
+ self.assertEqual({}, block._get_dev_disk_by_prefix("/dev/disk/by-id"))
+
+ @mock.patch("curtin.block.os.path.exists")
+ def test_disk_to_byid_returns_none_if_disk_byid_missing(self, m_exists):
+ """ disk_to_byid path returns None if /dev/disk/by-id is missing """
+ m_exists.return_value = False
+ self.assertEqual(None, block.disk_to_byid_path('/dev/sdb'))
+
class TestSysBlockPath(CiTestCase):
@mock.patch("curtin.block.get_blockdev_for_partition")
Follow ups