~charm-helpers/charm-helpers/devel

« back to all changes in this revision

Viewing changes to tests/contrib/storage/test_linux_storage_utils.py

  • Committer: James Page
  • Date: 2016-04-20 12:04:21 UTC
  • mfrom: (535.2.2 c-h)
  • Revision ID: james.page@ubuntu.com-20160420120421-vpn364sxk2y3po55
Switch is_device_mounted to use lsblk

This will correct detect a wider range of 'is use' states compared
to parsing the output of /proc/mounts, including block devices that
are part of LVM volumes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    def test_is_device_mounted(self, check_output):
52
52
        """It detects mounted devices as mounted."""
53
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
55
        result = storage_utils.is_device_mounted('/dev/sda')
56
56
        self.assertTrue(result)
57
57
 
59
59
    def test_is_device_mounted_partition(self, check_output):
60
60
        """It detects mounted partitions as mounted."""
61
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
63
        result = storage_utils.is_device_mounted('/dev/sda1')
64
64
        self.assertTrue(result)
65
65
 
68
68
        """It detects mounted devices as mounted if "mount" shows only a
69
69
        partition as mounted."""
70
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
72
        result = storage_utils.is_device_mounted('/dev/sda')
73
73
        self.assertTrue(result)
74
74
 
76
76
    def test_is_device_mounted_not_mounted(self, check_output):
77
77
        """It detects unmounted devices as not mounted."""
78
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
80
        result = storage_utils.is_device_mounted('/dev/sda')
81
81
        self.assertFalse(result)
82
82
 
84
84
    def test_is_device_mounted_not_mounted_partition(self, check_output):
85
85
        """It detects unmounted partitions as not mounted."""
86
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
88
        result = storage_utils.is_device_mounted('/dev/sda1')
89
89
        self.assertFalse(result)
90
90
 
92
92
    def test_is_device_mounted_full_disks(self, check_output):
93
93
        """It detects mounted full disks as mounted."""
94
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
96
        result = storage_utils.is_device_mounted('/dev/sda')
97
97
        self.assertTrue(result)
98
98
 
100
100
    def test_is_device_mounted_cciss(self, check_output):
101
101
        """It detects mounted cciss partitions as mounted."""
102
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
104
        result = storage_utils.is_device_mounted('/dev/cciss/c0d0')
105
105
        self.assertTrue(result)
106
106
 
108
108
    def test_is_device_mounted_cciss_not_mounted(self, check_output):
109
109
        """It detects unmounted cciss partitions as not mounted."""
110
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
112
        result = storage_utils.is_device_mounted('/dev/cciss/c0d0')
113
113
        self.assertFalse(result)