← Back to team overview

curtin-dev team mailing list archive

[Merge] ~mwhudson/curtin:convert-imsm into curtin:master

 

Michael Hudson-Doyle has proposed merging ~mwhudson/curtin:convert-imsm into curtin:master.

Commit message:
storage_config: properly handle raid containers


Requested reviews:
  curtin developers (curtin-dev)

For more details, see:
https://code.launchpad.net/~mwhudson/curtin/+git/curtin/+merge/404051
-- 
Your team curtin developers is requested to review the proposed merge of ~mwhudson/curtin:convert-imsm into curtin:master.
diff --git a/curtin/storage_config.py b/curtin/storage_config.py
index 81b7385..ebe7bb9 100644
--- a/curtin/storage_config.py
+++ b/curtin/storage_config.py
@@ -164,7 +164,7 @@ def _stype_to_deps(stype):
         'lvm_volgroup': {'devices'},
         'mount': {'device'},
         'partition': {'device'},
-        'raid': {'devices', 'spare_devices'},
+        'raid': {'devices', 'spare_devices', 'container'},
         'zfs': {'pool'},
         'zpool': {'vdevs'},
     }
@@ -212,7 +212,7 @@ def _validate_dep_type(source_id, dep_key, dep_id, sconfig):
         'mount': {'format'},
         'partition': {'bcache', 'disk', 'raid', 'partition'},
         'raid': {'bcache', 'disk', 'dm_crypt', 'lvm_partition',
-                 'partition'},
+                 'partition', 'raid'},
         'zfs': {'zpool'},
         'zpool': {'disk', 'partition'},
     }
@@ -493,8 +493,7 @@ class ProbertParser(object):
                 devtype = 'dmcrypt'
                 name = blockdev['DM_NAME']
         elif devname.startswith('/dev/md'):
-            if 'MD_NAME' in blockdev:
-                devtype = 'raid'
+            devtype = 'raid'
 
         for key, val in {'name': name, 'devtype': devtype}.items():
             if not val or val == 'MISSING':
@@ -1047,16 +1046,25 @@ class RaidParser(ProbertParser):
         # FIXME, need to handle rich md_name values, rather than mdX
         # LP: #1803933
         raidname = os.path.basename(devname)
-        return {'type': 'raid',
-                'id': 'raid-%s' % raidname,
-                'name': raidname,
-                'raidlevel': raid_data.get('raidlevel'),
-                'devices': sorted([
-                    self.blockdev_to_id(self.blockdev_data[dev])
-                    for dev in raid_data.get('devices')]),
-                'spare_devices': sorted([
-                    self.blockdev_to_id(self.blockdev_data[dev])
-                    for dev in raid_data.get('spare_devices')])}
+
+        action = {
+            'type': 'raid',
+            'id': self.blockdev_to_id(raid_data),
+            'name': raidname,
+            'raidlevel': raid_data.get('raidlevel'),
+            }
+
+        if 'container' in raid_data:
+            action['container'] = self.blockdev_byid_to_devname(
+                raid_data['container'])
+        else:
+            action['metadata'] = raid_data.get("MD_METADATA")
+            for k in 'devices', 'spare_devices':
+                action[k] = sorted([
+                    self.blockdev_byid_to_devname(dev)
+                    for dev in raid_data.get(k, [])])
+
+        return action
 
     def parse(self):
         """parse probert 'raid' data format.
diff --git a/tests/unittests/test_storage_config.py b/tests/unittests/test_storage_config.py
index 4c0e272..eb8ff4c 100644
--- a/tests/unittests/test_storage_config.py
+++ b/tests/unittests/test_storage_config.py
@@ -668,6 +668,7 @@ class TestRaidParser(CiTestCase):
             'type': 'raid',
             'id': 'raid-md0',
             'name': 'md0',
+            'metadata': '1.2',
             'raidlevel': 'raid5',
             'devices': ['disk-vde', 'disk-vdf', 'disk-vdg'],
             'spare_devices': [],
@@ -942,7 +943,7 @@ class TestExtractStorageConfig(CiTestCase):
                            cfg['id'].startswith('raid')]
         self.assertEqual(1, len(raids))
         self.assertEqual(1, len(raid_partitions))
-        self.assertEqual({'id': 'raid-md1', 'type': 'raid',
+        self.assertEqual({'id': 'raid-md1', 'type': 'raid', 'metadata': '1.2',
                           'raidlevel': 'raid1', 'name': 'md1',
                           'devices': ['partition-vdb1', 'partition-vdc1'],
                           'spare_devices': []}, raids[0])

Follow ups