[PATCH] Issue 292 Logical Storage Pool Returning "extended" Partitions as Possible Pool

From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> Extended partition is a container of logical partitions. Kimchi should skip extended partition regardless of it contains logical partitions or not. This patch uses pyparted to check if a partition is a extended partition and skip if it is. Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- contrib/DEBIAN/control.in | 1 + contrib/kimchi.spec.fedora.in | 1 + contrib/kimchi.spec.suse.in | 1 + docs/README.md | 6 +++--- src/kimchi/disks.py | 19 +++++++++++++++++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/contrib/DEBIAN/control.in b/contrib/DEBIAN/control.in index 1b03fc7..c2b2a40 100644 --- a/contrib/DEBIAN/control.in +++ b/contrib/DEBIAN/control.in @@ -15,6 +15,7 @@ Depends: python-cherrypy3 (>= 3.2.0), python-libxml2, qemu-kvm, python-pam, + python-parted, python-psutil (>= 0.6.0), python-ethtool, sosreport, diff --git a/contrib/kimchi.spec.fedora.in b/contrib/kimchi.spec.fedora.in index 149c3a7..bf80104 100644 --- a/contrib/kimchi.spec.fedora.in +++ b/contrib/kimchi.spec.fedora.in @@ -20,6 +20,7 @@ Requires: m2crypto Requires: python-imaging Requires: libxml2-python Requires: PyPAM +Requires: pyparted Requires: python-psutil >= 0.6.0 Requires: python-jsonschema >= 1.3.0 Requires: python-ethtool diff --git a/contrib/kimchi.spec.suse.in b/contrib/kimchi.spec.suse.in index beddada..cba0899 100644 --- a/contrib/kimchi.spec.suse.in +++ b/contrib/kimchi.spec.suse.in @@ -16,6 +16,7 @@ Requires: python-imaging Requires: python-M2Crypto Requires: python-libxml2 Requires: python-pam +Requires: python-parted Requires: python-psutil >= 0.6.0 Requires: python-jsonschema >= 1.3.0 Requires: python-ethtool diff --git a/docs/README.md b/docs/README.md index 5721878..4be0e53 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 + iscsi-initiator-utils libxslt pyparted # 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 + open-iscsi lvm2 xsltproc python-parted 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 + libxslt-tools python-xml python-parted Packages version requirement: python-psutil >= 0.6.0 diff --git a/src/kimchi/disks.py b/src/kimchi/disks.py index 8389922..cada869 100644 --- a/src/kimchi/disks.py +++ b/src/kimchi/disks.py @@ -20,6 +20,9 @@ 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 @@ -78,6 +81,17 @@ 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) + disk = PDisk(device) + if disk.getExtendedPartition().path == devNodePath: + return True + return False + + def _parse_lsblk_output(output, keys): # output is on format key="value", # where key can be NAME, TYPE, FSTYPE, SIZE, MOUNTPOINT, etc @@ -122,12 +136,13 @@ def get_partitions_names(): # Only list unmounted and unformated and leaf and (partition or disk) # leaf means a partition, a disk has no partition, or a disk not held # by any multipath device. Physical volume belongs to no volume group - # is also listed. + # is also listed. Extended partitions should not be listed. if not (dev['type'] in ['part', 'disk'] and dev['fstype'] in ['', 'LVM2_member'] and dev['mountpoint'] == "" and _get_vgname(devNodePath) == "" and - _is_dev_leaf(devNodePath)): + _is_dev_leaf(devNodePath) and + not _is_dev_extended_partition(dev['type'], devNodePath)): continue names.add(name) -- 1.8.5.3

just invert the position of the imports p comes after k
+from parted import Device as PDevice +from parted import Disk as PDisk + from kimchi.exception import OperationFailed from kimchi.utils import kimchi_log
@@ -78,6 +81,17 @@ 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) + disk = PDisk(device) + if disk.getExtendedPartition().path == devNodePath: + return True + return False + + def _parse_lsblk_output(output, keys): # output is on format key="value", # where key can be NAME, TYPE, FSTYPE, SIZE, MOUNTPOINT, etc @@ -122,12 +136,13 @@ def get_partitions_names(): # Only list unmounted and unformated and leaf and (partition or disk) # leaf means a partition, a disk has no partition, or a disk not held # by any multipath device. Physical volume belongs to no volume group - # is also listed. + # is also listed. Extended partitions should not be listed. if not (dev['type'] in ['part', 'disk'] and dev['fstype'] in ['', 'LVM2_member'] and dev['mountpoint'] == "" and _get_vgname(devNodePath) == "" and - _is_dev_leaf(devNodePath)): + _is_dev_leaf(devNodePath) and + not _is_dev_extended_partition(dev['type'], devNodePath)): continue
names.add(name)
-- Ramon Nunes Medeiros Software Engineer - Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com

