Merge lp:~ahasenack/charm-helpers/charm-helpers-ceph-lvm-1317980 into lp:charm-helpers

Proposed by Andreas Hasenack
Status: Merged
Merged at revision: 148
Proposed branch: lp:~ahasenack/charm-helpers/charm-helpers-ceph-lvm-1317980
Merge into: lp:charm-helpers
Diff against target: 62 lines (+25/-1)
3 files modified
README.test (+3/-0)
charmhelpers/contrib/storage/linux/lvm.py (+1/-1)
tests/contrib/storage/test_linux_storage_lvm.py (+21/-0)
To merge this branch: bzr merge lp:~ahasenack/charm-helpers/charm-helpers-ceph-lvm-1317980
Reviewer Review Type Date Requested Status
Marco Ceppi Approve
Review via email: mp+219105@code.launchpad.net

Commit message

Fix list_lvm_volume_group() to handle PVs that are not part of a volume group.

Description of the change

list_lvm_volume_group() would incorrectly return "Name" if an LVM physical volume is detected, but not assigned to a volume group. This is what such a PV looks like:

# pvdisplay /dev/sdb
  "/dev/sdb" is a new physical volume of "465.00 GiB"
  --- NEW Physical volume ---
  PV Name /dev/sdb
  VG Name
  PV Size 465.00 GiB
  Allocatable NO
  PE Size 0
  Total PE 0
  Free PE 0
  Allocated PE 0
  PV UUID 7RDJz8-pUqi-9RAz-J8pK-CDKs-JbAa-AO603b

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM! Thanks for this fix

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.test'
--- README.test 2013-10-21 08:34:03 +0000
+++ README.test 2014-05-10 20:06:51 +0000
@@ -6,3 +6,6 @@
6python-mock6python-mock
7python-testtools7python-testtools
8python-jinja28python-jinja2
9python-coverage
10python-netifaces
11python-netaddr
912
=== modified file 'charmhelpers/contrib/storage/linux/lvm.py'
--- charmhelpers/contrib/storage/linux/lvm.py 2013-06-24 22:39:29 +0000
+++ charmhelpers/contrib/storage/linux/lvm.py 2014-05-10 20:06:51 +0000
@@ -62,7 +62,7 @@
62 pvd = check_output(['pvdisplay', block_device]).splitlines()62 pvd = check_output(['pvdisplay', block_device]).splitlines()
63 for l in pvd:63 for l in pvd:
64 if l.strip().startswith('VG Name'):64 if l.strip().startswith('VG Name'):
65 vg = ' '.join(l.split()).split(' ').pop()65 vg = ' '.join(l.strip().split()[2:])
66 return vg66 return vg
6767
6868
6969
=== modified file 'tests/contrib/storage/test_linux_storage_lvm.py'
--- tests/contrib/storage/test_linux_storage_lvm.py 2013-06-24 22:39:29 +0000
+++ tests/contrib/storage/test_linux_storage_lvm.py 2014-05-10 20:06:51 +0000
@@ -19,6 +19,20 @@
1919
20"""20"""
2121
22EMPTY_VG_IN_PVDISPLAY = """
23 --- Physical volume ---
24 PV Name /dev/loop0
25 VG Name
26 PV Size 10.00 MiB / not usable 2.00 MiB
27 Allocatable yes
28 PE Size 4.00 MiB
29 Total PE 2
30 Free PE 2
31 Allocated PE 0
32 PV UUID fyVqlr-pyrL-89On-f6MD-U91T-dEfc-SL0V2V
33
34"""
35
22# It's a mouthful.36# It's a mouthful.
23STORAGE_LINUX_LVM = 'charmhelpers.contrib.storage.linux.lvm'37STORAGE_LINUX_LVM = 'charmhelpers.contrib.storage.linux.lvm'
2438
@@ -31,6 +45,13 @@
31 vg = lvm.list_lvm_volume_group('/dev/loop0')45 vg = lvm.list_lvm_volume_group('/dev/loop0')
32 self.assertEquals(vg, 'foo')46 self.assertEquals(vg, 'foo')
3347
48 def test_find_empty_volume_group_on_pv(self):
49 '''Return empty string when no volume group is assigned to the PV'''
50 with patch(STORAGE_LINUX_LVM + '.check_output') as check_output:
51 check_output.return_value = EMPTY_VG_IN_PVDISPLAY
52 vg = lvm.list_lvm_volume_group('/dev/loop0')
53 self.assertEquals(vg, '')
54
34 @patch(STORAGE_LINUX_LVM + '.list_lvm_volume_group')55 @patch(STORAGE_LINUX_LVM + '.list_lvm_volume_group')
35 def test_deactivate_lvm_volume_groups(self, ls_vg):56 def test_deactivate_lvm_volume_groups(self, ls_vg):
36 '''It deactivates active volume groups on LVM PV'''57 '''It deactivates active volume groups on LVM PV'''

Subscribers

People subscribed via source and target branches