[PATCH 2/6] Update unit tests and add a make target to run them.

David Lehman dlehman at redhat.com
Tue Jul 16 17:11:27 UTC 2013


---
 Makefile                             |  4 ++
 tests/action_test.py                 | 87 ++++++++++++------------------------
 tests/devicelibs_test/baseclass.py   |  3 --
 tests/devicelibs_test/crypto_test.py |  5 +--
 tests/devicelibs_test/edd_test.py    | 20 +++++----
 tests/devicelibs_test/lvm_test.py    | 13 +++---
 tests/devicelibs_test/mdraid_test.py | 17 +++----
 tests/devicelibs_test/mpath_test.py  | 86 -----------------------------------
 tests/devicelibs_test/swap_test.py   |  4 +-
 tests/partitioning_test.py           |  3 --
 tests/size_test.py                   | 14 +++---
 tests/storagetestcase.py             | 25 +++--------
 tests/udev_test.py                   | 65 +++++++++++++++------------
 13 files changed, 110 insertions(+), 236 deletions(-)
 delete mode 100755 tests/devicelibs_test/mpath_test.py

diff --git a/Makefile b/Makefile
index 2ecc6ce..0da915c 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,10 @@ check:
 	@echo "*** Running pylint to verify source ***"
 	#PYTHONPATH=. pylint blivet/*.py blivet/*/*.py --rcfile=/dev/null -i y -r n --disable=C,R --disable=W0141,W0142,W0221,W0401,W0403,W0404,W0603,W0611,W0612,W0613,W0614,W0703
 
+test:
+	@echo "*** Running unittests ***"
+	PYTHONPATH=.:tests/ python -m unittest discover -v -s tests/ -p '*_test.py'
+
 clean:
 	-rm *.tar.gz blivet/*.pyc blivet/*/*.pyc ChangeLog
 	$(MAKE) -C po clean
diff --git a/tests/action_test.py b/tests/action_test.py
index 5894557..06d21de 100644
--- a/tests/action_test.py
+++ b/tests/action_test.py
@@ -2,7 +2,6 @@
 
 import unittest
 from mock import Mock
-from mock import TestCase
 
 from storagetestcase import StorageTestCase
 import blivet
@@ -25,18 +24,17 @@ from blivet.deviceaction import ActionResizeDevice
 from blivet.deviceaction import ActionDestroyDevice
 from blivet.deviceaction import ActionCreateFormat
 from blivet.deviceaction import ActionResizeFormat
-from blivet.deviceaction import ActionMigrateFormat
 from blivet.deviceaction import ActionDestroyFormat
 
 """ DeviceActionTestSuite """
 
