From dc98c0d0eaf06af42c6f9eb3ee5ade9e237c5f40 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Fri, 30 Sep 2016 13:47:24 +0200 Subject: [PATCH 2/2] Try to search for "RAID Level" in mdadm's output (#1379865) mdadm's API (CLI) is ambiguous and may provide the RAID level as either the "RAID Level" or "Raid Level" item. Since we store these items in a hashtable, let's try to lookup both if the first one fails. Another approach would be to cannonicalize all the items keys when creating the hash table, but that seems like an overkill for one weird quirk. Signed-off-by: Vratislav Podzimek --- src/plugins/mdraid.c | 6 +++++ tests/md_test.py | 9 +++++++ tests/mdadm_fw_RAID_examine/mdadm | 53 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100755 tests/mdadm_fw_RAID_examine/mdadm diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c index abd97da..723b756 100644 --- a/src/plugins/mdraid.c +++ b/src/plugins/mdraid.c @@ -184,8 +184,14 @@ static BDMDExamineData* get_examine_data_from_table (GHashTable *table, gboolean char time_str[20]; data->level = g_strdup ((gchar*) g_hash_table_lookup (table, "Raid Level")); + if (!(data->level)) + /* BUG: mdadm outputs "RAID Level" for some metadata formats (rhbz#1380034) */ + data->level = g_strdup ((gchar*) g_hash_table_lookup (table, "RAID Level")); value = (gchar*) g_hash_table_lookup (table, "Raid Devices"); + if (!value) + /* BUG: mdadm outputs "RAID Devices" for some metadata formats (rhbz#1380034) */ + value = (gchar*) g_hash_table_lookup (table, "RAID Devices"); if (value) data->num_devices = g_ascii_strtoull (value, NULL, 0); else diff --git a/tests/md_test.py b/tests/md_test.py index 6664e44..df90582 100644 --- a/tests/md_test.py +++ b/tests/md_test.py @@ -404,6 +404,15 @@ class FakeMDADMutilTest(unittest.TestCase): self.assertEqual(ex_data.device, "/dev/md/Volume0") + def test_fw_raid_uppercase_examine(self): + """Verify that md_examine works with output using "RAID" instead of "Raid" """ + + with fake_utils("tests/mdadm_fw_RAID_examine"): + ex_data = BlockDev.md_examine("fake_dev") + + self.assertEqual(ex_data.level, "0") + self.assertEqual(ex_data.num_devices, 1) + def test_no_metadata_examine(self): """Verify that md_examine works as expected with no metadata spec""" diff --git a/tests/mdadm_fw_RAID_examine/mdadm b/tests/mdadm_fw_RAID_examine/mdadm new file mode 100755 index 0000000..c939860 --- /dev/null +++ b/tests/mdadm_fw_RAID_examine/mdadm @@ -0,0 +1,53 @@ +#!/bin/bash + +echo "$@"|grep -- "--brief" &>/dev/null +is_brief=$? + +if [ $is_brief -eq 0 ]; then + cat <