LGTM

On Thu, Jun 5, 2014 at 4:58 PM, Dimitris Bliablias <[email protected]>
wrote:

> Extend the unit test 'ganeti.storage.bdev_unittest.py' to support the
> new 'Import' and 'Export' functionality in the block device abstract
> class.
>
> This patch tests whether the 'Import' and 'Export' methods return the
> desirable output command. It covers the 'RADOSBlockDevice' volumes that
> override the default 'dd' behavior with the 'rbd' utility, and also the
> 'PersistentBlockDevice' template that does not comply completely with
> the default case. The rest of the block devices inherit the default 'dd'
> functionality from the base class. So, to avoid repeating tests for the
> same behavior for all those classes (FileStorage, Gluster, DRBD) we
> write tests only for the 'LogicalVolume' class.
>
> Signed-off-by: Dimitris Bliablias <[email protected]>
> ---
>  test/py/ganeti.storage.bdev_unittest.py |   95
> +++++++++++++++++++++++++++++++
>  1 file changed, 95 insertions(+)
>
> diff --git a/test/py/ganeti.storage.bdev_unittest.py b/test/py/
> ganeti.storage.bdev_unittest.py
> index e4685fe..b33629d 100755
> --- a/test/py/ganeti.storage.bdev_unittest.py
> +++ b/test/py/ganeti.storage.bdev_unittest.py
> @@ -37,6 +37,9 @@ import testutils
>
>
>  class TestRADOSBlockDevice(testutils.GanetiTestCase):
> +  """Tests for bdev.RADOSBlockDevice volumes
> +
> +  """
>    def setUp(self):
>      """Set up input data"""
>      testutils.GanetiTestCase.setUp(self)
> @@ -67,6 +70,10 @@ class TestRADOSBlockDevice(testutils.GanetiTestCase):
>      self.output_invalid =
> testutils.ReadTestData("bdev-rbd/output_invalid.txt")
>
>      self.volume_name = "d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0"
> +    self.test_unique_id = ("rbd", self.volume_name)
> +    self.test_params = {
> +      constants.LDP_POOL: "fake_pool"
> +      }
>
>    def test_ParseRbdShowmappedJson(self):
>      parse_function = bdev.RADOSBlockDevice._ParseRbdShowmappedJson
> @@ -104,6 +111,43 @@ class TestRADOSBlockDevice(testutils.GanetiTestCase):
>      self.assertRaises(errors.BlockDeviceError, parse_function,
>                        self.output_invalid, self.volume_name)
>
> +  @testutils.patch_object(utils, "RunCmd")
> +  @testutils.patch_object(bdev.RADOSBlockDevice,
> "_UnmapVolumeFromBlockdev")
> +  @testutils.patch_object(bdev.RADOSBlockDevice, "Attach")
> +  def testRADOSBlockDeviceImport(self, attach_mock, unmap_mock,
> run_cmd_mock):
> +    """Test for bdev.RADOSBlockDevice.Import()"""
> +    # Set up the mock objects return values
> +    attach_mock.return_value = True
> +    run_cmd_mock.return_value = \
> +        utils.RunResult(0, None, "", "", "", utils.process._TIMEOUT_NONE,
> 0)
> +
> +    # Create a fake rbd volume
> +    inst = bdev.RADOSBlockDevice(self.test_unique_id, [], 1024,
> +                                 self.test_params, {})
> +    # Desired output command
> +    import_cmd = [constants.RBD_CMD, "import",
> +                  "-p", inst.rbd_pool,
> +                  "-", inst.rbd_name]
> +
> +    self.assertEqual(inst.Import(), import_cmd)
> +
> +  @testutils.patch_object(bdev.RADOSBlockDevice, "Attach")
> +  def testRADOSBlockDeviceExport(self, attach_mock):
> +    """Test for bdev.RADOSBlockDevice.Export()"""
> +    # Set up the mock object return value
> +    attach_mock.return_value = True
> +
> +    # Create a fake rbd volume
> +    inst = bdev.RADOSBlockDevice(self.test_unique_id, [], 1024,
> +                                 self.test_params, {})
> +    # Desired output command
> +    export_cmd = [constants.RBD_CMD, "export",
> +                  "-p", inst.rbd_pool,
> +                  inst.rbd_name, "-"]
> +
> +    self.assertEqual(inst.Export(), export_cmd)
> +
> +
>  class TestExclusiveStoragePvs(unittest.TestCase):
>    """Test cases for functions dealing with LVM PV and exclusive storage"""
>    # Allowance for rounding
> @@ -267,6 +311,57 @@ class TestLogicalVolume(unittest.TestCase):
>        multi_res = bdev.LogicalVolume._GetLvInfo("fake_path",
> _run_cmd=fake_cmd)
>        self.assertEqual(multi_res, one_res)
>
> +  @testutils.patch_object(bdev.LogicalVolume, "Attach")
> +  def testLogicalVolumeImport(self, attach_mock):
> +    """Tests for bdev.LogicalVolume.Import()"""
> +    # Set up the mock object return value
> +    attach_mock.return_value = True
> +
> +    # Create a fake logical volume
> +    test_unique_id = ("ganeti",
>  "31225655-5775-4356-c212-e8b1e137550a.disk0")
> +    inst = bdev.LogicalVolume(test_unique_id, [], 1024, {}, {})
> +
> +    # Desired output command
> +    import_cmd = [constants.DD_CMD,
> +                  "of=%s" % inst.dev_path,
> +                  "bs=%s" % constants.DD_BLOCK_SIZE,
> +                  "oflag=direct", "conv=notrunc"]
> +
> +    self.assertEqual(inst.Import(), import_cmd)
> +
> +  @testutils.patch_object(bdev.LogicalVolume, "Attach")
> +  def testLogicalVolumeExport(self, attach_mock):
> +    """Test for bdev.LogicalVolume.Export()"""
> +    # Set up the mock object return value
> +    attach_mock.return_value = True
> +
> +    # Create a fake logical volume
> +    test_unique_id = ("ganeti",
>  "31225655-5775-4356-c212-e8b1e137550a.disk0")
> +    inst = bdev.LogicalVolume(test_unique_id, [], 1024, {}, {})
> +
> +    # Desired output command
> +    export_cmd = [constants.DD_CMD,
> +                  "if=%s" % inst.dev_path,
> +                  "bs=%s" % constants.DD_BLOCK_SIZE,
> +                  "count=%s" % inst.size,
> +                  "iflag=direct"]
> +
> +    self.assertEqual(inst.Export(), export_cmd)
> +
> +
> +class TestPersistentBlockDevice(testutils.GanetiTestCase):
> +  """Tests for bdev.PersistentBlockDevice volumes
> +
> +  """
> +  def testPersistentBlockDeviceImport(self):
> +    """Test case for bdev.PersistentBlockDevice.Import()"""
> +    # Create a fake block device
> +    test_unique_id = (constants.BLOCKDEV_DRIVER_MANUAL, "/dev/abc")
> +    inst = bdev.PersistentBlockDevice(test_unique_id, [], 1024, {}, {})
> +
> +    self.assertRaises(errors.BlockDeviceError,
> +                      bdev.PersistentBlockDevice.Import, inst)
> +
>
>  if __name__ == "__main__":
>    testutils.GanetiTestProgram()
> --
> 1.7.10.4
>
>

Reply via email to