-class DeviceActionTestCase(Storag
+class DeviceActionTestCase(StorageTestCase):
     def setUp(self):
         """ Create something like a preexisting autopart on two disks (sda,sdb).
 
             The other two disks (sdc,sdd) are left for individual tests to use.
         """
-        self.setUpAnaconda()
+        self.setUpStorage()
 
         for name in ["sda", "sdb", "sdc", "sdd"]:
             disk = self.newDevice(device_class=DiskDevice,
@@ -72,7 +70,7 @@ class DeviceActionTestCase(Storag
         self.storage.devicetree._addDevice(vg)
 
         lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_root", vgdev=vg, size=160000,
+                                 name="lv_root", parents=[vg], size=160000,
                                  exists=True)
         lv_root.format = self.newFormat("ext4", mountpoint="/",
                                         device_instance=lv_root,
@@ -80,7 +78,7 @@ class DeviceActionTestCase(Storag
         self.storage.devicetree._addDevice(lv_root)
 
         lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_swap", vgdev=vg, size=4000,
+                                 name="lv_swap", parents=[vg], size=4000,
                                  exists=True)
         lv_swap.format = self.newFormat("swap", device=lv_swap.path,
                                         device_instance=lv_swap,
@@ -104,12 +102,12 @@ class DeviceActionTestCase(Storag
                 - non-existent-device create..destroy cycles removed
                     - all actions on this device should get removed
                 - all actions pruned from to-be-destroyed devices
-                    - resize, format, migrate, &c
-                - redundant resize/migrate/format actions pruned
+                    - resize, format, &c
+                - redundant resize/format actions pruned
                     - last one registered stays
 
             - action sorting
-                - destroy..resize..migrate..create
+                - destroy..resize..create
                 - creation
                     - leaves-last, including formatting
                 - destruction
@@ -141,13 +139,13 @@ class DeviceActionTestCase(Storag
         self.scheduleCreateDevice(device=vg)
 
         lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_root", vgdev=vg, size=60000)
+                                 name="lv_root", parents=[vg], size=60000)
         self.scheduleCreateDevice(device=lv_root)
         format = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
         self.scheduleCreateFormat(device=lv_root, format=format)
 
         lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_swap", vgdev=vg, size=4000)
+                                 name="lv_swap", parents=[vg], size=4000)
         self.scheduleCreateDevice(device=lv_swap)
         format = self.newFormat("swap", device=lv_swap.path)
         self.scheduleCreateFormat(device=lv_swap, format=format)
@@ -221,25 +219,6 @@ class DeviceActionTestCase(Storag
                               lv_root.size - 1000)
         lv_root.format.exists = True
 
-        # instantiation of format migrate action for non-migratable format
-        # type should fail
-        lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
-        self.assertNotEqual(lv_swap, None)
-        self.assertEqual(lv_swap.exists, True)
-        self.failUnlessRaises(ValueError,
-                              blivet.deviceaction.ActionMigrateFormat,
-                              lv_swap)
-
-        # instantiation of format migrate for non-existent format should fail
-        lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
-        self.assertNotEqual(lv_root, None)
-        orig_format = lv_root.format
-        lv_root.format = getFormat("ext3", device=lv_root.path)
-        self.failUnlessRaises(ValueError,
-                              blivet.deviceaction.ActionMigrateFormat,
-                              lv_root)
-        lv_root.format = orig_format
-
         # instantiation of device create action for existing device should
         # fail
         lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
@@ -295,12 +274,6 @@ class DeviceActionTestCase(Storag
 
         sdc1_format.exists = True
 
-        migrate_sdc1 = ActionMigrateFormat(sdc1)
-        self.failUnlessRaises(blivet.errors.DeviceTreeError,
-                              self.storage.devicetree.registerAction,
-                              migrate_sdc1)
-        migrate_sdc1.cancel()
-
         resize_sdc1_format = ActionResizeFormat(sdc1, sdc1.size - 10000)
         self.failUnlessRaises(blivet.errors.DeviceTreeError,
                               self.storage.devicetree.registerAction,
@@ -377,36 +350,26 @@ class DeviceActionTestCase(Storag
         self.assertEqual(create_format_2.obsoletes(create_format_1), True)
         self.assertEqual(create_format_1.obsoletes(create_format_2), False)
 
-        # ActionMigrateFormat
-        #
-        # - obsoletes other ActionMigrateFormat instances w/ lower id and same
-        #   device
-        sdc1.format = self.newFormat("ext2", mountpoint="/", device=sdc1.path,
-                                     device_instance=sdc1,
-                                     exists=True)
-        migrate_1 = ActionMigrateFormat(sdc1)
-        migrate_2 = ActionMigrateFormat(sdc1)
-        self.assertEqual(migrate_2.obsoletes(migrate_1), True)
-        self.assertEqual(migrate_1.obsoletes(migrate_2), False)
-
         # ActionResizeFormat
         #
         # - obsoletes other ActionResizeFormat instances w/ lower id and same
         #   device
+        sdc1.exists = True
+        sdc1.format.exists = True
         resize_format_1 = ActionResizeFormat(sdc1, sdc1.size - 1000)
         resize_format_2 = ActionResizeFormat(sdc1, sdc1.size - 5000)
         self.assertEqual(resize_format_2.obsoletes(resize_format_1), True)
         self.assertEqual(resize_format_1.obsoletes(resize_format_2), False)
+        sdc1.exists = False
+        sdc1.format.exists = False
 
         # ActionCreateFormat
         #
-        # - obsoletes migrate, resize format actions w/ lower id on same device
+        # - obsoletes resize format actions w/ lower id on same device
         new_format = self.newFormat("ext4", mountpoint="/foo", device=sdc1.path)
         create_format_3 = ActionCreateFormat(sdc1, new_format)
         self.assertEqual(create_format_3.obsoletes(resize_format_1), True)
         self.assertEqual(create_format_3.obsoletes(resize_format_2), True)
-        self.assertEqual(create_format_3.obsoletes(migrate_1), True)
-        self.assertEqual(create_format_3.obsoletes(migrate_2), True)
 
         # ActionResizeDevice
         #
@@ -427,7 +390,6 @@ class DeviceActionTestCase(Storag
         #   self if format does not exist)
         destroy_format_1 = ActionDestroyFormat(sdc1)
         self.assertEqual(destroy_format_1.obsoletes(create_format_1), True)
-        self.assertEqual(destroy_format_1.obsoletes(migrate_2), True)
         self.assertEqual(destroy_format_1.obsoletes(resize_format_1), True)
         self.assertEqual(destroy_format_1.obsoletes(destroy_format_1), True)
 
@@ -438,7 +400,6 @@ class DeviceActionTestCase(Storag
         # sdc1 does not exist
         destroy_sdc1 = ActionDestroyDevice(sdc1)
         self.assertEqual(destroy_sdc1.obsoletes(create_format_2), True)
-        self.assertEqual(destroy_sdc1.obsoletes(migrate_1), True)
         self.assertEqual(destroy_sdc1.obsoletes(resize_format_2), True)
         self.assertEqual(destroy_sdc1.obsoletes(create_device_1), True)
         self.assertEqual(destroy_sdc1.obsoletes(resize_device_1), True)
@@ -482,13 +443,13 @@ class DeviceActionTestCase(Storag
         self.scheduleCreateDevice(device=vg)
 
         lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_root", vgdev=vg, size=60000)
+                                 name="lv_root", parents=[vg], size=60000)
         self.scheduleCreateDevice(device=lv_root)
         format = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
         self.scheduleCreateFormat(device=lv_root, format=format)
 
         lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_swap", vgdev=vg, size=4000)
+                                 name="lv_swap", parents=[vg], size=4000)
         self.scheduleCreateDevice(device=lv_swap)
         format = self.newFormat("swap", device=lv_swap.path)
         self.scheduleCreateFormat(device=lv_swap, format=format)
@@ -601,13 +562,13 @@ class DeviceActionTestCase(Storag
         self.scheduleCreateDevice(device=vg)
 
         lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_root", vgdev=vg, size=160000)
+                                 name="lv_root", parents=[vg], size=160000)
         self.scheduleCreateDevice(device=lv_root)
         format = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
         self.scheduleCreateFormat(device=lv_root, format=format)
 
         lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                 name="lv_swap", vgdev=vg, size=4000)
+                                 name="lv_swap", parents=[vg], size=4000)
         self.scheduleCreateDevice(device=lv_swap)
         format = self.newFormat("swap", device=lv_swap.path)
         self.scheduleCreateFormat(device=lv_swap, format=format)
@@ -764,7 +725,7 @@ class DeviceActionTestCase(Storag
                                 name="testvg", parents=[sdc1], size=50000)
         create_vg = self.scheduleCreateDevice(device=testvg)
         testlv = self.newDevice(device_class=LVMLogicalVolumeDevice,
-                                name="testlv", vgdev=testvg, size=30000)
+                                name="testlv", parents=[testvg], size=30000)
         create_lv = self.scheduleCreateDevice(device=testlv)
         format = self.newFormat("ext4", device=testlv.path)
         create_lv_format = self.scheduleCreateFormat(device=testlv, format=format)
@@ -796,7 +757,7 @@ class DeviceActionTestCase(Storag
                                 name="testvg", parents=[sdc1], size=50000)
         testlv = self.newDevice(device_class=LVMLogicalVolumeDevice,
                                 exists=True,
-                                name="testlv", vgdev=testvg, size=30000)
+                                name="testlv", parents=[testvg], size=30000)
         testlv.format = self.newFormat("ext4", device=testlv.path,
                                        exists=True, device_instance=testlv)
 
@@ -806,9 +767,13 @@ class DeviceActionTestCase(Storag
         # device containing PV before resize of VG or LVs
         tmp = sdc1.format
         sdc1.format = None      # since lvmpv format is not resizable
+        sdc1.exists = True
+        sdc1.format.exists = True
         grow_pv = ActionResizeDevice(sdc1, sdc1.size + 10000)
         grow_lv = ActionResizeDevice(testlv, testlv.size + 5000)
         grow_lv_format = ActionResizeFormat(testlv, testlv.size + 5000)
+        sdc1.exists = False
+        sdc1.format.exists = False
 
         self.assertEqual(grow_lv.requires(grow_pv), True)
         self.assertEqual(grow_pv.requires(grow_lv), False)
@@ -847,7 +812,11 @@ class DeviceActionTestCase(Storag
         # shrinks a device that depends on the first action's device, eg:
         # shrink LV before resizing VG or PV devices
         shrink_lv = ActionResizeDevice(testlv, testlv.size - 10000)
+        sdc1.exists = True
+        sdc1.format.exists = True
         shrink_pv = ActionResizeDevice(sdc1, sdc1.size - 5000)
+        sdc1.exists = False
+        sdc1.format.exists = False
 
         self.assertEqual(shrink_pv.requires(shrink_lv), True)
         self.assertEqual(shrink_lv.requires(shrink_pv), False)
diff --git a/tests/devicelibs_test/baseclass.py b/tests/devicelibs_test/baseclass.py
index 06adef9..0209898 100644
--- a/tests/devicelibs_test/baseclass.py
+++ b/tests/devicelibs_test/baseclass.py
@@ -63,9 +63,6 @@ class DevicelibsTestCase(unittest.TestCase):
     _LOOP_DEVICES = ["/tmp/test-virtdev0", "/tmp/test-virtdev1"]
 
     def __init__(self, *args, **kwargs):
-        import pyanaconda.anaconda_log
-        pyanaconda.anaconda_log.init()
-
         unittest.TestCase.__init__(self, *args, **kwargs)
         self._loopMap = {}
 
diff --git a/tests/devicelibs_test/crypto_test.py b/tests/devicelibs_test/crypto_test.py
index 9e82de5..0e1422c 100755
--- a/tests/devicelibs_test/crypto_test.py
+++ b/tests/devicelibs_test/crypto_test.py
@@ -1,22 +1,19 @@
 #!/usr/bin/python
 import baseclass
 import unittest
-from mock import acceptance
 
 import tempfile
 import os
 
 class CryptoTestCase(baseclass.DevicelibsTestCase):
 
+    @skipUnless(os.geteuid() == 0, "requires root privileges")
     def testCrypto(self):
         _LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
         _LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
 
         import blivet.devicelibs.crypto as crypto
 
-
-    @acceptance
-    def testCrypto(self):
         ##
         ## is_luks
         ##
diff --git a/tests/devicelibs_test/edd_test.py b/tests/devicelibs_test/edd_test.py
index 25fa070..ec402ac 100644
--- a/tests/devicelibs_test/edd_test.py
+++ b/tests/devicelibs_test/edd_test.py
@@ -1,18 +1,14 @@
+import unittest
 import mock
 
-class EddTestCase(mock.TestCase):
-    def setUp(self):
-        self.setupModules(
-            ['_isys', 'logging', 'pyanaconda.anaconda_log', 'block'])
-
-    def tearDown(self):
-        self.tearDownModules()
-
+class EddTestCase(unittest.TestCase):
+    @unittest.skip("not implemented")
     def test_biosdev_to_edd_dir(self):
         from blivet.devicelibs import edd
         path = edd.biosdev_to_edd_dir(138)
         self.assertEqual("/sys/firmware/edd/int13_dev8a", path)
 
+    @unittest.skip("not implemented")
     def test_collect_edd_data(self):
         from blivet.devicelibs import edd
 
@@ -41,6 +37,7 @@ class EddTestCase(mock.TestCase):
         self.assertEqual(edd_dict[0x80].ata_device, 0)
         self.assertEqual(edd_dict[0x80].mbr_signature, "0x000ccb01")
 
+    @unittest.skip("not implemented")
     def test_collect_edd_data_cciss(self):
         from blivet.devicelibs import edd
         fs = EddTestFS(self, edd).sda_cciss()
@@ -49,6 +46,7 @@ class EddTestCase(mock.TestCase):
         self.assertEqual(edd_dict[0x80].pci_dev, None)
         self.assertEqual(edd_dict[0x80].channel, None)
 
+    @unittest.skip("not implemented")
     def test_edd_entry_str(self):
         from blivet.devicelibs import edd
         fs = EddTestFS(self, edd).sda_vda()
@@ -59,6 +57,7 @@ class EddTestCase(mock.TestCase):
 \tscsi_lun: None, sectors: 2097152"""
         self.assertEqual(str(edd_dict[0x80]), expected_output)
 
+    @unittest.skip("not implemented")
     def test_matcher_device_path(self):
         from blivet.devicelibs import edd
         fs = EddTestFS(self, edd).sda_vda()
@@ -72,6 +71,7 @@ class EddTestCase(mock.TestCase):
         path = analyzer.devname_from_pci_dev()
         self.assertEqual(path, "vda")
 
+    @unittest.skip("not implemented")
     def test_bad_device_path(self):
         from blivet.devicelibs import edd
         fs = EddTestFS(self, edd).sda_vda_no_pcidev()
@@ -81,6 +81,7 @@ class EddTestCase(mock.TestCase):
         path = analyzer.devname_from_pci_dev()
         self.assertEqual(path, None)
 
+    @unittest.skip("not implemented")
     def test_bad_host_bus(self):
         from blivet.devicelibs import edd
         fs = EddTestFS(self, edd).sda_vda_no_host_bus()
@@ -97,6 +98,7 @@ class EddTestCase(mock.TestCase):
         devname = analyzer.devname_from_pci_dev()
         self.assertEqual(devname, "vda")
 
+    @unittest.skip("not implemented")
     def test_get_edd_dict_1(self):
         """ Test get_edd_dict()'s pci_dev matching. """
         from blivet.devicelibs import edd
@@ -105,6 +107,7 @@ class EddTestCase(mock.TestCase):
                          {'sda' : 0x80,
                           'vda' : 0x81})
 
+    @unittest.skip("not implemented")
     def test_get_edd_dict_2(self):
         """ Test get_edd_dict()'s pci_dev matching. """
         from blivet.devicelibs import edd
@@ -116,6 +119,7 @@ class EddTestCase(mock.TestCase):
                          {'sda' : 0x80,
                           'vda' : 0x81})
 
+    @unittest.skip("not implemented")
     def test_get_edd_dict_3(self):
         """ Test scenario when the 0x80 and 0x81 edd directories contain the
             same data and give no way to distinguish among the two devices.
diff --git a/tests/devicelibs_test/lvm_test.py b/tests/devicelibs_test/lvm_test.py
index e639a21..8690ee2 100755
--- a/tests/devicelibs_test/lvm_test.py
+++ b/tests/devicelibs_test/lvm_test.py
@@ -1,19 +1,16 @@
 #!/usr/bin/python
 import baseclass
 import unittest
-from mock import acceptance
 
 class LVMTestCase(baseclass.DevicelibsTestCase):
 
+    @skipUnless(os.geteuid() == 0, "requires root privileges")
     def testLVM(self):
         _LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
         _LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
 
         import storage.devicelibs.lvm as lvm
 
-
-    @acceptance
-    def testLVM(self):
         ##
         ## pvcreate
         ##
@@ -202,22 +199,22 @@ class LVMTestCase(baseclass.DevicelibsTestCase):
         # pv already removed
         self.assertRaises(lvm.LVMError, lvm.pvremove, _LOOP_DEV0)
 
-    #def testGetPossiblePhysicalExtents(self):
+    def testGetPossiblePhysicalExtents(self):
         # pass
         self.assertEqual(lvm.getPossiblePhysicalExtents(4),
                          filter(lambda pe: pe > 4, map(lambda power: 2**power, xrange(3, 25))))
         self.assertEqual(lvm.getPossiblePhysicalExtents(100000),
                          filter(lambda pe: pe > 100000, map(lambda power: 2**power, xrange(3, 25))))
 
-    #def testGetMaxLVSize(self):
+    def testGetMaxLVSize(self):
         # pass
         self.assertEqual(lvm.getMaxLVSize(), 16*1024**2)
 
-    #def testSafeLVMName(self):
+    def testSafeLVMName(self):
         # pass
         self.assertEqual(lvm.safeLvmName("/strange/lv*name5"), "strange_lvname5")
 
-    #def testClampSize(self):
+    def testClampSize(self):
         # pass
         self.assertEqual(lvm.clampSize(10, 4), 8L)
         self.assertEqual(lvm.clampSize(10, 4, True), 12L)
diff --git a/tests/devicelibs_test/mdraid_test.py b/tests/devicelibs_test/mdraid_test.py
index 8d81020..2c2fc0d 100755
--- a/tests/devicelibs_test/mdraid_test.py
+++ b/tests/devicelibs_test/mdraid_test.py
@@ -2,18 +2,12 @@
 import baseclass
 import unittest
 import time
-from mock import acceptance
 
 class MDRaidTestCase(baseclass.DevicelibsTestCase):
 
     def testMDRaid(self):
-        _LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
-        _LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
-
         import blivet.devicelibs.mdraid as mdraid
 
-    @acceptance
-    def testMDRaid(self):
         ##
         ## getRaidLevels
         ##
@@ -28,7 +22,7 @@ class MDRaidTestCase(baseclass.DevicelibsTestCase):
         self.assertEqual(mdraid.get_raid_min_members(mdraid.RAID1), 2)
         self.assertEqual(mdraid.get_raid_min_members(mdraid.RAID5), 3)
         self.assertEqual(mdraid.get_raid_min_members(mdraid.RAID6), 4)
-        self.assertEqual(mdraid.get_raid_min_members(mdraid.RAID10), 2)
+        self.assertEqual(mdraid.get_raid_min_members(mdraid.RAID10), 4)
 
         # fail
         # unsupported raid
@@ -42,12 +36,19 @@ class MDRaidTestCase(baseclass.DevicelibsTestCase):
         self.assertEqual(mdraid.get_raid_max_spares(mdraid.RAID1, 5), 3)
         self.assertEqual(mdraid.get_raid_max_spares(mdraid.RAID5, 5), 2)
         self.assertEqual(mdraid.get_raid_max_spares(mdraid.RAID6, 5), 1)
-        self.assertEqual(mdraid.get_raid_max_spares(mdraid.RAID10, 5), 3)
+        self.assertEqual(mdraid.get_raid_max_spares(mdraid.RAID10, 5), 1)
 
         # fail
         # unsupported raid
         self.assertRaises(ValueError, mdraid.get_raid_max_spares, 8, 5)
 
+    @skipUnless(os.geteuid() == 0, "requires root privileges")
+    def testMDRaidAsRoot(self):
+        _LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
+        _LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
+
+        import blivet.devicelibs.mdraid as mdraid
+
         ##
         ## mdcreate
         ##
diff --git a/tests/devicelibs_test/mpath_test.py b/tests/devicelibs_test/mpath_test.py
deleted file mode 100755
index 91ee10d..0000000
--- a/tests/devicelibs_test/mpath_test.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/python
-import mock
-
-class MPathTestCase(mock.TestCase):
-
-    # creating devices, user_friendly_names set to yes
-    output1 = """\
-create: mpathb (1ATA     ST3120026AS                                         5M) undef ATA,ST3120026AS
-size=112G features='0' hwhandler='0' wp=undef
-`-+- policy='round-robin 0' prio=1 status=undef
-  `- 2:0:0:0 sda 8:0  undef ready running
-create: mpatha (36006016092d21800703762872c60db11) undef DGC,RAID 5
-size=10G features='1 queue_if_no_path' hwhandler='1 emc' wp=undef
-`-+- policy='round-robin 0' prio=2 status=undef
-  |- 6:0:0:0 sdb 8:16 undef ready running
-  `- 7:0:0:0 sdc 8:32 undef ready running\
-"""
-
-    # listing existing devices, user_friendly_names set to yes
-    output2 = """\
-mpathb (3600a0b800067fcc9000001f34d23ff88) dm-1 IBM,1726-4xx  FAStT
-size=100G features='0' hwhandler='1 rdac' wp=rw
-`-+- policy='round-robin 0' prio=-1 status=active
-  |- 1:0:0:0 sda 8:0  active undef running
-  `- 2:0:0:0 sdc 8:32 active undef running
-mpatha (3600a0b800067fabc000067694d23fe6e) dm-0 IBM,1726-4xx  FAStT
-size=100G features='0' hwhandler='1 rdac' wp=rw
-`-+- policy='round-robin 0' prio=-1 status=active
-  |- 1:0:0:1 sdb 8:16 active undef running
-  `- 2:0:0:1 sdd 8:48 active undef running
-"""
-
-    # creating devices, user_friendly_names set to no
-    output3 = """\
-create: 3600a0b800067fabc000067694d23fe6e undef IBM,1726-4xx  FAStT
-size=100G features='1 queue_if_no_path' hwhandler='1 rdac' wp=undef
-`-+- policy='round-robin 0' prio=6 status=undef
-  |- 1:0:0:1 sdb 8:16 undef ready running
-  `- 2:0:0:1 sdd 8:48 undef ready running
-create: 3600a0b800067fcc9000001f34d23ff88 undef IBM,1726-4xx  FAStT
-size=100G features='1 queue_if_no_path' hwhandler='1 rdac' wp=undef
-`-+- policy='round-robin 0' prio=3 status=undef
-  |- 1:0:0:0 sda 8:0  undef ready running
-  `- 2:0:0:0 sdc 8:32 undef ready running\
-"""
-
-    # listing existing devices, user_friendly_names set to no
-    output4 = """\
-3600a0b800067fcc9000001f34d23ff88 dm-1 IBM,1726-4xx  FAStT
-size=100G features='0' hwhandler='1 rdac' wp=rw
-`-+- policy='round-robin 0' prio=-1 status=active
-  |- 1:0:0:0 sda 8:0  active undef running
-  `- 2:0:0:0 sdc 8:32 active undef running
-3600a0b800067fabc000067694d23fe6e dm-0 IBM,1726-4xx  FAStT
-size=100G features='0' hwhandler='1 rdac' wp=rw
-`-+- policy='round-robin 0' prio=-1 status=active
-  |- 1:0:0:1 sdb 8:16 active undef running
-  `- 2:0:0:1 sdd 8:48 active undef running
-"""
-
-    def setUp(self):
-        self.setupModules(
-            ['_isys', 'logging', 'anaconda_log', 'block'])
-
-    def tearDown(self):
-        self.tearDownModules()
-
-    def testParse(self):
-        from blivet.devicelibs import mpath
-        topology = mpath.parseMultipathOutput(self.output1)
-        self.assertEqual(topology,
-                         {'mpatha':['sdb','sdc'], 'mpathb':['sda']})
-        topology = mpath.parseMultipathOutput(self.output2)
-        self.assertEqual(topology,
-                         {'mpathb':['sda','sdc'], 'mpatha':['sdb', 'sdd']})
-        topology = mpath.parseMultipathOutput(self.output3)
-        self.assertEqual(topology,
-                         {'3600a0b800067fabc000067694d23fe6e' : ['sdb','sdd'],
-                          '3600a0b800067fcc9000001f34d23ff88' : ['sda', 'sdc']})
-        topology = mpath.parseMultipathOutput(self.output4)
-        self.assertEqual(topology,
-                         {'3600a0b800067fabc000067694d23fe6e' : ['sdb','sdd'],
-                          '3600a0b800067fcc9000001f34d23ff88' : ['sda', 'sdc']})
-
-def suite():
-    return unittest.TestLoader().loadTestsFromTestCase(MPathTestCase)
diff --git a/tests/devicelibs_test/swap_test.py b/tests/devicelibs_test/swap_test.py
index 6df47ad..1f319d5 100755
--- a/tests/devicelibs_test/swap_test.py
+++ b/tests/devicelibs_test/swap_test.py
@@ -1,18 +1,16 @@
 #!/usr/bin/python
 import baseclass
 import unittest
-from mock import acceptance
 
 class SwapTestCase(baseclass.DevicelibsTestCase):
 
+    @skipUnless(os.geteuid() == 0, "requires root privileges")
     def testSwap(self):
         _LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
         _LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
 
         import blivet.devicelibs.swap as swap
 
-    @acceptance
-    def testSwap(self):
         ##
         ## mkswap
         ##
diff --git a/tests/partitioning_test.py b/tests/partitioning_test.py
index 9d4b4c6..5c840ff 100644
--- a/tests/partitioning_test.py
+++ b/tests/partitioning_test.py
@@ -5,9 +5,6 @@ from mock import Mock
 
 import parted
 
-import pyanaconda.anaconda_log
-pyanaconda.anaconda_log.init()
-
 from blivet.partitioning import getNextPartitionType
 
 # disklabel-type-specific constants
diff --git a/tests/size_test.py b/tests/size_test.py
index bb4629c..547035b 100644
--- a/tests/size_test.py
+++ b/tests/size_test.py
@@ -23,8 +23,6 @@
 
 import unittest
 
-from pyanaconda import anaconda_log
-anaconda_log.init()
 from blivet.errors import *
 from blivet.size import Size, _prefixes
 
@@ -35,12 +33,16 @@ class SizeTestCase(unittest.TestCase):
 
         self.assertRaises(SizeNotPositiveError, Size, bytes=-1)
 
-        self.assertRaises(SizeNotPositiveError, Size, spec="0")
+        zero = Size(bytes=0)
+        self.assertEqual(zero, 0.0)
+
         self.assertRaises(SizeNotPositiveError, Size, spec="-1 TB")
         self.assertRaises(SizeNotPositiveError, Size, spec="-47kb")
 
         s = Size(bytes=500)
-        self.assertRaises(SizePlacesError, s.humanReadable, places=0)
+        self.assertRaises(SizePlacesError, s.humanReadable, places=-1)
+
+        self.assertEqual(s.humanReadable(places=0), "500 B")
 
     def _prefixTestHelper(self, bytes, factor, prefix, abbr):
         c = bytes * factor
@@ -74,10 +76,10 @@ class SizeTestCase(unittest.TestCase):
 
     def testHumanReadable(self):
         s = Size(bytes=58929971L)
-        self.assertEquals(s.humanReadable(), "58.9 Mb")
+        self.assertEquals(s.humanReadable(), "58.92 MB")
 
         s = Size(bytes=478360371L)
-        self.assertEquals(s.humanReadable(), "0.48 Gb")
+        self.assertEquals(s.humanReadable(), "478.36 MB")
 
 def suite():
     return unittest.TestLoader().loadTestsFromTestCase(SizeTestCase)
diff --git a/tests/storagetestcase.py b/tests/storagetestcase.py
index addf707..6df4ca0 100644
--- a/tests/storagetestcase.py
+++ b/tests/storagetestcase.py
@@ -2,14 +2,9 @@
 
 import unittest
 from mock import Mock
-from mock import TestCase
 
 import parted
 
-import pyanaconda.anaconda_log
-pyanaconda.anaconda_log.init()
-
-import pyanaconda.iutil
 import blivet as blivet
 from blivet.formats import getFormat
 
@@ -25,7 +20,7 @@ from blivet.devices import LVMLogicalVolumeDevice
 from blivet.devices import FileDevice
 
 
-class StorageTestCase(TestCase):
+class StorageTestCase(unittest.TestCase):
     """ StorageTestCase
 
         This is a base class for storage test cases. It sets up imports of
@@ -36,22 +31,15 @@ class StorageTestCase(TestCase):
 
     """
     def __init__(self, *args, **kwargs):
-        TestCase.__init__(self, *args, **kwargs)
-
-        self.setUpAnaconda()
-
-    def setUpAnaconda(self):
-        pyanaconda.iutil.execWithRedirect = Mock()
-        pyanaconda.iutil.execWithCapture = Mock()
-        pyanaconda.iutil.execWithPulseProgress = Mock()
-        blivet.udev = Mock()
+        super(StorageTestCase, self).__init__(*args, **kwargs)
+        blivet.util.execWithRedirect = Mock()
+        blivet.util.execWithCapture = Mock()
 
-        self.anaconda = Mock()
         self.setUpStorage()
 
     def setUpStorage(self):
         self.setUpDeviceLibs()
-        self.storage = blivet.Blivet(self.anaconda)
+        self.storage = blivet.Blivet()
 
         # device status
         blivet.devices.StorageDevice.status = False
@@ -68,7 +56,6 @@ class StorageTestCase(TestCase):
         # prevent Ext2FS from trying to run resize2fs to get a filesystem's
         # minimum size
         blivet.formats.fs.Ext2FS.minSize = blivet.formats.DeviceFormat.minSize
-        blivet.formats.fs.FS.migratable = blivet.formats.DeviceFormat.migratable
 
     def setUpDeviceLibs(self):
         # devicelibs shouldn't be touching or looking at the host system
@@ -283,5 +270,3 @@ class StorageTestCase(TestCase):
         _device = devicetree.getDeviceByName(device.name)
         self.assertEqual(_device.format.type, None)
         return action
-
-
diff --git a/tests/udev_test.py b/tests/udev_test.py
index 9217aeb..feaca45 100644
--- a/tests/udev_test.py
+++ b/tests/udev_test.py
@@ -1,23 +1,17 @@
 #!/usr/bin/python
 
+import unittest
 import mock
 import os
 
-class UdevTest(mock.TestCase):
+class UdevTest(unittest.TestCase):
 
     def setUp(self):
-        self.setupModules(["_isys", "block", "ConfigParser"])
-        self.fs = mock.DiskIO()
-
         import blivet.udev
         blivet.udev.os = mock.Mock()
         blivet.udev.log = mock.Mock()
-        blivet.udev.open = self.fs.open
-
-    def tearDown(self):
-        self.tearDownModules()
 
-    def udev_enumerate_devices_test(self):
+    def test_udev_enumerate_devices(self):
         import blivet.udev
         ENUMERATE_LIST = [
             '/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda',
@@ -27,7 +21,6 @@ class UdevTest(mock.TestCase):
             '/sys/devices/virtual/block/ram1',
             '/sys/devices/virtual/block/dm-0',
         ]
-
         blivet.udev.global_udev.enumerate_devices = mock.Mock(return_value=ENUMERATE_LIST)
         ret = blivet.udev.udev_enumerate_devices()
         self.assertEqual(set(ret),
@@ -37,7 +30,7 @@ class UdevTest(mock.TestCase):
             '/devices/virtual/block/dm-0'])
         )
 
-    def udev_get_device_1_test(self):
+    def test_udev_get_device_1(self):
         import blivet.udev
 
         class Device(object):
@@ -66,6 +59,8 @@ class UdevTest(mock.TestCase):
         dev = Device()
         blivet.udev.global_udev = mock.Mock()
         blivet.udev.global_udev.create_device.return_value = dev
+
+        saved = blivet.udev.udev_parse_uevent_file
         blivet.udev.udev_parse_uevent_file = mock.Mock(return_value=dev)
 
         ret = blivet.udev.udev_get_device(DEV_PATH)
@@ -74,13 +69,15 @@ class UdevTest(mock.TestCase):
         self.assertEqual(ret['sysfs_path'], DEV_PATH)
         self.assertTrue(blivet.udev.udev_parse_uevent_file.called)
 
-    def udev_get_device_2_test(self):
+        blivet.udev.udev_parse_uevent_file = saved
+
+    def test_udev_get_device_2(self):
         import blivet.udev
         blivet.udev.os.path.exists.return_value = False
         ret = blivet.udev.udev_get_device('')
         self.assertEqual(ret, None)
 
-    def udev_get_device_3_test(self):
+    def test_udev_get_device_3(self):
         import blivet.udev
         blivet.udev.os.path.exists.return_value = True
         blivet.udev.global_udev = mock.Mock()
@@ -88,8 +85,9 @@ class UdevTest(mock.TestCase):
         ret = blivet.udev.udev_get_device('')
         self.assertEqual(ret, None)
 
-    def udev_get_devices_test(self):
+    def test_udev_get_devices(self):
         import blivet.udev
+        saved = blivet.udev.udev_settle
         blivet.udev.udev_settle = mock.Mock()
         DEVS = \
             ['/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda',
@@ -100,24 +98,31 @@ class UdevTest(mock.TestCase):
         blivet.udev.udev_get_device = lambda x: x
         ret = blivet.udev.udev_get_devices()
         self.assertEqual(ret, DEVS)
+        blivet.udev.udev_settle = saved
 
-    def udev_parse_uevent_file_1_test(self):
+    def test_udev_parse_uevent_file_1(self):
         import blivet.udev
-        blivet.udev.os.path.normpath = os.path.normpath
-        blivet.udev.os.access.return_value = True
+        # For this one we're accessing the real uevent file (twice).
+        path = '/devices/virtual/block/loop1'
+        info = {'sysfs_path': path}
+        for line in open('/sys' + path + '/uevent').readlines():
+            (name, equals, value) = line.strip().partition("=")
+            if not equals:
+                continue
 
-        FILE_CONTENT = "MAJOR=7\nMINOR=1\nDEVNAME=loop1\nDEVTYPE=disk\n"
-        self.fs.open('/sys/devices/virtual/block/loop1/uevent', 'w').write(FILE_CONTENT)
-        dev = {'sysfs_path': '/devices/virtual/block/loop1'}
+            info[name] = value
+
+        dev = {'sysfs_path': path}
+        blivet.udev.os.path.normpath = os.path.normpath
+        blivet.udev.os.access = os.access
+        blivet.udev.os.R_OK = os.R_OK
         ret = blivet.udev.udev_parse_uevent_file(dev)
-        self.assertEqual(ret,
-            {'sysfs_path': '/devices/virtual/block/loop1',
-            'DEVNAME': 'loop1',
-            'DEVTYPE': 'disk',
-            'MAJOR': '7',
-            'MINOR': '1'})
-
-    def udev_parse_uevent_file_2_test(self):
+        self.assertEqual(ret, info)
+        blivet.udev.os.path.normpath = mock.Mock()
+        blivet.udev.os.access = mock.Mock()
+        blivet.udev.os.R_OK = mock.Mock()
+
+    def test_udev_parse_uevent_file_2(self):
         import blivet.udev
         blivet.udev.os.path.normpath = os.path.normpath
         blivet.udev.os.access.return_value = False
@@ -137,3 +142,7 @@ class UdevTest(mock.TestCase):
         blivet.udev.util = mock.Mock()
         blivet.udev.udev_trigger()
         self.assertTrue(blivet.udev.util.run_program.called)
+
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.8.1.4



More information about the anaconda-patches mailing list