[blivet:f21-branch 03/14] Be more robust in the face of possible changes to mdadm's UUIDs.
mulhern
amulhern at redhat.com
Mon Sep 29 17:22:50 UTC 2014
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devicelibs/mdraid.py | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index 5bb6226..aaf4567 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -21,6 +21,7 @@
#
import os
+import re
import uuid
from .. import util
@@ -237,6 +238,24 @@ def canonicalize_UUID(a_uuid):
"""
return str(uuid.UUID(a_uuid.replace(':', '')))
+def process_UUIDS(info, UUID_keys):
+ """ Extract and convert expected UUIDs to canonical form.
+ Reassign canonicalized UUIDs to corresponding keys.
+
+ :param dict info: a dictionary of key/value pairs
+ :param tuple UUID_keys: a list of keys known to be UUIDs
+ """
+ for k, v in ((k, info[k]) for k in UUID_keys if k in info):
+ try:
+ # extract mdadm UUID, e.g., '3386ff85:f5012621:4a435f06:1eb47236'
+ the_uuid = re.match(r"(([a-f0-9]){8}:){3}([a-f0-9]){8}", v)
+
+ info[k] = canonicalize_UUID(the_uuid.group())
+ except (ValueError, AttributeError) as e:
+ # the unlikely event that mdadm's UUIDs change their format
+ log.warning('uuid value %s could not be canonicalized: %s', v, e)
+ info[k] = v # record the value, since mdadm provided something
+
def mdexamine(device):
""" Run mdadm --examine to obtain information about an array member.
@@ -270,8 +289,7 @@ def mdexamine(device):
if name == "metadata":
info["MD_METADATA"] = value
- for k, v in ((k,v) for (k,v) in info.iteritems() if k.endswith("UUID")):
- info[k] = canonicalize_UUID(v)
+ process_UUIDS(info, ('MD_UUID', 'MD_DEV_UUID'))
return info
--
1.9.3
More information about the anaconda-patches
mailing list