Merge lp:~chris.macnaughton/charm-helpers/use-lsblk-to-check-mount into lp:charm-helpers

Proposed by Chris MacNaughton
Status: Merged
Merged at revision: 570
Proposed branch: lp:~chris.macnaughton/charm-helpers/use-lsblk-to-check-mount
Merge into: lp:charm-helpers
Diff against target: 92 lines (+13/-13)
2 files modified
charmhelpers/contrib/storage/linux/utils.py (+5/-5)
tests/contrib/storage/test_linux_storage_utils.py (+8/-8)
To merge this branch: bzr merge lp:~chris.macnaughton/charm-helpers/use-lsblk-to-check-mount
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+292199@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Chris Holcombe (xfactor973) wrote :

+1 from me. This looks good

539. By Chris MacNaughton

Return false in the case where lsblk gives an error

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/storage/linux/utils.py'
--- charmhelpers/contrib/storage/linux/utils.py 2015-08-07 09:00:30 +0000
+++ charmhelpers/contrib/storage/linux/utils.py 2016-04-19 15:19:17 +0000
@@ -64,8 +64,8 @@
64 :returns: boolean: True if the path represents a mounted device, False if64 :returns: boolean: True if the path represents a mounted device, False if
65 it doesn't.65 it doesn't.
66 '''66 '''
67 is_partition = bool(re.search(r".*[0-9]+\b", device))67 try:
68 out = check_output(['mount']).decode('UTF-8')68 out = check_output(['lsblk', '-P', device]).decode('UTF-8')
69 if is_partition:69 except:
70 return bool(re.search(device + r"\b", out))70 return False
71 return bool(re.search(device + r"[0-9]*\b", out))71 return bool(re.search(r'MOUNTPOINT=".+"', out))
7272
=== modified file 'tests/contrib/storage/test_linux_storage_utils.py'
--- tests/contrib/storage/test_linux_storage_utils.py 2015-11-02 23:06:58 +0000
+++ tests/contrib/storage/test_linux_storage_utils.py 2016-04-19 15:19:17 +0000
@@ -51,7 +51,7 @@
51 def test_is_device_mounted(self, check_output):51 def test_is_device_mounted(self, check_output):
52 """It detects mounted devices as mounted."""52 """It detects mounted devices as mounted."""
53 check_output.return_value = (53 check_output.return_value = (
54 b"/dev/sda1 on / type ext4 (rw,errors=remount-ro)\n")54 b'NAME="sda" MAJ:MIN="8:16" RM="0" SIZE="238.5G" RO="0" TYPE="disk" MOUNTPOINT="/tmp"\n')
55 result = storage_utils.is_device_mounted('/dev/sda')55 result = storage_utils.is_device_mounted('/dev/sda')
56 self.assertTrue(result)56 self.assertTrue(result)
5757
@@ -59,7 +59,7 @@
59 def test_is_device_mounted_partition(self, check_output):59 def test_is_device_mounted_partition(self, check_output):
60 """It detects mounted partitions as mounted."""60 """It detects mounted partitions as mounted."""
61 check_output.return_value = (61 check_output.return_value = (
62 b"/dev/sda1 on / type ext4 (rw,errors=remount-ro)\n")62 b'NAME="sda1" MAJ:MIN="8:16" RM="0" SIZE="238.5G" RO="0" TYPE="disk" MOUNTPOINT="/tmp"\n')
63 result = storage_utils.is_device_mounted('/dev/sda1')63 result = storage_utils.is_device_mounted('/dev/sda1')
64 self.assertTrue(result)64 self.assertTrue(result)
6565
@@ -68,7 +68,7 @@
68 """It detects mounted devices as mounted if "mount" shows only a68 """It detects mounted devices as mounted if "mount" shows only a
69 partition as mounted."""69 partition as mounted."""
70 check_output.return_value = (70 check_output.return_value = (
71 b"/dev/sda1 on / type ext4 (rw,errors=remount-ro)\n")71 b'NAME="sda1" MAJ:MIN="8:16" RM="0" SIZE="238.5G" RO="0" TYPE="disk" MOUNTPOINT="/tmp"\n')
72 result = storage_utils.is_device_mounted('/dev/sda')72 result = storage_utils.is_device_mounted('/dev/sda')
73 self.assertTrue(result)73 self.assertTrue(result)
7474
@@ -76,7 +76,7 @@
76 def test_is_device_mounted_not_mounted(self, check_output):76 def test_is_device_mounted_not_mounted(self, check_output):
77 """It detects unmounted devices as not mounted."""77 """It detects unmounted devices as not mounted."""
78 check_output.return_value = (78 check_output.return_value = (
79 b"/dev/foo on / type ext4 (rw,errors=remount-ro)\n")79 b'NAME="sda" MAJ:MIN="8:16" RM="0" SIZE="238.5G" RO="0" TYPE="disk" MOUNTPOINT=""\n')
80 result = storage_utils.is_device_mounted('/dev/sda')80 result = storage_utils.is_device_mounted('/dev/sda')
81 self.assertFalse(result)81 self.assertFalse(result)
8282
@@ -84,7 +84,7 @@
84 def test_is_device_mounted_not_mounted_partition(self, check_output):84 def test_is_device_mounted_not_mounted_partition(self, check_output):
85 """It detects unmounted partitions as not mounted."""85 """It detects unmounted partitions as not mounted."""
86 check_output.return_value = (86 check_output.return_value = (
87 b"/dev/foo on / type ext4 (rw,errors=remount-ro)\n")87 b'NAME="sda" MAJ:MIN="8:16" RM="0" SIZE="238.5G" RO="0" TYPE="disk" MOUNTPOINT=""\n')
88 result = storage_utils.is_device_mounted('/dev/sda1')88 result = storage_utils.is_device_mounted('/dev/sda1')
89 self.assertFalse(result)89 self.assertFalse(result)
9090
@@ -92,7 +92,7 @@
92 def test_is_device_mounted_full_disks(self, check_output):92 def test_is_device_mounted_full_disks(self, check_output):
93 """It detects mounted full disks as mounted."""93 """It detects mounted full disks as mounted."""
94 check_output.return_value = (94 check_output.return_value = (
95 b"/dev/sda on / type ext4 (rw,errors=remount-ro)\n")95 b'NAME="sda" MAJ:MIN="8:16" RM="0" SIZE="238.5G" RO="0" TYPE="disk" MOUNTPOINT="/tmp"\n')
96 result = storage_utils.is_device_mounted('/dev/sda')96 result = storage_utils.is_device_mounted('/dev/sda')
97 self.assertTrue(result)97 self.assertTrue(result)
9898
@@ -100,7 +100,7 @@
100 def test_is_device_mounted_cciss(self, check_output):100 def test_is_device_mounted_cciss(self, check_output):
101 """It detects mounted cciss partitions as mounted."""101 """It detects mounted cciss partitions as mounted."""
102 check_output.return_value = (102 check_output.return_value = (
103 b"/dev/cciss/c0d0 on / type ext4 (rw,errors=remount-ro)\n")103 b'NAME="cciss!c0d0" MAJ:MIN="104:0" RM="0" SIZE="273.3G" RO="0" TYPE="disk" MOUNTPOINT="/root"\n')
104 result = storage_utils.is_device_mounted('/dev/cciss/c0d0')104 result = storage_utils.is_device_mounted('/dev/cciss/c0d0')
105 self.assertTrue(result)105 self.assertTrue(result)
106106
@@ -108,6 +108,6 @@
108 def test_is_device_mounted_cciss_not_mounted(self, check_output):108 def test_is_device_mounted_cciss_not_mounted(self, check_output):
109 """It detects unmounted cciss partitions as not mounted."""109 """It detects unmounted cciss partitions as not mounted."""
110 check_output.return_value = (110 check_output.return_value = (
111 b"/dev/cciss/c0d1 on / type ext4 (rw,errors=remount-ro)\n")111 b'NAME="cciss!c0d0" MAJ:MIN="104:0" RM="0" SIZE="273.3G" RO="0" TYPE="disk" MOUNTPOINT=""\n')
112 result = storage_utils.is_device_mounted('/dev/cciss/c0d0')112 result = storage_utils.is_device_mounted('/dev/cciss/c0d0')
113 self.assertFalse(result)113 self.assertFalse(result)

Subscribers

People subscribed via source and target branches