[Kimchi-devel] [PATCH] Fix pyparted dependency problem

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Tue Apr 8 09:47:27 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

On opensuse, libvirt and python-parted depend on same lib
of different versions, working this problem around
by using parted command instead of python-parted library.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 docs/README.md      |  6 +++---
 src/kimchi/disks.py | 49 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/docs/README.md b/docs/README.md
index 8b8b181..a3e1403 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -53,7 +53,7 @@ Install Dependencies
                         PyPAM m2crypto python-jsonschema rpm-build \
                         qemu-kvm python-psutil python-ethtool sos \
                         python-ipaddr python-lxml nfs-utils \
-                        iscsi-initiator-utils libxslt pyparted
+                        iscsi-initiator-utils libxslt
      # If using RHEL6, install the following additional packages:
      $ sudo yum install python-unittest2 python-ordereddict
      # Restart libvirt to allow configuration changes to take effect
@@ -75,7 +75,7 @@ for more information on how to configure your system to access this repository.
                            python-pam python-m2crypto python-jsonschema \
                            qemu-kvm libtool python-psutil python-ethtool \
                            sosreport python-ipaddr python-lxml nfs-common \
-                           open-iscsi lvm2 xsltproc python-parted
+                           open-iscsi lvm2 xsltproc
 
     Packages version requirement:
         python-jsonschema >= 1.3.0
@@ -89,7 +89,7 @@ for more information on how to configure your system to access this repository.
                           python-pam python-M2Crypto python-jsonschema \
                           rpm-build kvm python-psutil python-ethtool \
                           python-ipaddr python-lxml nfs-client open-iscsi \
-                          libxslt-tools python-xml python-parted
+                          libxslt-tools python-xml
 
     Packages version requirement:
         python-psutil >= 0.6.0
diff --git a/src/kimchi/disks.py b/src/kimchi/disks.py
index 5f004b3..1611459 100644
--- a/src/kimchi/disks.py
+++ b/src/kimchi/disks.py
@@ -20,11 +20,8 @@
 import re
 import subprocess
 
-from parted import Device as PDevice
-from parted import Disk as PDisk
-
 from kimchi.exception import OperationFailed
-from kimchi.utils import kimchi_log
+from kimchi.utils import kimchi_log, run_command, parse_cmd_output
 
 
 def _get_friendly_dm_path(maj_min):
@@ -92,15 +89,19 @@ def _is_dev_leaf(devNodePath):
     return childrenCount == 0
 
 
-def _is_dev_extended_partition(devType, devNodePath):
-    if devType != 'part':
-        return False
-    diskPath = devNodePath.rstrip('0123456789')
-    device = PDevice(diskPath)
-    extended_part = PDisk(device).getExtendedPartition()
-    if extended_part and extended_part.path == devNodePath:
-        return True
-    return False
+def _get_disks():
+    disks = list()
+    output, error, returncode = run_command(['lsblk', '--nodeps'])
+    if returncode != 0:
+        raise OperationFailed('Cannot retrieve block info')
+
+    targets = parse_cmd_output(output,
+        output_items=['name', 'magic', 'rm', 'size', 'ro', 'type'])
+    for target in targets:
+        if target['type'] == 'disk':
+            disks.append('/dev/%s' % target['name'])
+
+    return disks
 
 
 def _parse_lsblk_output(output, keys):
@@ -134,11 +135,31 @@ def _get_vgname(devNodePath):
     return re.findall(r"LVM2_VG_NAME='([^\']*)'", out)[0]
 
 
+def _get_extended_partitions():
+    disks = _get_disks()
+    extended_parts = list()
+
+    for disk in disks:
+        output, error, returncode = run_command(['parted', disk, 'print'])
+        if returncode != 0:
+            kimchi_log.error('Cannot get partition info of %s', disk)
+
+        outs = output.partition('File system     Flags')
+        partitions = parse_cmd_output(outs[2],
+            output_items=['number', 'start', 'end', 'size', 'type', 'fs', 'flags'])
+        for partition in partitions:
+            if partition['type'] == 'extended':
+                extended_parts.append('%s%s' % (disk.lstrip('/dev/'), partition['number']))
+
+    return extended_parts
+
+
 def get_partitions_names():
     names = set()
     keys = ["NAME", "TYPE", "FSTYPE", "MOUNTPOINT", "MAJ:MIN"]
     # output is on format key="value",
     # where key can be NAME, TYPE, FSTYPE, MOUNTPOINT
+    extended_parts = _get_extended_partitions()
     for dev in _get_lsblk_devs(keys):
         # split()[0] to avoid the second part of the name, after the
         # whiteline
@@ -153,7 +174,7 @@ def get_partitions_names():
                 dev['mountpoint'] == "" and
                 _get_vgname(devNodePath) == "" and
                 _is_dev_leaf(devNodePath) and
-                not _is_dev_extended_partition(dev['type'], devNodePath)):
+                name not in extended_parts):
             continue
 
         names.add(name)
-- 
1.8.3.2




More information about the Kimchi-devel mailing list