Skip to content

Commit

Permalink
Merge pull request #1276 from vojtechtrefny/main_partition-type-name
Browse files Browse the repository at this point in the history
Add partition type human-readable string to PartitionDevice
  • Loading branch information
vojtechtrefny authored Aug 27, 2024
2 parents 1f53cb4 + 55540b1 commit 709884a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blivet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def log_bd_message(level, msg):
from gi.repository import GLib
from gi.repository import BlockDev as blockdev
if arch.is_s390():
_REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "s390", "nvme", "fs"))
_REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "s390", "nvme", "fs", "part"))
else:
_REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "nvme", "fs"))
_REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "nvme", "fs", "part"))

blockdev.utils_set_log_level(syslog.LOG_INFO)

Expand Down
26 changes: 26 additions & 0 deletions blivet/devices/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from ..formats import DeviceFormat, get_format
from ..devicelibs.gpt import gpt_part_uuid_for_mountpoint
from ..size import Size, MiB, ROUND_DOWN
from .. import avail_plugs

import logging
log = logging.getLogger("blivet")
Expand Down Expand Up @@ -159,6 +160,7 @@ def __init__(self, name, fmt=None, uuid=None,
self._parted_partition = None
self._orig_path = None
self._part_type_uuid = None
self._part_type_name = None
self._mountpoint = mountpoint

if not exists and size is None:
Expand Down Expand Up @@ -384,6 +386,30 @@ def part_type_uuid(self):
pass
return self._part_type_uuid

@property
def part_type_name(self):
""" Get the partition's type as a human-readable string. """
if not self.exists:
return None
else:
if self._part_type_name:
return self._part_type_name
else:
if "part" not in avail_plugs:
log.info("Libblockdev part plugin not available, cannot get partition type")
return None
else:
try:
spec = blockdev.part.get_part_spec(self.disk.path, self.path)
except (blockdev.PartError, blockdev.BlockDevNotImplementedError) as e:
log.error("Failed to get partition spec for %s: %s", self.path, str(e))
else:
if not spec or not hasattr(spec, "type_name"):
log.error("Failed to get partition spec for %s", self.path)
else:
self._part_type_name = spec.type_name
return self._part_type_name

@property
def is_extended(self):
return (self.part_type is not None and
Expand Down
1 change: 1 addition & 0 deletions python-blivet.spec
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Recommends: libblockdev-lvm >= %{libblockdevver}
Recommends: libblockdev-mdraid >= %{libblockdevver}
Recommends: libblockdev-mpath >= %{libblockdevver}
Recommends: libblockdev-nvme >= %{libblockdevver}
Recommends: libblockdev-part >= %{libblockdevver}
Recommends: libblockdev-swap >= %{libblockdevver}

%ifarch s390 s390x
Expand Down
8 changes: 8 additions & 0 deletions tests/storage_tests/devices_test/lvm_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import shutil
import subprocess
from uuid import UUID

import parted

from ..storagetestcase import StorageTestCase

Expand Down Expand Up @@ -101,6 +104,11 @@ def test_lvm_basic(self):
self.assertIsNone(pv.format.vg_name)
self.assertIsNone(pv.format.vg_uuid)

# not really related to LVM, but we want to test the partition types somewhere
if hasattr(parted.Partition, "type_uuid"):
self.assertEqual(pv.part_type_uuid, UUID('e6d6d379-f507-44c2-a23c-238f2a3df928'))
self.assertEqual(pv.part_type_name, "Linux LVM")

def test_lvm_thin(self):
disk = self.storage.devicetree.get_device_by_path(self.vdevs[0])
self.assertIsNotNone(disk)
Expand Down

0 comments on commit 709884a

Please sign in to comment.