storage: yapf formatting

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2017-12-31 21:53:37 +05:30 committed by James Valleroy
parent 67cb367838
commit 407f5fb6ac
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
""" """
Test module for storage module operations. Test module for storage module operations.
""" """
@ -25,7 +24,6 @@ import subprocess
import tempfile import tempfile
import unittest import unittest
euid = os.geteuid() euid = os.geteuid()
@ -39,6 +37,7 @@ def _get_partition_device(device, partition_number):
class Disk(): class Disk():
"""Context manager to create/destroy a disk.""" """Context manager to create/destroy a disk."""
def __init__(self, test_case, size, disk_info, file_system_info=None): def __init__(self, test_case, size, disk_info, file_system_info=None):
"""Initialize the context manager object.""" """Initialize the context manager object."""
self.size = size self.size = size
@ -122,13 +121,14 @@ class Disk():
class TestActions(unittest.TestCase): class TestActions(unittest.TestCase):
"""Test all actions related to storage.""" """Test all actions related to storage."""
@unittest.skipUnless(euid == 0, 'Needs to be root') @unittest.skipUnless(euid == 0, 'Needs to be root')
def test_simple_case(self): def test_simple_case(self):
"""Test a simple with no complications""" """Test a simple with no complications"""
disk_info = ['mktable msdos', disk_info = [
'mkpart primary btrfs 1 8', 'mktable msdos', 'mkpart primary btrfs 1 8',
'mkpart primary btrfs 9 16', 'mkpart primary btrfs 9 16', 'mkpart primary btrfs 20 200'
'mkpart primary btrfs 20 200'] ]
with Disk(self, 256, disk_info, [(3, 'btrfs')]): with Disk(self, 256, disk_info, [(3, 'btrfs')]):
# No free space # No free space
self.assert_free_space(1, space=False) self.assert_free_space(1, space=False)
@ -144,10 +144,10 @@ class TestActions(unittest.TestCase):
@unittest.skipUnless(euid == 0, 'Needs to be root') @unittest.skipUnless(euid == 0, 'Needs to be root')
def test_extended_partition_free_space(self): def test_extended_partition_free_space(self):
"""Test that free space does not show up when outside extended.""" """Test that free space does not show up when outside extended."""
disk_info = ['mktable msdos', disk_info = [
'mkpart primary 1 8', 'mktable msdos', 'mkpart primary 1 8', 'mkpart extended 8 32',
'mkpart extended 8 32', 'mkpart logical 9 16'
'mkpart logical 9 16'] ]
with Disk(self, 64, disk_info): with Disk(self, 64, disk_info):
self.assert_free_space(5, space=False) self.assert_free_space(5, space=False)
self.expand_partition(5, success=False) self.expand_partition(5, success=False)
@ -156,12 +156,11 @@ class TestActions(unittest.TestCase):
def test_gpt_partition_free_space(self): def test_gpt_partition_free_space(self):
"""Test that GPT partitions can be expanded.""" """Test that GPT partitions can be expanded."""
# Specifically check for partition number > 4 # Specifically check for partition number > 4
disk_info = ['mktable gpt', disk_info = [
'mkpart primary 1 4', 'mktable gpt', 'mkpart primary 1 4', 'mkpart extended 4 8',
'mkpart extended 4 8', 'mkpart extended 8 12', 'mkpart extended 12 16',
'mkpart extended 8 12', 'mkpart extended 16 160'
'mkpart extended 12 16', ]
'mkpart extended 16 160']
with Disk(self, 256, disk_info, [(5, 'btrfs')]): with Disk(self, 256, disk_info, [(5, 'btrfs')]):
self.assert_free_space(5, space=True) self.assert_free_space(5, space=True)
self.expand_partition(5, success=True) self.expand_partition(5, success=True)
@ -170,8 +169,7 @@ class TestActions(unittest.TestCase):
@unittest.skipUnless(euid == 0, 'Needs to be root') @unittest.skipUnless(euid == 0, 'Needs to be root')
def test_unsupported_file_system(self): def test_unsupported_file_system(self):
"""Test that free space after unknown file system does not count.""" """Test that free space after unknown file system does not count."""
disk_info = ['mktable msdos', disk_info = ['mktable msdos', 'mkpart primary 1 8']
'mkpart primary 1 8']
with Disk(self, 32, disk_info): with Disk(self, 32, disk_info):
self.assert_free_space(1, space=False) self.assert_free_space(1, space=False)
self.expand_partition(1, success=False) self.expand_partition(1, success=False)
@ -179,8 +177,7 @@ class TestActions(unittest.TestCase):
@unittest.skipUnless(euid == 0, 'Needs to be root') @unittest.skipUnless(euid == 0, 'Needs to be root')
def test_btrfs_expansion(self): def test_btrfs_expansion(self):
"""Test that btrfs file system can be expanded.""" """Test that btrfs file system can be expanded."""
disk_info = ['mktable msdos', disk_info = ['mktable msdos', 'mkpart primary btrfs 1 200']
'mkpart primary btrfs 1 200']
with Disk(self, 256, disk_info, [(1, 'btrfs')]): with Disk(self, 256, disk_info, [(1, 'btrfs')]):
self.expand_partition(1, success=True) self.expand_partition(1, success=True)
self.expand_partition(1, success=False) self.expand_partition(1, success=False)
@ -189,8 +186,7 @@ class TestActions(unittest.TestCase):
@unittest.skipUnless(euid == 0, 'Needs to be root') @unittest.skipUnless(euid == 0, 'Needs to be root')
def test_ext4_expansion(self): def test_ext4_expansion(self):
"""Test that ext4 file system can be expanded.""" """Test that ext4 file system can be expanded."""
disk_info = ['mktable msdos', disk_info = ['mktable msdos', 'mkpart primary ext4 1 64']
'mkpart primary ext4 1 64']
with Disk(self, 128, disk_info, [(1, 'ext4')]): with Disk(self, 128, disk_info, [(1, 'ext4')]):
self.expand_partition(1, success=True) self.expand_partition(1, success=True)
self.expand_partition(1, success=False) self.expand_partition(1, success=False)
@ -199,7 +195,8 @@ class TestActions(unittest.TestCase):
def assert_free_space(self, partition_number, space=True): def assert_free_space(self, partition_number, space=True):
"""Verify that free is available/not available after a parition.""" """Verify that free is available/not available after a parition."""
device = _get_partition_device(self.device, partition_number) device = _get_partition_device(self.device, partition_number)
result = self.run_action(['storage', 'is-partition-expandable', device]) result = self.run_action(
['storage', 'is-partition-expandable', device])
self.assertEqual(result, space) self.assertEqual(result, space)
def expand_partition(self, partition_number, success=True): def expand_partition(self, partition_number, success=True):
@ -225,8 +222,10 @@ class TestActions(unittest.TestCase):
def assert_aligned(self, partition_number): def assert_aligned(self, partition_number):
"""Test that partition is optimally aligned.""" """Test that partition is optimally aligned."""
subprocess.run(['parted', '--script', self.device, 'align-check', subprocess.run([
'opti', str(partition_number)]) 'parted', '--script', self.device, 'align-check', 'opti',
str(partition_number)
])
def assert_btrfs_file_system_healthy(self, partition_number): def assert_btrfs_file_system_healthy(self, partition_number):
"""Perform a successful ext4 file system check.""" """Perform a successful ext4 file system check."""