[blivet:master/f21-branch] Catch up with pyudev changes that effect MD_UUID* values (#1147087)
Vratislav Podzimek
vpodzime at redhat.com
Tue Sep 30 19:18:04 UTC 2014
On Mon, 2014-09-29 at 09:03 -0400, mulhern wrote:
> Resolves: fed#1147087
>
> On switching to pyudev, MD_UUID* were obtained, not from mdraid methods, but
> from pyudev methods. Since these did not pass through the mdraid methods,
> they were not canonicalized, leading to uncanonicalized forms being used for
> lookup. Now, they are canonicalized on lookup in blivet.util.py. Since
> the canonicalize_UUID method is shared, it is moved up into blivet.utils.py.
>
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
> blivet/devicelibs/mdraid.py | 19 +------------------
> blivet/udev.py | 5 +++--
> blivet/util.py | 20 ++++++++++++++++++++
> 3 files changed, 24 insertions(+), 20 deletions(-)
>
> diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
> index cb36f32..3dc93da 100644
> --- a/blivet/devicelibs/mdraid.py
> +++ b/blivet/devicelibs/mdraid.py
> @@ -22,7 +22,6 @@
>
> import os
> import re
> -import uuid
>
> from .. import util
> from ..errors import MDRaidError
> @@ -256,22 +255,6 @@ def mddeactivate(device):
> except MDRaidError as msg:
> raise MDRaidError("mddeactivate failed for %s: %s" % (device, msg))
>
> -def canonicalize_UUID(a_uuid):
> - """ Converts uuids to canonical form.
> -
> - :param str a_uuid: the UUID
> -
> - :returns: a canonicalized UUID
> - :rtype: str
> -
> - mdadm's UUIDs are actual 128 bit uuids, but it formats them strangely.
> - This converts the uuids to canonical form.
> - Example:
> - mdadm UUID: '3386ff85:f5012621:4a435f06:1eb47236'
> - canonical UUID: '3386ff85-f501-2621-4a43-5f061eb47236'
> - """
> - 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.
> @@ -284,7 +267,7 @@ def process_UUIDS(info, UUID_keys):
> # 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())
> + info[k] = util.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)
> diff --git a/blivet/udev.py b/blivet/udev.py
> index df587b7..c8ee3db 100644
> --- a/blivet/udev.py
> +++ b/blivet/udev.py
> @@ -349,7 +349,7 @@ def device_get_md_uuid(info):
> # Value for MD_UUID known to be obtained from:
> # * pyudev/libudev
> # * mdraid/mdadm (all numeric metadata versions and container default)
> - return info["MD_UUID"]
> + return util.canonicalize_UUID(info["MD_UUID"])
>
> def device_get_md_container(info):
> """
> @@ -396,7 +396,8 @@ def device_get_md_device_uuid(info):
> # * mdraid/mdadm (only 1.x metadata versions)
> # Value for ID_FS_UUID_SUB known to be obtained from:
> # * pyudev/libudev
> - return info.get('ID_FS_UUID_SUB') or info.get('MD_DEV_UUID')
> + md_device_uuid = info.get('ID_FS_UUID_SUB') or info.get('MD_DEV_UUID')
> + return util.canonicalize_UUID(md_device_uuid) if md_device_uuid else None
>
> def device_get_vg_name(info):
> return info['LVM2_VG_NAME']
> diff --git a/blivet/util.py b/blivet/util.py
> index 28dc125..ad61936 100644
> --- a/blivet/util.py
> +++ b/blivet/util.py
> @@ -8,6 +8,7 @@ import subprocess
> import re
> import sys
> import tempfile
> +import uuid
> from decimal import Decimal
> from contextlib import contextmanager
>
> @@ -362,6 +363,25 @@ class ObjectID(object):
> self.id = self._newid_gen() # pylint: disable=attribute-defined-outside-init
> return self
>
> +def canonicalize_UUID(a_uuid):
> + """ Converts uuids to canonical form.
> +
> + :param str a_uuid: the UUID
> +
> + :returns: a canonicalized UUID
> + :rtype: str
> +
> + mdadm's UUIDs are actual 128 bit uuids, but it formats them strangely.
> + This converts the uuids to canonical form.
> + Example:
> + mdadm UUID: '3386ff85:f5012621:4a435f06:1eb47236'
> + canonical UUID: '3386ff85-f501-2621-4a43-5f061eb47236'
> +
> + If the UUID is already in canonical form, the conversion
> + is equivalent to the identity.
> + """
> + return str(uuid.UUID(a_uuid.replace(':', '')))
> +
> ##
> ## Convenience functions for examples and tests
> ##
Looks good to me.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list