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
1=== modified file 'README.test'
2--- README.test 2013-10-21 08:34:03 +0000
3+++ README.test 2014-05-10 20:06:51 +0000
4@@ -6,3 +6,6 @@
5 python-mock
6 python-testtools
7 python-jinja2
8+python-coverage
9+python-netifaces
10+python-netaddr
11
12=== modified file 'charmhelpers/contrib/storage/linux/lvm.py'
13--- charmhelpers/contrib/storage/linux/lvm.py 2013-06-24 22:39:29 +0000
14+++ charmhelpers/contrib/storage/linux/lvm.py 2014-05-10 20:06:51 +0000
15@@ -62,7 +62,7 @@
16 pvd = check_output(['pvdisplay', block_device]).splitlines()
17 for l in pvd:
18 if l.strip().startswith('VG Name'):
19- vg = ' '.join(l.split()).split(' ').pop()
20+ vg = ' '.join(l.strip().split()[2:])
21 return vg
22
23
24
25=== modified file 'tests/contrib/storage/test_linux_storage_lvm.py'
26--- tests/contrib/storage/test_linux_storage_lvm.py 2013-06-24 22:39:29 +0000
27+++ tests/contrib/storage/test_linux_storage_lvm.py 2014-05-10 20:06:51 +0000
28@@ -19,6 +19,20 @@
29
30 """
31
32+EMPTY_VG_IN_PVDISPLAY = """
33+ --- Physical volume ---
34+ PV Name /dev/loop0
35+ VG Name
36+ PV Size 10.00 MiB / not usable 2.00 MiB
37+ Allocatable yes
38+ PE Size 4.00 MiB
39+ Total PE 2
40+ Free PE 2
41+ Allocated PE 0
42+ PV UUID fyVqlr-pyrL-89On-f6MD-U91T-dEfc-SL0V2V
43+
44+"""
45+
46 # It's a mouthful.
47 STORAGE_LINUX_LVM = 'charmhelpers.contrib.storage.linux.lvm'
48
49@@ -31,6 +45,13 @@
50 vg = lvm.list_lvm_volume_group('/dev/loop0')
51 self.assertEquals(vg, 'foo')
52
53+ def test_find_empty_volume_group_on_pv(self):
54+ '''Return empty string when no volume group is assigned to the PV'''
55+ with patch(STORAGE_LINUX_LVM + '.check_output') as check_output:
56+ check_output.return_value = EMPTY_VG_IN_PVDISPLAY
57+ vg = lvm.list_lvm_volume_group('/dev/loop0')
58+ self.assertEquals(vg, '')
59+
60 @patch(STORAGE_LINUX_LVM + '.list_lvm_volume_group')
61 def test_deactivate_lvm_volume_groups(self, ls_vg):
62 '''It deactivates active volume groups on LVM PV'''

Subscribers

People subscribed via source and target branches