Merge lp:~gandelman-a/charm-helpers/loopback_fix into lp:charm-helpers

Proposed by Adam Gandelman
Status: Merged
Merged at revision: 61
Proposed branch: lp:~gandelman-a/charm-helpers/loopback_fix
Merge into: lp:charm-helpers
Diff against target: 38 lines (+11/-6)
2 files modified
charmhelpers/contrib/storage/linux/loopback.py (+5/-2)
tests/contrib/storage/test_linux_storage_loopback.py (+6/-4)
To merge this branch: bzr merge lp:~gandelman-a/charm-helpers/loopback_fix
Reviewer Review Type Date Requested Status
Charm Helper Maintainers Pending
Review via email: mp+175710@code.launchpad.net

Commit message

contrib.storage.linux.loopback: Fix create_loopback() to actually return full path of new device.

Description of the change

create_loopback() is expected to return the full path of a newly created loopback. 'losetup --find' does not return any output on creation, so inspect loopback_devices() after creation and actually return path.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/storage/linux/loopback.py'
2--- charmhelpers/contrib/storage/linux/loopback.py 2013-06-24 22:39:29 +0000
3+++ charmhelpers/contrib/storage/linux/loopback.py 2013-07-19 00:23:39 +0000
4@@ -35,8 +35,11 @@
5
6 :returns: str: Full path to new loopback device (eg, /dev/loop0)
7 '''
8- cmd = ['losetup', '--find', file_path]
9- return check_output(cmd).strip()
10+ file_path = os.path.abspath(file_path)
11+ check_call(['losetup', '--find', file_path])
12+ for d, f in loopback_devices().iteritems():
13+ if f == file_path:
14+ return d
15
16
17 def ensure_loopback_device(path, size):
18
19=== modified file 'tests/contrib/storage/test_linux_storage_loopback.py'
20--- tests/contrib/storage/test_linux_storage_loopback.py 2013-06-24 22:39:29 +0000
21+++ tests/contrib/storage/test_linux_storage_loopback.py 2013-07-19 00:23:39 +0000
22@@ -64,10 +64,12 @@
23 check_call.assert_called_with(['truncate', '--size', '15G',
24 '/tmp/foo.img'])
25
26- def test_create_loopback(self):
27+ @patch.object(loopback, 'loopback_devices')
28+ def test_create_loopback(self, _devs):
29 '''It corectly calls losetup to create a loopback device'''
30- with patch(STORAGE_LINUX_LOOPBACK + '.check_output') as check_output:
31- check_output.return_value = '/dev/loop0'
32+ _devs.return_value = {'/dev/loop0': '/tmp/foo'}
33+ with patch(STORAGE_LINUX_LOOPBACK + '.check_call') as check_call:
34+ check_call.return_value = ''
35 result = loopback.create_loopback('/tmp/foo')
36- check_output.assert_called_with(['losetup', '--find', '/tmp/foo'])
37+ check_call.assert_called_with(['losetup', '--find', '/tmp/foo'])
38 self.assertEquals(result, '/dev/loop0')

Subscribers

People subscribed via source and target branches