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
=== modified file 'charmhelpers/contrib/storage/linux/loopback.py'
--- charmhelpers/contrib/storage/linux/loopback.py 2015-01-22 06:06:03 +0000
+++ charmhelpers/contrib/storage/linux/loopback.py 2015-11-02 19:48:58 +0000
@@ -76,3 +76,13 @@
76 check_call(cmd)76 check_call(cmd)
7777
78 return create_loopback(path)78 return create_loopback(path)
79
80
81def is_mapped_loopback_device(device):
82 """
83 Checks if a given device name is an existing/mapped loopback device.
84 :param device: str: Full path to the device (eg, /dev/loop1).
85 :returns: str: Path to the backing file if is a loopback device
86 empty string otherwise
87 """
88 return loopback_devices().get(device, "")
7989
=== modified file 'tests/contrib/storage/test_linux_storage_loopback.py'
--- tests/contrib/storage/test_linux_storage_loopback.py 2013-07-18 00:46:25 +0000
+++ tests/contrib/storage/test_linux_storage_loopback.py 2015-11-02 19:48:58 +0000
@@ -73,3 +73,10 @@
73 result = loopback.create_loopback('/tmp/foo')73 result = loopback.create_loopback('/tmp/foo')
74 check_call.assert_called_with(['losetup', '--find', '/tmp/foo'])74 check_call.assert_called_with(['losetup', '--find', '/tmp/foo'])
75 self.assertEquals(result, '/dev/loop0')75 self.assertEquals(result, '/dev/loop0')
76
77 @patch.object(loopback, 'loopback_devices')
78 def test_create_is_mapped_loopback_device(self, devs):
79 devs.return_value = {'/dev/loop0': "/tmp/manco"}
80 self.assertEquals(loopback.is_mapped_loopback_device("/dev/loop0"),
81 "/tmp/manco")
82 self.assertFalse(loopback.is_mapped_loopback_device("/dev/loop1"))

Subscribers

People subscribed via source and target branches