[blivet:all] Give mdadm format uuids to the outside world (#1155151)
Vratislav Podzimek
vpodzime at redhat.com
Thu Oct 23 07:22:34 UTC 2014
On Wed, 2014-10-22 at 13:43 -0400, mulhern wrote:
> Resolves: rhbz#1155151
>
> We need our uuids obtained from mdadm to be the canonical format internally,
> as we need to compare them to other UUIDs obtained from other sources,
> which are in canonical form.
>
> But the outside world needs to see mdadm's own format UUIDs.
>
> Hence, we need a conversion function to convert from canonical UUIDs to
> mdadm format UUIDs, and we need to invoke that function in the correct
> places.
>
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
> blivet/devicelibs/mdraid.py | 28 ++++++++++++++++++++++++++++
> blivet/devices.py | 11 ++++++-----
> tests/devicelibs_test/mdraid_test.py | 6 +++++-
> 3 files changed, 39 insertions(+), 6 deletions(-)
>
> diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
> index f4ed875..29579ae 100644
> --- a/blivet/devicelibs/mdraid.py
> +++ b/blivet/devicelibs/mdraid.py
> @@ -22,6 +22,7 @@
>
> import os
> import re
> +import string
>
> from .. import util
> from ..errors import MDRaidError
> @@ -360,3 +361,30 @@ def name_from_md_node(node):
>
> log.debug("returning %s", name)
> return name
> +
> +def mduuid_from_canonical(a_uuid):
> + """ Change a canonicalized uuid to mdadm's preferred format.
> +
> + :param str a_uuid: a string representing a UUID.
> +
> + :returns: a UUID in mdadm's preferred format
> + :rtype: str
> +
> + mdadm's UUIDs are actual 128 bit uuids, but it formats them strangely.
> + This converts a uuid from canonical form to mdadm's form.
> + Example:
> + mdadm UUID: '3386ff85:f5012621:4a435f06:1eb47236'
> + canonical UUID: '3386ff85-f501-2621-4a43-5f061eb47236'
> + """
> + NUM_DIGITS = 32
> + a_uuid = a_uuid.replace('-', '')
> +
> + if len(a_uuid) != NUM_DIGITS:
> + raise MDRaidError("Missing digits in stripped UUID %s." % a_uuid)
> +
> + if any(c not in string.hexdigits for c in a_uuid):
> + raise MDRaidError("Non-hex digits in stripped UUID %s." % a_uuid)
> +
> + CHUNK_LEN = 8
> +
> + return ":".join([a_uuid[n:n+CHUNK_LEN] for n in range(0, NUM_DIGITS, CHUNK_LEN)])
You can drop the square brackets here.
Otherwise it looks good to me, but I agree with Brian that a separate
property doing the conversion would be better.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list