Merge lp:~tribaal/charms/trusty/swift-storage/backport-1496004-to-stable into lp:~openstack-charmers-archive/charms/trusty/swift-storage/trunk

Proposed by Chris Glass
Status: Merged
Merged at revision: 72
Proposed branch: lp:~tribaal/charms/trusty/swift-storage/backport-1496004-to-stable
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-storage/trunk
Diff against target: 139 lines (+72/-6)
2 files modified
hooks/swift_storage_utils.py (+39/-5)
unit_tests/test_swift_storage_utils.py (+33/-1)
To merge this branch: bzr merge lp:~tribaal/charms/trusty/swift-storage/backport-1496004-to-stable
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
David Britton (community) Approve
Review via email: mp+273547@code.launchpad.net

Description of the change

This is a backport of the fixes introduced in https://code.launchpad.net/~gnuoy/charms/trusty/swift-storage/lp1496004/+merge/273209 .

Note that the only difference in terms of diff is that the swift_storage_utils.py file is in the "hooks" folder here instead of the "lib/" folder in the -next branch.

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

charm_unit_test #10581 swift-storage for tribaal mp273547
    UNIT OK: passed

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

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

charm_lint_check #11390 swift-storage for tribaal mp273547
    LINT FAIL: lint-test failed
    LINT FAIL: charm-proof failed

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

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

Revision history for this message
David Britton (dpb) wrote :

Looks like a straight backport, diff looks good. +1

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

charm_amulet_test #7137 swift-storage for tribaal mp273547
    AMULET OK: passed

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

