Merge lp:~jason-hobbs/charms/trusty/cinder/remove-volume-group into lp:~openstack-charmers-archive/charms/trusty/cinder/next

Proposed by Jason Hobbs
Status: Merged
Merged at revision: 109
Proposed branch: lp:~jason-hobbs/charms/trusty/cinder/remove-volume-group
Merge into: lp:~openstack-charmers-archive/charms/trusty/cinder/next
Prerequisite: lp:~jason-hobbs/charms/trusty/cinder/log-lvm-info
Diff against target: 160 lines (+88/-3)
2 files modified
hooks/cinder_utils.py (+36/-1)
unit_tests/test_cinder_utils.py (+52/-2)
To merge this branch: bzr merge lp:~jason-hobbs/charms/trusty/cinder/remove-volume-group
Reviewer Review Type Date Requested Status
Corey Bryant (community) Approve
Review via email: mp+265461@code.launchpad.net

Commit message

When 'overwrite' is set and volume group exists on other devices, remove it.

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #6567 cinder-next for jason-hobbs mp265461
    LINT FAIL: lint-test failed

LINT Results (max last 2 lines):
make: *** [lint] Error 1
ERROR:root:Make target returned non-zero.

Full lint test output: http://paste.ubuntu.com/11916989/
Build: http://10.245.162.77:8080/job/charm_lint_check/6567/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #6199 cinder-next for jason-hobbs mp265461
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/6199/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #5244 cinder-next for jason-hobbs mp265461
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/11917122/
Build: http://10.245.162.77:8080/job/charm_amulet_test/5244/

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Hey Jason, thanks for the patch! I have a couple minor comments below. Also can you run 'make lint' and fix the results? The amulet failure above might have just been an osci hiccup.

110. By Jason Hobbs

Corrections from code review.

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #6625 cinder-next for jason-hobbs mp265461
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/6625/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #6252 cinder-next for jason-hobbs mp265461
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/6252/

Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

On 07/22/2015 08:19 AM, Corey Bryant wrote:
> Hey Jason, thanks for the patch! I have a couple minor comments below. Also can you run 'make lint' and fix the results? The amulet failure above might have just been an osci hiccup.

Thanks for the review - I fixed the lint and docstring copy/paste errors
you pointed out.

>> if vg_found is False and len(new_devices) > 0:
>> + if overwrite:
>> + ensure_lvm_volume_group_non_existent(volume_group)
>
> I wouldn't block merging on this but it seems like you could get rid of ensure_lvm_volume_group_non_existent and just add it's logic to remove_lvm_volume_group.

I'd prefer to leave it how it is - I like that 'remove_lvm_volume_group'
does just one thing - it issues the vgremove command. I also think it'd
be less clear to always call "remove_lvm_volume_group" even if it's not
there to begin with.

Jason

Revision history for this message
Corey Bryant (corey.bryant) wrote :

> On 07/22/2015 08:19 AM, Corey Bryant wrote:
> > Hey Jason, thanks for the patch! I have a couple minor comments below.
> Also can you run 'make lint' and fix the results? The amulet failure above
> might have just been an osci hiccup.
>
> Thanks for the review - I fixed the lint and docstring copy/paste errors
> you pointed out.
>
> >> if vg_found is False and len(new_devices) > 0:
> >> + if overwrite:
> >> + ensure_lvm_volume_group_non_existent(volume_group)
> >
> > I wouldn't block merging on this but it seems like you could get rid of
> ensure_lvm_volume_group_non_existent and just add it's logic to
> remove_lvm_volume_group.
>
> I'd prefer to leave it how it is - I like that 'remove_lvm_volume_group'
> does just one thing - it issues the vgremove command. I also think it'd
> be less clear to always call "remove_lvm_volume_group" even if it's not
> there to begin with.

Fair enough, I'm convinced.
>
> Jason

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Just waiting on the amulet results to post before landing this.

review: Approve
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #5254 cinder-next for jason-hobbs mp265461
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/5254/

Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

