Merge lp:~tribaal/charm-helpers/stable-device-mounted-accepts-partitions into lp:~openstack-charmers/charm-helpers/stable-1604

Proposed by Chris Glass
Status: Merged
Merged at revision: 158
Proposed branch: lp:~tribaal/charm-helpers/stable-device-mounted-accepts-partitions
Merge into: lp:~openstack-charmers/charm-helpers/stable-1604
Diff against target: 68 lines (+45/-1)
2 files modified
charmhelpers/contrib/storage/linux/utils.py (+3/-0)
tests/contrib/storage/test_linux_storage_utils.py (+42/-1)
To merge this branch: bzr merge lp:~tribaal/charm-helpers/stable-device-mounted-accepts-partitions
Reviewer Review Type Date Requested Status
OpenStack Charmers Pending
Review via email: mp+230598@code.launchpad.net

Description of the change

This MP is to propagate the is_device_mounted changes from trunk to the stable branch.

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/utils.py'
2--- charmhelpers/contrib/storage/linux/utils.py 2014-05-13 16:18:57 +0000
3+++ charmhelpers/contrib/storage/linux/utils.py 2014-08-13 09:45:34 +0000
4@@ -45,5 +45,8 @@
5 :returns: boolean: True if the path represents a mounted device, False if
6 it doesn't.
7 '''
8+ is_partition = bool(re.search(r".*[0-9]+\b", device))
9 out = check_output(['mount'])
10+ if is_partition:
11+ return bool(re.search(device + r"\b", out))
12 return bool(re.search(device + r"[0-9]+\b", out))
13
14=== modified file 'tests/contrib/storage/test_linux_storage_utils.py'
15--- tests/contrib/storage/test_linux_storage_utils.py 2014-05-06 21:25:24 +0000
16+++ tests/contrib/storage/test_linux_storage_utils.py 2014-08-13 09:45:34 +0000
17@@ -55,9 +55,50 @@
18 self.assertTrue(result)
19
20 @patch(STORAGE_LINUX_UTILS + '.check_output')
21+ def test_is_device_mounted_partition(self, check_output):
22+ '''It detects mounted partitions as mounted.'''
23+ check_output.return_value = (
24+ "/dev/sda1 on / type ext4 (rw,errors=remount-ro)\n")
25+ result = storage_utils.is_device_mounted('/dev/sda1')
26+ self.assertTrue(result)
27+
28+ @patch(STORAGE_LINUX_UTILS + '.check_output')
29+ def test_is_device_mounted_partition_with_device(self, check_output):
30+ '''It detects mounted devices as mounted if "mount" shows only a
31+ partition as mounted.'''
32+ check_output.return_value = (
33+ "/dev/sda1 on / type ext4 (rw,errors=remount-ro)\n")
34+ result = storage_utils.is_device_mounted('/dev/sda')
35+ self.assertTrue(result)
36+
37+ @patch(STORAGE_LINUX_UTILS + '.check_output')
38 def test_is_device_mounted_not_mounted(self, check_output):
39- '''It detects unmounted devices as mounted.'''
40+ '''It detects unmounted devices as not mounted.'''
41 check_output.return_value = (
42 "/dev/foo on / type ext4 (rw,errors=remount-ro)\n")
43 result = storage_utils.is_device_mounted('/dev/sda')
44 self.assertFalse(result)
45+
46+ @patch(STORAGE_LINUX_UTILS + '.check_output')
47+ def test_is_device_mounted_not_mounted_partition(self, check_output):
48+ '''It detects unmounted partitions as not mounted.'''
49+ check_output.return_value = (
50+ "/dev/foo on / type ext4 (rw,errors=remount-ro)\n")
51+ result = storage_utils.is_device_mounted('/dev/sda1')
52+ self.assertFalse(result)
53+
54+ @patch(STORAGE_LINUX_UTILS + '.check_output')
55+ def test_is_device_mounted_cciss(self, check_output):
56+ '''It detects mounted cciss partitions as mounted.'''
57+ check_output.return_value = (
58+ "/dev/cciss/c0d0 on / type ext4 (rw,errors=remount-ro)\n")
59+ result = storage_utils.is_device_mounted('/dev/cciss/c0d0')
60+ self.assertTrue(result)
61+
62+ @patch(STORAGE_LINUX_UTILS + '.check_output')
63+ def test_is_device_mounted_cciss_not_mounted(self, check_output):
64+ '''It detects unmounted cciss partitions as not mounted.'''
65+ check_output.return_value = (
66+ "/dev/cciss/c0d1 on / type ext4 (rw,errors=remount-ro)\n")
67+ result = storage_utils.is_device_mounted('/dev/cciss/c0d0')
68+ self.assertFalse(result)

Subscribers

People subscribed via source and target branches