Revision history for this message
Liam Young (gnuoy) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/swift_storage_utils.py'
--- hooks/swift_storage_utils.py 2015-07-01 20:53:27 +0000
+++ hooks/swift_storage_utils.py 2015-10-06 15:16:25 +0000
@@ -3,7 +3,7 @@
3import shutil3import shutil
4import tempfile4import tempfile
55
6from subprocess import check_call, call, CalledProcessError6from subprocess import check_call, call, CalledProcessError, check_output
77
8# Stuff copied from cinder py charm, needs to go somewhere8# Stuff copied from cinder py charm, needs to go somewhere
9# common.9# common.
@@ -177,19 +177,53 @@
177 return is_block_device(partition) and not is_device_mounted(partition)177 return is_block_device(partition) and not is_device_mounted(partition)
178178
179179
180def find_block_devices():180def get_mount_point(device):
181 mnt_point = None
182 try:
183 out = check_output(['findmnt', device])
184 mnt_points = []
185 for line in out.split('\n'):
186 if line and not line.startswith('TARGET'):
187 mnt_points.append(line.split()[0])
188 if len(mnt_points) > 1:
189 log('Device {} mounted in multiple times, ignoring'.format(device))
190 else:
191 mnt_point = mnt_points[0]
192 except CalledProcessError:
193 # findmnt returns non-zero rc if dev not mounted
194 pass
195 return mnt_point
196
197
198def find_block_devices(include_mounted=False):
181 found = []199 found = []
182 incl = ['sd[a-z]', 'vd[a-z]', 'cciss\/c[0-9]d[0-9]']200 incl = ['sd[a-z]', 'vd[a-z]', 'cciss\/c[0-9]d[0-9]']
183201
184 with open('/proc/partitions') as proc:202 with open('/proc/partitions') as proc:
185 print proc
186 partitions = [p.split() for p in proc.readlines()[2:]]203 partitions = [p.split() for p in proc.readlines()[2:]]
187 for partition in [p[3] for p in partitions if p]:204 for partition in [p[3] for p in partitions if p]:
188 for inc in incl:205 for inc in incl:
189 _re = re.compile(r'^(%s)$' % inc)206 _re = re.compile(r'^(%s)$' % inc)
190 if _re.match(partition):207 if _re.match(partition):
191 found.append(os.path.join('/dev', partition))208 found.append(os.path.join('/dev', partition))
192 return [f for f in found if _is_storage_ready(f)]209 if include_mounted:
210 devs = [f for f in found if is_block_device(f)]
211 else:
212 devs = [f for f in found if _is_storage_ready(f)]
213 return devs
214
215
216def guess_block_devices():
217 bdevs = find_block_devices(include_mounted=True)
218 gdevs = []
219 for dev in bdevs:
220 if is_device_mounted(dev):
221 mnt_point = get_mount_point(dev)
222 if mnt_point and mnt_point.startswith('/srv/node'):
223 gdevs.append(dev)
224 else:
225 gdevs.append(dev)
226 return gdevs
193227
194228
195def determine_block_devices():229def determine_block_devices():
@@ -201,7 +235,7 @@
201 return None235 return None
202236
203 if block_device == 'guess':237 if block_device == 'guess':
204 bdevs = find_block_devices()238 bdevs = guess_block_devices()
205 else:239 else:
206 bdevs = block_device.split(' ')240 bdevs = block_device.split(' ')
207241
208242
=== modified file 'unit_tests/test_swift_storage_utils.py'
--- unit_tests/test_swift_storage_utils.py 2015-04-02 18:56:27 +0000
+++ unit_tests/test_swift_storage_utils.py 2015-10-06 15:16:25 +0000
@@ -75,6 +75,11 @@
75 8 16 119454720 sdb175 8 16 119454720 sdb1
76"""76"""
7777
78FINDMNT_FOUND_TEMPLATE = """
79TARGET SOURCE FSTYPE OPTIONS
80{} /dev/{} xfs rw,relatime,attr2,inode64,noquota
81"""
82
7883
79class SwiftStorageUtilsTests(CharmTestCase):84class SwiftStorageUtilsTests(CharmTestCase):
8085
@@ -153,9 +158,17 @@
153 ex = ['/dev/vdb', '/srv/swift.img']158 ex = ['/dev/vdb', '/srv/swift.img']
154 self.assertEqual(ex, result)159 self.assertEqual(ex, result)
155160
161 @patch.object(swift_utils, 'check_output')
156 @patch.object(swift_utils, 'find_block_devices')162 @patch.object(swift_utils, 'find_block_devices')
157 @patch.object(swift_utils, 'ensure_block_device')163 @patch.object(swift_utils, 'ensure_block_device')
158 def test_determine_block_device_guess_dev(self, _ensure, _find):164 def test_determine_block_device_guess_dev(self, _ensure, _find,
165 _check_output):
166 "Devices already mounted under /srv/node/ should be returned"
167 def _findmnt(cmd):
168 dev = cmd[1].split('/')[-1]
169 mnt_point = '/srv/node/' + dev
170 return FINDMNT_FOUND_TEMPLATE.format(mnt_point, dev)
171 _check_output.side_effect = _findmnt
159 _ensure.side_effect = self._fake_ensure172 _ensure.side_effect = self._fake_ensure
160 self.test_config.set('block-device', 'guess')173 self.test_config.set('block-device', 'guess')
161 _find.return_value = ['/dev/vdb', '/dev/sdb']174 _find.return_value = ['/dev/vdb', '/dev/sdb']
@@ -163,6 +176,25 @@
163 self.assertTrue(_find.called)176 self.assertTrue(_find.called)
164 self.assertEquals(result, ['/dev/vdb', '/dev/sdb'])177 self.assertEquals(result, ['/dev/vdb', '/dev/sdb'])
165178
179 @patch.object(swift_utils, 'check_output')
180 @patch.object(swift_utils, 'find_block_devices')
181 @patch.object(swift_utils, 'ensure_block_device')
182 def test_determine_block_device_guess_dev_not_eligable(self, _ensure,
183 _find,
184 _check_output):
185 "Devices not mounted under /srv/node/ should not be returned"
186 def _findmnt(cmd):
187 dev = cmd[1].split('/')[-1]
188 mnt_point = '/'
189 return FINDMNT_FOUND_TEMPLATE.format(mnt_point, dev)
190 _check_output.side_effect = _findmnt
191 _ensure.side_effect = self._fake_ensure
192 self.test_config.set('block-device', 'guess')
193 _find.return_value = ['/dev/vdb']
194 result = swift_utils.determine_block_devices()
195 self.assertTrue(_find.called)
196 self.assertEquals(result, [])
197
166 def test_mkfs_xfs(self):198 def test_mkfs_xfs(self):
167 swift_utils.mkfs_xfs('/dev/sdb')199 swift_utils.mkfs_xfs('/dev/sdb')
168 self.check_call.assert_called_with(200 self.check_call.assert_called_with(

Subscribers

People subscribed via source and target branches