From 5d0355abb945dbe304ecab6de923e8b0f7444196 Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Fri, 7 Nov 2014 15:48:42 -0600
Subject: [PATCH 09/51] Store disklabel and partition UUIDs when available.

---
 blivet/devices/partition.py | 5 +++--
 blivet/formats/disklabel.py | 1 +
 blivet/populator.py         | 6 +++++-
 blivet/udev.py              | 6 ++++++
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/blivet/devices/partition.py b/blivet/devices/partition.py
index 4071935..d980479 100644
--- a/blivet/devices/partition.py
+++ b/blivet/devices/partition.py
@@ -60,7 +60,7 @@ class PartitionDevice(StorageDevice):
     _resizable = True
     defaultSize = DEFAULT_PART_SIZE
 
-    def __init__(self, name, fmt=None,
+    def __init__(self, name, fmt=None, uuid=None,
                  size=None, grow=False, maxsize=None, start=None, end=None,
                  major=None, minor=None, bootable=None,
                  sysfsPath='', parents=None, exists=False,
@@ -79,6 +79,7 @@ class PartitionDevice(StorageDevice):
 
             For existing partitions only:
 
+            :keyword str uuid: partition UUID (not filesystem UUID)
             :keyword major: the device major
             :type major: long
             :keyword minor: the device minor
@@ -130,7 +131,7 @@ class PartitionDevice(StorageDevice):
         self._partedPartition = None
         self._origPath = None
 
-        StorageDevice.__init__(self, name, fmt=fmt, size=size,
+        StorageDevice.__init__(self, name, fmt=fmt, uuid=uuid, size=size,
                                major=major, minor=minor, exists=exists,
                                sysfsPath=sysfsPath, parents=parents)
 
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 361b0cf..42f9b4c 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -48,6 +48,7 @@ class DiskLabel(DeviceFormat):
         """
             :keyword device: full path to the block device node
             :type device: str
+            :keyword str uuid: disklabel UUID
             :keyword labelType: type of disklabel to create
             :type labelType: str
             :keyword exists: whether the formatting exists
diff --git a/blivet/populator.py b/blivet/populator.py
index 52263b2..5d9ae39 100644
--- a/blivet/populator.py
+++ b/blivet/populator.py
@@ -392,7 +392,8 @@ class Populator(object):
 
     def addUdevPartitionDevice(self, info, disk=None):
         name = udev.device_get_name(info)
-        log_method_call(self, name=name)
+        uuid = udev.device_get_partition_uuid(info)
+        log_method_call(self, name=name, uuid=uuid)
         sysfs_path = udev.device_get_sysfs_path(info)
 
         if name.startswith("md"):
@@ -454,6 +455,7 @@ class Populator(object):
         device = None
         try:
             device = PartitionDevice(name, sysfsPath=sysfs_path,
+                                     uuid=uuid,
                                      major=udev.device_get_major(info),
                                      minor=udev.device_get_minor(info),
                                      exists=True, parents=[disk])
@@ -753,6 +755,7 @@ class Populator(object):
 
     def handleUdevDiskLabelFormat(self, info, device):
         disklabel_type = udev.device_get_disklabel_type(info)
+        disklabel_uuid = udev.device_get_disklabel_uuid(info)
         log_method_call(self, device=device.name, label_type=disklabel_type)
         # if there is no disklabel on the device
         # blkid doesn't understand dasd disklabels, so bypass for dasd
@@ -789,6 +792,7 @@ class Populator(object):
         try:
             fmt = formats.getFormat("disklabel",
                                     device=device.path,
+                                    uuid=disklabel_uuid,
                                     exists=True)
         except InvalidDiskLabelError as e:
             log.info("no usable disklabel on %s", device.name)
diff --git a/blivet/udev.py b/blivet/udev.py
index db8c27f..ff43e34 100644
--- a/blivet/udev.py
+++ b/blivet/udev.py
@@ -557,6 +557,12 @@ def device_get_disklabel_type(info):
 
     return info.get("ID_PART_TABLE_TYPE")
 
+def device_get_disklabel_uuid(info):
+    return info.get("ID_PART_TABLE_UUID")
+
+def device_get_partition_uuid(info):
+    return info.get("ID_PART_ENTRY_UUID")
+
 # iscsi disks' ID_PATH form depends on the driver:
 # for software iscsi:
 # ip-${iscsi_address}:${iscsi_port}-iscsi-${iscsi_tgtname}-lun-${lun}
-- 
2.1.0