on 2014/03/11 20:06, Ramon Medeiros wrote:
just invert the position of the imports
p comes after k
Thanks Ramon. I'm following PEP 8 [1]. It's standard for Python coding style. The kimchi project is following it as I thought. The PEP 8 suggests we group the import statements in the following sections. standard library imports blank line related third party imports blank line local application/library specific imports In this case pyparted is a third party import. So I put it before kimchi import. [1] http://legacy.python.org/dev/peps/pep-0008/#imports
+from parted import Device as PDevice +from parted import Disk as PDisk + from kimchi.exception import OperationFailed from kimchi.utils import kimchi_log
@@ -78,6 +81,17 @@ 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) + disk = PDisk(device) + if disk.getExtendedPartition().path == devNodePath: + return True + return False + + def _parse_lsblk_output(output, keys): # output is on format key="value", # where key can be NAME, TYPE, FSTYPE, SIZE, MOUNTPOINT, etc @@ -122,12 +136,13 @@ def get_partitions_names(): # Only list unmounted and unformated and leaf and (partition or disk) # leaf means a partition, a disk has no partition, or a disk not held # by any multipath device. Physical volume belongs to no volume group - # is also listed. + # is also listed. Extended partitions should not be listed. if not (dev['type'] in ['part', 'disk'] and dev['fstype'] in ['', 'LVM2_member'] and dev['mountpoint'] == "" and _get_vgname(devNodePath) == "" and - _is_dev_leaf(devNodePath)): + _is_dev_leaf(devNodePath) and + not _is_dev_extended_partition(dev['type'], devNodePath)): continue
names.add(name)
-- Thanks and best regards! Zhou Zheng Sheng / 周征晟 E-mail: zhshzhou@linux.vnet.ibm.com Telephone: 86-10-82454397

Reviewed-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> pyparted is good to detect the extended partition On 03/11/2014 01:06 PM, zhshzhou@linux.vnet.ibm.com wrote:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Extended partition is a container of logical partitions. Kimchi should skip extended partition regardless of it contains logical partitions or not. This patch uses pyparted to check if a partition is a extended partition and skip if it is.
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- contrib/DEBIAN/control.in | 1 + contrib/kimchi.spec.fedora.in | 1 + contrib/kimchi.spec.suse.in | 1 + docs/README.md | 6 +++--- src/kimchi/disks.py | 19 +++++++++++++++++-- 5 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/contrib/DEBIAN/control.in b/contrib/DEBIAN/control.in index 1b03fc7..c2b2a40 100644 --- a/contrib/DEBIAN/control.in +++ b/contrib/DEBIAN/control.in @@ -15,6 +15,7 @@ Depends: python-cherrypy3 (>= 3.2.0), python-libxml2, qemu-kvm, python-pam, + python-parted, python-psutil (>= 0.6.0), python-ethtool, sosreport, diff --git a/contrib/kimchi.spec.fedora.in b/contrib/kimchi.spec.fedora.in index 149c3a7..bf80104 100644 --- a/contrib/kimchi.spec.fedora.in +++ b/contrib/kimchi.spec.fedora.in @@ -20,6 +20,7 @@ Requires: m2crypto Requires: python-imaging Requires: libxml2-python Requires: PyPAM +Requires: pyparted Requires: python-psutil >= 0.6.0 Requires: python-jsonschema >= 1.3.0 Requires: python-ethtool diff --git a/contrib/kimchi.spec.suse.in b/contrib/kimchi.spec.suse.in index beddada..cba0899 100644 --- a/contrib/kimchi.spec.suse.in +++ b/contrib/kimchi.spec.suse.in @@ -16,6 +16,7 @@ Requires: python-imaging Requires: python-M2Crypto Requires: python-libxml2 Requires: python-pam +Requires: python-parted Requires: python-psutil >= 0.6.0 Requires: python-jsonschema >= 1.3.0 Requires: python-ethtool diff --git a/docs/README.md b/docs/README.md index 5721878..4be0e53 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 + iscsi-initiator-utils libxslt pyparted # 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 + open-iscsi lvm2 xsltproc python-parted
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 + libxslt-tools python-xml python-parted
Packages version requirement: python-psutil >= 0.6.0 diff --git a/src/kimchi/disks.py b/src/kimchi/disks.py index 8389922..cada869 100644 --- a/src/kimchi/disks.py +++ b/src/kimchi/disks.py @@ -20,6 +20,9 @@ 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
@@ -78,6 +81,17 @@ 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) + disk = PDisk(device) + if disk.getExtendedPartition().path == devNodePath: + return True + return False + + def _parse_lsblk_output(output, keys): # output is on format key="value", # where key can be NAME, TYPE, FSTYPE, SIZE, MOUNTPOINT, etc @@ -122,12 +136,13 @@ def get_partitions_names(): # Only list unmounted and unformated and leaf and (partition or disk) # leaf means a partition, a disk has no partition, or a disk not held # by any multipath device. Physical volume belongs to no volume group - # is also listed. + # is also listed. Extended partitions should not be listed. if not (dev['type'] in ['part', 'disk'] and dev['fstype'] in ['', 'LVM2_member'] and dev['mountpoint'] == "" and _get_vgname(devNodePath) == "" and - _is_dev_leaf(devNodePath)): + _is_dev_leaf(devNodePath) and + not _is_dev_extended_partition(dev['type'], devNodePath)): continue
names.add(name)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

Reviewed-by: Crístian Viana <vianac@linux.vnet.ibm.com> Am 11-03-2014 02:06, schrieb zhshzhou@linux.vnet.ibm.com:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Extended partition is a container of logical partitions. Kimchi should skip extended partition regardless of it contains logical partitions or not. This patch uses pyparted to check if a partition is a extended partition and skip if it is.
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
participants (6)
-
Aline Manera
-
Crístian Viana
-
Ramon Medeiros
-
Sheldon
-
Zhou Zheng Sheng
-
zhshzhou@linux.vnet.ibm.com