Merge lp:~niedbalski/charm-helpers/fix-lp1510666 into lp:charm-helpers

Proposed by Jorge Niedbalski
Status: Merged
Merged at revision: 481
Proposed branch: lp:~niedbalski/charm-helpers/fix-lp1510666
Merge into: lp:charm-helpers
Diff against target: 32 lines (+17/-0)
2 files modified
charmhelpers/contrib/storage/linux/loopback.py (+10/-0)
tests/contrib/storage/test_linux_storage_loopback.py (+7/-0)
To merge this branch: bzr merge lp:~niedbalski/charm-helpers/fix-lp1510666
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+276451@code.launchpad.net

Description of the change

Adds the is_mapped_loopback_device method for fixing LP: #1510666

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 2015-01-22 06:06:03 +0000
3+++ charmhelpers/contrib/storage/linux/loopback.py 2015-11-02 19:48:58 +0000
4@@ -76,3 +76,13 @@
5 check_call(cmd)
6
7 return create_loopback(path)
8+
9+
10+def is_mapped_loopback_device(device):
11+ """
12+ Checks if a given device name is an existing/mapped loopback device.
13+ :param device: str: Full path to the device (eg, /dev/loop1).
14+ :returns: str: Path to the backing file if is a loopback device
15+ empty string otherwise
16+ """
17+ return loopback_devices().get(device, "")
18
19=== modified file 'tests/contrib/storage/test_linux_storage_loopback.py'
20--- tests/contrib/storage/test_linux_storage_loopback.py 2013-07-18 00:46:25 +0000
21+++ tests/contrib/storage/test_linux_storage_loopback.py 2015-11-02 19:48:58 +0000
22@@ -73,3 +73,10 @@
23 result = loopback.create_loopback('/tmp/foo')
24 check_call.assert_called_with(['losetup', '--find', '/tmp/foo'])
25 self.assertEquals(result, '/dev/loop0')
26+
27+ @patch.object(loopback, 'loopback_devices')
28+ def test_create_is_mapped_loopback_device(self, devs):
29+ devs.return_value = {'/dev/loop0': "/tmp/manco"}
30+ self.assertEquals(loopback.is_mapped_loopback_device("/dev/loop0"),
31+ "/tmp/manco")
32+ self.assertFalse(loopback.is_mapped_loopback_device("/dev/loop1"))

Subscribers

People subscribed via source and target branches