← Back to team overview

curtin-dev team mailing list archive

[Merge] ~dbungert/curtin:cryptoswap-dm-name into curtin:master

 

Dan Bungert has proposed merging ~dbungert/curtin:cryptoswap-dm-name into curtin:master.

Commit message:
block_meta: fix fstab path to cryptoswap

Curtin has this system by which it looks for the most robust path to the
device.  Sadly, the existing mechanism fails for cryptoswap.

At install time, this device shows up with an ID that looks like
CRYPT-LUKS2 and insted ends up with CRYPT-PLAIN but the underlying
device remains luks (has the header).

This change appears to not affect other cases like LVM on LUKS, based on
regression testing of the existing Subiquity LVM+LUKS guided install
type.

I believe the name appropriate as a selection mechanism because we
already know it needs to be unique.



Requested reviews:
  curtin developers (curtin-dev)

For more details, see:
https://code.launchpad.net/~dbungert/curtin/+git/curtin/+merge/460156
-- 
Your team curtin developers is requested to review the proposed merge of ~dbungert/curtin:cryptoswap-dm-name into curtin:master.
diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
index 8ba7a55..4291b00 100644
--- a/curtin/commands/block_meta.py
+++ b/curtin/commands/block_meta.py
@@ -1309,9 +1309,12 @@ def get_volume_spec(device_path):
     if 'raid' in block_type or device_path.startswith('/dev/md'):
         devlinks = [link for link in info['DEVLINKS']
                     if os.path.basename(link).startswith('md-uuid-')]
-    elif block_type in ['crypt', 'lvm', 'mpath']:
+    elif block_type in ['lvm', 'mpath']:
         devlinks = [link for link in info['DEVLINKS']
                     if os.path.basename(link).startswith('dm-uuid-')]
+    elif block_type in ['crypt']:
+        devlinks = [link for link in info['DEVLINKS']
+                    if link.startswith('/dev/disk/by-id/dm-name-')]
     elif block_type in ['disk', 'part']:
         if device_path.startswith('/dev/bcache'):
             devlinks = [link for link in info['DEVLINKS']
diff --git a/tests/unittests/test_commands_block_meta.py b/tests/unittests/test_commands_block_meta.py
index 5adb46c..bc17f9a 100644
--- a/tests/unittests/test_commands_block_meta.py
+++ b/tests/unittests/test_commands_block_meta.py
@@ -1436,7 +1436,7 @@ class TestFstabVolumeSpec(CiTestCase):
                    '/dev/bcache/by-uuid/f36394c0-3cc0-4423-8d6f-ffac130f171a'],
         'crypt': [
             "/dev/disk/by-uuid/bf243cf7-5e45-4d38-b00d-3d35df616ac0",
-            "/dev/disk/by-id/dm-name-dmcrypt0 /dev/mapper/dmcrypt0",
+            "/dev/disk/by-id/dm-name-dmcrypt0", "/dev/mapper/dmcrypt0",
             ("/dev/disk/by-id/"
              "dm-uuid-CRYPT-LUKS2-344580c161864ba59712bd84df3e86ba-dmcrypt0")],
         'lvm': [
@@ -1522,25 +1522,21 @@ class TestFstabVolumeSpec(CiTestCase):
         self.m_info.return_value = {'DEVLINKS': DEVLINKS}
         self.assertEqual(device, block_meta.get_volume_spec(device))
 
-    def test_crypt_uses_dm_uuid_devlink(self):
+    def test_crypt_uses_dm_name_devlink(self):
         block_type = 'crypt'
-        dm_uuid = (
-            "/dev/disk/by-id/"
-            "dm-uuid-CRYPT-LUKS2-344580c161864ba59712bd84df3e86ba-dmcrypt0")
+        dm_name = "/dev/disk/by-id/dm-name-dmcrypt0"
         device = self.random_string()
         DEVLINKS = copy.deepcopy(self.DEVLINK_MAP[block_type])
         self.m_vtype.return_value = block_type
         self.m_info.return_value = {'DEVLINKS': DEVLINKS}
-        self.assertEqual(dm_uuid, block_meta.get_volume_spec(device))
+        self.assertEqual(dm_name, block_meta.get_volume_spec(device))
 
-    def test_crypt_device_uses_devname_if_no_dm_uuid_link(self):
+    def test_crypt_device_uses_devname_if_no_dm_name_link(self):
         block_type = 'crypt'
-        dm_uuid = (
-            "/dev/disk/by-id/"
-            "dm-uuid-CRYPT-LUKS2-344580c161864ba59712bd84df3e86ba-dmcrypt0")
+        dm_name = "/dev/disk/by-id/dm-name-dmcrypt0"
         device = self.random_string()
         DEVLINKS = copy.deepcopy(self.DEVLINK_MAP[block_type])
-        DEVLINKS.remove(dm_uuid)
+        DEVLINKS.remove(dm_name)
         self.m_vtype.return_value = block_type
         self.m_info.return_value = {'DEVLINKS': DEVLINKS}
         self.assertEqual(device, block_meta.get_volume_spec(device))

Follow ups