Can this be landed now?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/cinder_utils.py'
2--- hooks/cinder_utils.py 2015-07-22 15:02:01 +0000
3+++ hooks/cinder_utils.py 2015-07-22 15:02:01 +0000
4@@ -355,6 +355,38 @@
5 subprocess.check_call(['vgextend', volume_group, block_device])
6
7
8+def lvm_volume_group_exists(volume_group):
9+ """Check for the existence of a volume group.
10+
11+ :param volume_group: str: Name of volume group.
12+ """
13+ try:
14+ subprocess.check_call(['vgdisplay', volume_group])
15+ except subprocess.CalledProcessError:
16+ return False
17+ else:
18+ return True
19+
20+
21+def remove_lvm_volume_group(volume_group):
22+ """Remove a volume group.
23+
24+ :param volume_group: str: Name of volume group to remove.
25+ """
26+ subprocess.check_call(['vgremove', '--force', volume_group])
27+
28+
29+def ensure_lvm_volume_group_non_existent(volume_group):
30+ """Remove volume_group if it exists.
31+
32+ :param volume_group: str: Name of volume group.
33+ """
34+ if not lvm_volume_group_exists(volume_group):
35+ return
36+
37+ remove_lvm_volume_group(volume_group)
38+
39+
40 def log_lvm_info():
41 """Log some useful information about how LVM is setup."""
42 pvscan_output = subprocess.check_output(['pvscan'])
43@@ -405,8 +437,11 @@
44 vg_found = True
45
46 log_lvm_info()
47-
48+
49 if vg_found is False and len(new_devices) > 0:
50+ if overwrite:
51+ ensure_lvm_volume_group_non_existent(volume_group)
52+
53 # Create new volume group from first device
54 create_lvm_volume_group(volume_group, new_devices[0])
55 new_devices.remove(new_devices[0])
56
57=== modified file 'unit_tests/test_cinder_utils.py'
58--- unit_tests/test_cinder_utils.py 2015-07-22 15:02:01 +0000
59+++ unit_tests/test_cinder_utils.py 2015-07-22 15:02:01 +0000
60@@ -2,6 +2,7 @@
61
62 from collections import OrderedDict
63 import os
64+import subprocess
65
66 os.environ['JUJU_UNIT_NAME'] = 'cinder'
67 import cinder_utils as cinder_utils
68@@ -247,11 +248,12 @@
69 _check.assert_called_with(['fdisk', '-l', '/dev/vdb'], stderr=-2)
70
71 @patch('cinder_utils.log_lvm_info', Mock())
72+ @patch.object(cinder_utils, 'ensure_lvm_volume_group_non_existent')
73 @patch.object(cinder_utils, 'clean_storage')
74 @patch.object(cinder_utils, 'reduce_lvm_volume_group_missing')
75 @patch.object(cinder_utils, 'extend_lvm_volume_group')
76 def test_configure_lvm_storage(self, extend_lvm, reduce_lvm,
77- clean_storage):
78+ clean_storage, ensure_non_existent):
79 devices = ['/dev/vdb', '/dev/vdc']
80 self.is_lvm_physical_volume.return_value = False
81 cinder_utils.configure_lvm_storage(devices, 'test', True, True)
82@@ -266,6 +268,7 @@
83 self.create_lvm_volume_group.assert_called_with('test', '/dev/vdb')
84 reduce_lvm.assert_called_with('test')
85 extend_lvm.assert_called_with('test', '/dev/vdc')
86+ ensure_non_existent.assert_called_with('test')
87
88 @patch('cinder_utils.log_lvm_info', Mock())
89 @patch.object(cinder_utils, 'has_partition_table')
90@@ -301,11 +304,13 @@
91 reduce_lvm.assert_called_with('test')
92
93 @patch('cinder_utils.log_lvm_info', Mock())
94+ @patch.object(cinder_utils, 'ensure_lvm_volume_group_non_existent')
95 @patch.object(cinder_utils, 'clean_storage')
96 @patch.object(cinder_utils, 'reduce_lvm_volume_group_missing')
97 @patch.object(cinder_utils, 'extend_lvm_volume_group')
98 def test_configure_lvm_storage_loopback(self, extend_lvm, reduce_lvm,
99- clean_storage):
100+ clean_storage,
101+ ensure_non_existent):
102 devices = ['/mnt/loop0|10']
103 self.ensure_loopback_device.return_value = '/dev/loop0'
104 self.is_lvm_physical_volume.return_value = False
105@@ -316,6 +321,7 @@
106 self.create_lvm_volume_group.assert_called_with('test', '/dev/loop0')
107 reduce_lvm.assert_called_with('test')
108 self.assertFalse(extend_lvm.called)
109+ ensure_non_existent.assert_called_with('test')
110
111 @patch('cinder_utils.log_lvm_info', Mock())
112 @patch.object(cinder_utils, 'clean_storage')
113@@ -725,3 +731,47 @@
114 cinder_utils.log_lvm_info()
115 _check.assert_called_with(['pvscan'])
116 self.juju_log.assert_called_with("pvscan: %s" % output)
117+
118+ @patch.object(cinder_utils, 'lvm_volume_group_exists')
119+ @patch.object(cinder_utils, 'remove_lvm_volume_group')
120+ def test_ensure_non_existent_removes_if_present(self,
121+ remove_lvm_volume_group,
122+ volume_group_exists):
123+ volume_group = "test"
124+ volume_group_exists.return_value = True
125+ cinder_utils.ensure_lvm_volume_group_non_existent(volume_group)
126+ remove_lvm_volume_group.assert_called_with(volume_group)
127+
128+ @patch.object(cinder_utils, 'lvm_volume_group_exists')
129+ @patch.object(cinder_utils, 'remove_lvm_volume_group')
130+ def test_ensure_non_existent_not_present(self, remove_lvm_volume_group,
131+ volume_group_exists):
132+ volume_group = "test"
133+ volume_group_exists.return_value = False
134+ cinder_utils.ensure_lvm_volume_group_non_existent(volume_group)
135+ self.assertFalse(remove_lvm_volume_group.called)
136+
137+ @patch('subprocess.check_call')
138+ def test_lvm_volume_group_exists_finds_volume_group(self, _check):
139+ volume_group = "test"
140+ _check.return_value = True
141+ result = cinder_utils.lvm_volume_group_exists(volume_group)
142+ self.assertTrue(result)
143+ _check.assert_called_with(['vgdisplay', volume_group])
144+
145+ @patch('subprocess.check_call')
146+ def test_lvm_volume_group_exists_finds_no_volume_group(self, _check):
147+ volume_group = "test"
148+
149+ def raise_error(x):
150+ raise subprocess.CalledProcessError(1, x)
151+ _check.side_effect = raise_error
152+ result = cinder_utils.lvm_volume_group_exists(volume_group)
153+ self.assertFalse(result)
154+ _check.assert_called_with(['vgdisplay', volume_group])
155+
156+ @patch('subprocess.check_call')
157+ def test_remove_lvm_volume_group(self, _check):
158+ volume_group = "test"
159+ cinder_utils.remove_lvm_volume_group(volume_group)
160+ _check.assert_called_with(['vgremove', '--force', volume_group])

Subscribers

People subscribed via source and target branches