[blivet:master 1/2] Further abstract loopbackedtestcase on block_size.

Vratislav Podzimek vpodzime at redhat.com
Wed Oct 1 09:47:46 UTC 2014


On Tue, 2014-09-30 at 09:02 -0400, mulhern wrote:
> Also, have deviceSpec contain a list of actual Sizes() instead of counts of
> unchangeable size blocks and do the math to infer block size
> and number of blocks to pass to makeLoopDev.
> 
> Change any overrides of deviceSpec in subclasses appropriately.
> 
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
>  tests/devicelibs_test/btrfs_test.py              |  3 ++-
>  tests/devicelibs_test/mdraid_interrogate_test.py |  5 +++--
>  tests/devicelibs_test/mdraid_test.py             |  6 +++---
>  tests/formats_test/fslabeling.py                 |  3 ++-
>  tests/formats_test/selinux_test.py               |  3 ++-
>  tests/loopbackedtestcase.py                      | 27 +++++++++++++++---------
>  6 files changed, 29 insertions(+), 18 deletions(-)
> 
> diff --git a/tests/devicelibs_test/btrfs_test.py b/tests/devicelibs_test/btrfs_test.py
> index dcf1bcd..91950d2 100755
> --- a/tests/devicelibs_test/btrfs_test.py
> +++ b/tests/devicelibs_test/btrfs_test.py
> @@ -7,6 +7,7 @@ import unittest
>  
>  import blivet.devicelibs.btrfs as btrfs
>  from blivet.errors import BTRFSError
> +from blivet.size import Size
>  
>  from tests import loopbackedtestcase
>  
> @@ -164,7 +165,7 @@ class BTRFSAsRootTestCase2(BTRFSMountDevice):
>  class BTRFSAsRootTestCase3(loopbackedtestcase.LoopBackedTestCase):
>  
>      def __init__(self, methodName='runTest'):
> -        super(BTRFSAsRootTestCase3, self).__init__(methodName=methodName, deviceSpec=[8192])
> +        super(BTRFSAsRootTestCase3, self).__init__(methodName=methodName, deviceSpec=[Size("8192 KiB")])
>  
>      def testSmallDevice(self):
>          """ Creation of a smallish device will result in an error if the
> diff --git a/tests/devicelibs_test/mdraid_interrogate_test.py b/tests/devicelibs_test/mdraid_interrogate_test.py
> index 2178d79..034c929 100755
> --- a/tests/devicelibs_test/mdraid_interrogate_test.py
> +++ b/tests/devicelibs_test/mdraid_interrogate_test.py
> @@ -8,6 +8,7 @@ import blivet.devicelibs.mdraid as mdraid
>  
>  from . import mdraid_test
>  from blivet.errors import MDRaidError
> +from blivet.size import Size
>  
>  class MDRaidInterrogateTestCase(mdraid_test.MDRaidAsRootTestCase):
>  
> @@ -33,7 +34,7 @@ class MDRaidInterrogateTestCase(mdraid_test.MDRaidAsRootTestCase):
>  class MDExamineTestCase(MDRaidInterrogateTestCase):
>  
>      def __init__(self, methodName='runTest'):
> -        super(MDExamineTestCase, self).__init__(methodName=methodName, deviceSpec=[102400, 102400, 102400])
> +        super(MDExamineTestCase, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB") for _ in range(3)])
>  
>      names_0 = [
>        'DEVICE',
> @@ -130,7 +131,7 @@ class MDExamineTestCase(MDRaidInterrogateTestCase):
>  class MDDetailTestCase(MDRaidInterrogateTestCase):
>  
>      def __init__(self, methodName='runTest'):
> -        super(MDDetailTestCase, self).__init__(methodName=methodName, deviceSpec=[102400, 102400, 102400])
> +        super(MDDetailTestCase, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB") for _ in range(3)])
>  
>      names = [
>          'ACTIVE DEVICES',
> diff --git a/tests/devicelibs_test/mdraid_test.py b/tests/devicelibs_test/mdraid_test.py
> index 380d853..687ec12 100755
> --- a/tests/devicelibs_test/mdraid_test.py
> +++ b/tests/devicelibs_test/mdraid_test.py
> @@ -84,7 +84,7 @@ class JustAddTestCaseFactory(TestCaseFactory):
>      def makeClass(name, level):
>  
>          def __init__(self, methodName='runTest'):
> -            super(self.__class__, self).__init__(methodName=methodName, deviceSpec=[102400, 102400, 102400, 102400, 102400])
> +            super(self.__class__, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB") for _ in range(5)])
>              self.longMessage = True
>  
>          def testAdd(self):
> @@ -127,7 +127,7 @@ class GrowTestCaseFactory(object):
>      def makeClass(name, level):
>  
>          def __init__(self, methodName='runTest'):
> -            super(self.__class__, self).__init__(methodName=methodName, deviceSpec=[102400, 102400, 102400, 102400, 102400, 102400])
> +            super(self.__class__, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB") for _ in range(6)])
>              self.longMessage = True
>  
>          def testGrow(self):
> @@ -210,7 +210,7 @@ for l in levels:
>  class SimpleRaidTest(MDRaidAsRootTestCase):
>  
>      def __init__(self, methodName='runTest'):
> -        super(SimpleRaidTest, self).__init__(methodName=methodName, deviceSpec=[102400, 102400, 102400])
> +        super(SimpleRaidTest, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB") for _ in range(3)])
>          self.longMessage = True
>  
>      def testMDRaidAsRoot(self):
> diff --git a/tests/formats_test/fslabeling.py b/tests/formats_test/fslabeling.py
> index 22d74ee..c35a7b0 100644
> --- a/tests/formats_test/fslabeling.py
> +++ b/tests/formats_test/fslabeling.py
> @@ -5,6 +5,7 @@ from six import add_metaclass
>  
>  from tests import loopbackedtestcase
>  from blivet.errors import FSError
> +from blivet.size import Size
>  
>  @add_metaclass(abc.ABCMeta)
>  class LabelingAsRoot(loopbackedtestcase.LoopBackedTestCase):
> @@ -21,7 +22,7 @@ class LabelingAsRoot(loopbackedtestcase.LoopBackedTestCase):
>         doc="A label which is invalid for this filesystem.")
>  
>      def __init__(self, methodName='runTest'):
> -        super(LabelingAsRoot, self).__init__(methodName=methodName, deviceSpec=[102400])
> +        super(LabelingAsRoot, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB")])
>  
>      def setUp(self):
>          an_fs = self._fs_class()
> diff --git a/tests/formats_test/selinux_test.py b/tests/formats_test/selinux_test.py
> index 00771ad..14433da 100755
> --- a/tests/formats_test/selinux_test.py
> +++ b/tests/formats_test/selinux_test.py
> @@ -7,13 +7,14 @@ import unittest
>  import blivet
>  from tests import loopbackedtestcase
>  import blivet.formats.fs as fs
> +from blivet.size import Size
>  
>  class SELinuxContextTestCase(loopbackedtestcase.LoopBackedTestCase):
>      """Testing SELinux contexts.
>      """
>  
>      def __init__(self, methodName='runTest'):
> -        super(SELinuxContextTestCase, self).__init__(methodName=methodName, deviceSpec=[102400])
> +        super(SELinuxContextTestCase, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB")])
>  
>      def testMountingExt2FS(self):
>          an_fs = fs.Ext2FS(device=self.loopDevices[0], label="test")
> diff --git a/tests/loopbackedtestcase.py b/tests/loopbackedtestcase.py
> index cd09bf7..6b996f7 100644
> --- a/tests/loopbackedtestcase.py
> +++ b/tests/loopbackedtestcase.py
> @@ -2,16 +2,18 @@ import unittest
>  import os
>  import subprocess
>  
> +from blivet.size import Size
>  
> -def makeLoopDev(device_name, file_name, num_blocks=102400):
> +def makeLoopDev(device_name, file_name, num_blocks=102400, block_size=1024):
>      """ Set up a loop device with a backing store.
>  
>          :param str device_name: the path of the loop device
>          :param str file_name: the path of the backing file
>          :param int num_blocks: the size of file_name in number of blocks
> +        :param int block_size: the number of bytes in a block
>      """
>      proc = subprocess.Popen(["dd", "if=/dev/zero", "of=%s" % file_name,
> -                             "bs=1024", "count=%d" % num_blocks],
> +                             "bs=%d" % block_size, "count=%d" % num_blocks],
>                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>      while True:
>          proc.communicate()
> @@ -67,33 +69,38 @@ def getFreeLoopDev():
>  @unittest.skipUnless(os.geteuid() == 0, "requires root privileges")
>  class LoopBackedTestCase(unittest.TestCase):
>  
> -    DEFAULT_STORE_SIZE = 102400
> +    DEFAULT_BLOCK_SIZE = Size(1024)
I think 'Size("1 KiB")' would be nicer here.

> +    DEFAULT_STORE_SIZE = Size("100 MiB")
>      _DEFAULT_DEVICE_SPEC = [DEFAULT_STORE_SIZE, DEFAULT_STORE_SIZE]
>      _STORE_FILE_TEMPLATE = 'test-virtdev%d'
>      _STORE_FILE_PATH = '/var/tmp'
>  
> -    def __init__(self, methodName='runTest', deviceSpec=None):
> +    def __init__(self, methodName='runTest', deviceSpec=None, block_size=None):
>          """ DevicelibsTestCase manages loop devices.
>  
>              It constructs loop devices according to loopDeviceSpec,
>              sets them up, and tears them down again.
>  
> -            :param deviceSpec: Specification for the loop devices.
> -            :type deviceSpec: list of int
> -
> -            deviceSpec is currently just a list of ints corresponding
> -            to the number of blocks for each backing store.
> +            :param deviceSpec: list containing the size of each loop device
> +            :type deviceSpec: list of Size or NoneType
> +            :param block_size: block size for dd command when making devices
> +            :type block_size: Size or NoneType
>          """
>          unittest.TestCase.__init__(self, methodName=methodName)
>          self._deviceSpec = deviceSpec or self._DEFAULT_DEVICE_SPEC
>          self._loopMap = {}
>          self.loopDevices = []
> +        self.block_size = block_size or self.DEFAULT_BLOCK_SIZE
> +
> +        if any(d % self.block_size != Size(0) for d in self._deviceSpec):
> +            raise ValueError("Every device size must be a multiple of the block size.")
>  
>      def setUp(self):
>          for index, size in enumerate(self._deviceSpec):
>              store = os.path.join(self._STORE_FILE_PATH, self._STORE_FILE_TEMPLATE % index)
>              dev = getFreeLoopDev()
> -            makeLoopDev(dev, store, num_blocks=size)
> +            num_blocks = int(size / self.block_size)
> +            makeLoopDev(dev, store, num_blocks=num_blocks, block_size=int(self.block_size))
>              self._loopMap[dev] = store
>              self.loopDevices.append(dev)
>  

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list