aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorwiktor w brodlo <wiktor@brodlo.net>2011-06-15 16:59:54 +0000
committerwiktor w brodlo <wiktor@brodlo.net>2011-06-15 16:59:54 +0000
commit2590d96369d0217e31dc2812690dde61dac417b5 (patch)
tree82276f787b08a28548e342c7921486f1acefab9f /tests
parentfirst commit (diff)
downloadanaconda-2590d96369d0217e31dc2812690dde61dac417b5.tar.gz
anaconda-2590d96369d0217e31dc2812690dde61dac417b5.tar.bz2
anaconda-2590d96369d0217e31dc2812690dde61dac417b5.zip
Initial import from Sabayon (ver 0.9.9.56)
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am24
-rw-r--r--tests/__init__.py29
-rw-r--r--tests/storage/Makefile.am24
-rw-r--r--tests/storage/__init__.py0
-rw-r--r--tests/storage/devicelibs/Makefile.am22
-rw-r--r--tests/storage/devicelibs/__init__.py0
-rw-r--r--tests/storage/devicelibs/baseclass.py55
-rw-r--r--tests/storage/devicelibs/crypto.py126
-rw-r--r--tests/storage/devicelibs/lvm.py230
-rw-r--r--tests/storage/devicelibs/mdraid.py107
-rw-r--r--tests/storage/devicelibs/mpath.py29
-rw-r--r--tests/storage/devicelibs/swap.py66
12 files changed, 712 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..062b931
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,24 @@
+# tests/Makefile.am for anaconda
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: David Cantrell <dcantrell@redhat.com>
+
+SUBDIRS = storage
+
+EXTRA_DIST = *.py
+
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..d5b53a8
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1,29 @@
+import os
+
+# this has to be imported before running anything
+import anaconda_log
+import upgrade
+
+
+def getAvailableSuites():
+ root, tests_dir = os.path.split(os.path.dirname(__file__))
+ modules = []
+
+ for root, dirs, files in os.walk(tests_dir):
+ for filename in files:
+ if filename.endswith(".py") and filename != "__init__.py":
+ basename, extension = os.path.splitext(filename)
+ modules.append(os.path.join(root, basename).replace("/", "."))
+
+ available_suites = {}
+ for module in modules:
+ imported = __import__(module, globals(), locals(), [module], -1)
+ try:
+ suite = getattr(imported, "suite")
+ except AttributeError as e:
+ continue
+
+ if callable(suite):
+ available_suites[module] = suite()
+
+ return available_suites
diff --git a/tests/storage/Makefile.am b/tests/storage/Makefile.am
new file mode 100644
index 0000000..e3e520c
--- /dev/null
+++ b/tests/storage/Makefile.am
@@ -0,0 +1,24 @@
+# tests/storage/Makefile.am for anaconda
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: David Cantrell <dcantrell@redhat.com>
+
+SUBDIRS = devicelibs
+
+EXTRA_DIST = *.py
+
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/storage/__init__.py
diff --git a/tests/storage/devicelibs/Makefile.am b/tests/storage/devicelibs/Makefile.am
new file mode 100644
index 0000000..eeeabbd
--- /dev/null
+++ b/tests/storage/devicelibs/Makefile.am
@@ -0,0 +1,22 @@
+# tests/storage/devicelibs/Makefile.am for anaconda
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: David Cantrell <dcantrell@redhat.com>
+
+EXTRA_DIST = *.py
+
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/tests/storage/devicelibs/__init__.py b/tests/storage/devicelibs/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/storage/devicelibs/__init__.py
diff --git a/tests/storage/devicelibs/baseclass.py b/tests/storage/devicelibs/baseclass.py
new file mode 100644
index 0000000..c19bfc3
--- /dev/null
+++ b/tests/storage/devicelibs/baseclass.py
@@ -0,0 +1,55 @@
+import unittest
+import os
+import subprocess
+
+
+def makeLoopDev(device_name, file_name):
+ proc = subprocess.Popen(["dd", "if=/dev/zero", "of=%s" % file_name,
+ "bs=1024", "count=102400"],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ while True:
+ proc.communicate()
+ if proc.returncode is not None:
+ rc = proc.returncode
+ break
+ if rc:
+ raise OSError, "dd failed creating the file %s" % file_name
+
+ proc = subprocess.Popen(["losetup", device_name, file_name],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ while True:
+ proc.communicate()
+ if proc.returncode is not None:
+ rc = proc.returncode
+ break
+ if rc:
+ raise OSError, "losetup failed setting up the loop device %s" % device_name
+
+def removeLoopDev(device_name, file_name):
+ proc = subprocess.Popen(["losetup", "-d", device_name],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ while True:
+ proc.communicate()
+ if proc.returncode is not None:
+ rc = proc.returncode
+ break
+ if rc:
+ raise OSError, "losetup failed removing the loop device %s" % device_name
+
+ os.unlink(file_name)
+
+
+class DevicelibsTestCase(unittest.TestCase):
+
+ _LOOP_DEVICES = (("/dev/loop0", "/tmp/test-virtdev0"),
+ ("/dev/loop1", "/tmp/test-virtdev1"))
+
+ ((_LOOP_DEV0, _LOOP_FILE0), (_LOOP_DEV1, _LOOP_FILE1)) = _LOOP_DEVICES
+
+ def setUp(self):
+ for dev, file in self._LOOP_DEVICES:
+ makeLoopDev(dev, file)
+
+ def tearDown(self):
+ for dev, file in self._LOOP_DEVICES:
+ removeLoopDev(dev, file)
diff --git a/tests/storage/devicelibs/crypto.py b/tests/storage/devicelibs/crypto.py
new file mode 100644
index 0000000..0f9f7bd
--- /dev/null
+++ b/tests/storage/devicelibs/crypto.py
@@ -0,0 +1,126 @@
+import baseclass
+import unittest
+import storage.devicelibs.crypto as crypto
+
+import tempfile
+import os
+
+class CryptoTestCase(baseclass.DevicelibsTestCase):
+
+ def testCrypto(self):
+ ##
+ ## is_luks
+ ##
+ # pass
+ self.assertEqual(crypto.is_luks(self._LOOP_DEV0), -22)
+ self.assertEqual(crypto.is_luks("/not/existing/device"), -22)
+
+ ##
+ ## luks_format
+ ##
+ # pass
+ self.assertEqual(crypto.luks_format(self._LOOP_DEV0, passphrase="secret", cipher="aes-cbc-essiv:sha256", key_size=256), None)
+
+ # make a key file
+ handle, keyfile = tempfile.mkstemp(prefix="key", text=False)
+ os.write(handle, "nobodyknows")
+ os.close(handle)
+
+ # format with key file
+ self.assertEqual(crypto.luks_format(self._LOOP_DEV1, key_file=keyfile), None)
+
+ # fail
+ self.assertRaises(crypto.CryptoError, crypto.luks_format, "/not/existing/device", passphrase="secret", cipher="aes-cbc-essiv:sha256", key_size=256)
+ # no passhprase or key file
+ self.assertRaises(ValueError, crypto.luks_format, self._LOOP_DEV1, cipher="aes-cbc-essiv:sha256", key_size=256)
+
+ ##
+ ## is_luks
+ ##
+ # pass
+ self.assertEqual(crypto.is_luks(self._LOOP_DEV0), 0) # 0 = is luks
+ self.assertEqual(crypto.is_luks(self._LOOP_DEV1), 0)
+
+ ##
+ ## luks_add_key
+ ##
+ # pass
+ self.assertEqual(crypto.luks_add_key(self._LOOP_DEV0, new_passphrase="another-secret", passphrase="secret"), None)
+
+ # make another key file
+ handle, new_keyfile = tempfile.mkstemp(prefix="key", text=False)
+ os.write(handle, "area51")
+ os.close(handle)
+
+ # add new key file
+ self.assertEqual(crypto.luks_add_key(self._LOOP_DEV1, new_key_file=new_keyfile, key_file=keyfile), None)
+
+ # fail
+ self.assertRaises(RuntimeError, crypto.luks_add_key, self._LOOP_DEV0, new_passphrase="another-secret", passphrase="wrong-passphrase")
+
+ ##
+ ## luks_remove_key
+ ##
+ # fail
+ self.assertRaises(RuntimeError, crypto.luks_remove_key, self._LOOP_DEV0, del_passphrase="another-secret", passphrase="wrong-pasphrase")
+
+ # pass
+ self.assertEqual(crypto.luks_remove_key(self._LOOP_DEV0, del_passphrase="another-secret", passphrase="secret"), None)
+
+ # remove key file
+ self.assertEqual(crypto.luks_remove_key(self._LOOP_DEV1, del_key_file=new_keyfile, key_file=keyfile), None)
+
+ ##
+ ## luks_open
+ ##
+ # pass
+ self.assertEqual(crypto.luks_open(self._LOOP_DEV0, "crypted", passphrase="secret"), None)
+ self.assertEqual(crypto.luks_open(self._LOOP_DEV1, "encrypted", key_file=keyfile), None)
+
+ # fail
+ self.assertRaises(crypto.CryptoError, crypto.luks_open, "/not/existing/device", "another-crypted", passphrase="secret")
+ self.assertRaises(crypto.CryptoError, crypto.luks_open, "/not/existing/device", "another-crypted", key_file=keyfile)
+ # no passhprase or key file
+ self.assertRaises(ValueError, crypto.luks_open, self._LOOP_DEV1, "another-crypted")
+
+ ##
+ ## luks_status
+ ##
+ # pass
+ self.assertEqual(crypto.luks_status("crypted"), True)
+ self.assertEqual(crypto.luks_status("encrypted"), True)
+ self.assertEqual(crypto.luks_status("another-crypted"), False)
+
+ ##
+ ## luks_uuid
+ ##
+ # pass
+ uuid = crypto.luks_uuid(self._LOOP_DEV0)
+ self.assertEqual(crypto.luks_uuid(self._LOOP_DEV0), uuid)
+ uuid = crypto.luks_uuid(self._LOOP_DEV1)
+ self.assertEqual(crypto.luks_uuid(self._LOOP_DEV1), uuid)
+
+ ##
+ ## luks_close
+ ##
+ # pass
+ self.assertEqual(crypto.luks_close("crypted"), None)
+ self.assertEqual(crypto.luks_close("encrypted"), None)
+
+ # fail
+ self.assertRaises(crypto.CryptoError, crypto.luks_close, "wrong-name")
+ # already closed
+ self.assertRaises(crypto.CryptoError, crypto.luks_close, "crypted")
+ self.assertRaises(crypto.CryptoError, crypto.luks_close, "encrypted")
+
+ # cleanup
+ os.unlink(keyfile)
+ os.unlink(new_keyfile)
+
+
+def suite():
+ return unittest.TestLoader().loadTestsFromTestCase(CryptoTestCase)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/storage/devicelibs/lvm.py b/tests/storage/devicelibs/lvm.py
new file mode 100644
index 0000000..e6ba1a6
--- /dev/null
+++ b/tests/storage/devicelibs/lvm.py
@@ -0,0 +1,230 @@
+import baseclass
+import unittest
+import storage.devicelibs.lvm as lvm
+
+class LVMTestCase(baseclass.DevicelibsTestCase):
+
+ def testLVM(self):
+ ##
+ ## pvcreate
+ ##
+ # pass
+ for dev, file in self._LOOP_DEVICES:
+ self.assertEqual(lvm.pvcreate(dev), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.pvcreate, "/not/existing/device")
+
+ ##
+ ## pvresize
+ ##
+ # pass
+ for dev, file in self._LOOP_DEVICES:
+ self.assertEqual(lvm.pvresize(dev, 50), None)
+ self.assertEqual(lvm.pvresize(dev, 100), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.pvresize, "/not/existing/device", 50)
+
+ ##
+ ## vgcreate
+ ##
+ # pass
+ self.assertEqual(lvm.vgcreate("test-vg", [self._LOOP_DEV0, self._LOOP_DEV1], 4), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.vgcreate, "another-vg", ["/not/existing/device"], 4)
+ # vg already exists
+ self.assertRaises(lvm.LVMError, lvm.vgcreate, "test-vg", [self._LOOP_DEV0], 4)
+ # pe size must be power of 2
+ self.assertRaises(lvm.LVMError, lvm.vgcreate, "another-vg", [self._LOOP_DEV0], 5)
+
+ ##
+ ## pvremove
+ ##
+ # fail
+ # cannot remove pv now with vg created
+ self.assertRaises(lvm.LVMError, lvm.pvremove, self._LOOP_DEV0)
+
+ ##
+ ## vgdeactivate
+ ##
+ # pass
+ self.assertEqual(lvm.vgdeactivate("test-vg"), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.vgdeactivate, "wrong-vg-name")
+
+ ##
+ ## vgreduce
+ ##
+ # pass
+ self.assertEqual(lvm.vgreduce("test-vg", [self._LOOP_DEV1]), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.vgreduce, "wrong-vg-name", [self._LOOP_DEV1])
+ self.assertRaises(lvm.LVMError, lvm.vgreduce, "test-vg", ["/not/existing/device"])
+
+ ##
+ ## vgactivate
+ ##
+ # pass
+ self.assertEqual(lvm.vgactivate("test-vg"), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.vgactivate, "wrong-vg-name")
+
+ ##
+ ## pvinfo
+ ##
+ # pass
+ self.assertEqual(lvm.pvinfo(self._LOOP_DEV0)["pv_name"], self._LOOP_DEV0)
+ # no vg
+ self.assertEqual(lvm.pvinfo(self._LOOP_DEV1)["pv_name"], self._LOOP_DEV1)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.pvinfo, "/not/existing/device")
+
+ ##
+ ## vginfo
+ ##
+ # pass
+ self.assertEqual(lvm.vginfo("test-vg")["pe_size"], "4.00")
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.vginfo, "wrong-vg-name")
+
+ ##
+ ## lvcreate
+ ##
+ # pass
+ self.assertEqual(lvm.lvcreate("test-vg", "test-lv", 10), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.lvcreate, "wrong-vg-name", "another-lv", 10)
+
+ ##
+ ## lvdeactivate
+ ##
+ # pass
+ self.assertEqual(lvm.lvdeactivate("test-vg", "test-lv"), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.lvdeactivate, "test-vg", "wrong-lv-name")
+ self.assertRaises(lvm.LVMError, lvm.lvdeactivate, "wrong-vg-name", "test-lv")
+ self.assertRaises(lvm.LVMError, lvm.lvdeactivate, "wrong-vg-name", "wrong-lv-name")
+
+ ##
+ ## lvresize
+ ##
+ # pass
+ self.assertEqual(lvm.lvresize("test-vg", "test-lv", 60), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.lvresize, "test-vg", "wrong-lv-name", 80)
+ self.assertRaises(lvm.LVMError, lvm.lvresize, "wrong-vg-name", "test-lv", 80)
+ self.assertRaises(lvm.LVMError, lvm.lvresize, "wrong-vg-name", "wrong-lv-name", 80)
+ # changing to same size
+ self.assertRaises(lvm.LVMError, lvm.lvresize, "test-vg", "test-lv", 60)
+
+ ##
+ ## lvactivate
+ ##
+ # pass
+ self.assertEqual(lvm.lvactivate("test-vg", "test-lv"), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.lvactivate, "test-vg", "wrong-lv-name")
+ self.assertRaises(lvm.LVMError, lvm.lvactivate, "wrong-vg-name", "test-lv")
+ self.assertRaises(lvm.LVMError, lvm.lvactivate, "wrong-vg-name", "wrong-lv-name")
+
+ ##
+ ## lvs
+ ##
+ # pass
+ self.assertEqual(lvm.lvs("test-vg")["test-lv"]["size"], "60.00")
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.lvs, "wrong-vg-name")
+
+ ##
+ ## has_lvm
+ ##
+ # pass
+ self.assertEqual(lvm.has_lvm(), True)
+
+ # fail
+ # TODO
+
+ ##
+ ## lvremove
+ ##
+ # pass
+ self.assertEqual(lvm.lvdeactivate("test-vg", "test-lv"), None) # is deactivation needed?
+ self.assertEqual(lvm.lvremove("test-vg", "test-lv"), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.lvremove, "test-vg", "wrong-lv-name")
+ self.assertRaises(lvm.LVMError, lvm.lvremove, "wrong-vg-name", "test-lv")
+ self.assertRaises(lvm.LVMError, lvm.lvremove, "wrong-vg-name", "wrong-lv-name")
+ # lv already removed
+ self.assertRaises(lvm.LVMError, lvm.lvremove, "test-vg", "test-lv")
+
+ ##
+ ## vgremove
+ ##
+ # pass
+ self.assertEqual(lvm.vgremove("test-vg"), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.vgremove, "wrong-vg-name")
+ # vg already removed
+ self.assertRaises(lvm.LVMError, lvm.vgremove, "test-vg")
+
+ ##
+ ## pvremove
+ ##
+ # pass
+ for dev, file in self._LOOP_DEVICES:
+ self.assertEqual(lvm.pvremove(dev), None)
+
+ # fail
+ self.assertRaises(lvm.LVMError, lvm.pvremove, "/not/existing/device")
+ # pv already removed
+ self.assertRaises(lvm.LVMError, lvm.pvremove, self._LOOP_DEV0)
+
+ #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):
+ # pass
+ self.assertEqual(lvm.getMaxLVSize(), 16*1024**2)
+
+ #def testSafeLVMName(self):
+ # pass
+ self.assertEqual(lvm.safeLvmName("/strange/lv*name5"), "strange_lvname5")
+
+ #def testClampSize(self):
+ # pass
+ self.assertEqual(lvm.clampSize(10, 4), 8L)
+ self.assertEqual(lvm.clampSize(10, 4, True), 12L)
+
+ #def testVGUsedSpace(self):
+ # TODO
+ pass
+
+ #def testVGFreeSpace(self):
+ # TODO
+ pass
+
+
+def suite():
+ return unittest.TestLoader().loadTestsFromTestCase(LVMTestCase)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/storage/devicelibs/mdraid.py b/tests/storage/devicelibs/mdraid.py
new file mode 100644
index 0000000..3c0ee72
--- /dev/null
+++ b/tests/storage/devicelibs/mdraid.py
@@ -0,0 +1,107 @@
+import baseclass
+import unittest
+import storage.devicelibs.mdraid as mdraid
+
+import time
+
+class MDRaidTestCase(baseclass.DevicelibsTestCase):
+
+ def testMDRaid(self):
+ ##
+ ## getRaidLevels
+ ##
+ # pass
+ self.assertEqual(mdraid.getRaidLevels(), mdraid.getRaidLevels())
+
+ ##
+ ## get_raid_min_members
+ ##
+ # pass
+ self.assertEqual(mdraid.get_raid_min_members(mdraid.RAID0), 2)
+ 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)
+
+ # fail
+ # unsupported raid
+ self.assertRaises(ValueError, mdraid.get_raid_min_members, 4)
+
+ ##
+ ## get_raid_max_spares
+ ##
+ # pass
+ self.assertEqual(mdraid.get_raid_max_spares(mdraid.RAID0, 5), 0)
+ 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)
+
+ # fail
+ # unsupported raid
+ self.assertRaises(ValueError, mdraid.get_raid_max_spares, 4, 5)
+
+ ##
+ ## mdcreate
+ ##
+ # pass
+ self.assertEqual(mdraid.mdcreate("/dev/md0", 1, [self._LOOP_DEV0, self._LOOP_DEV1]), None)
+ # wait for raid to settle
+ time.sleep(2)
+
+ # fail
+ self.assertRaises(mdraid.MDRaidError, mdraid.mdcreate, "/dev/md1", 1, ["/not/existing/dev0", "/not/existing/dev1"])
+
+ ##
+ ## mddeactivate
+ ##
+ # pass
+ self.assertEqual(mdraid.mddeactivate("/dev/md0"), None)
+
+ # fail
+ self.assertRaises(mdraid.MDRaidError, mdraid.mddeactivate, "/not/existing/md")
+
+ ##
+ ## mdadd
+ ##
+ # pass
+ # TODO
+
+ # fail
+ self.assertRaises(mdraid.MDRaidError, mdraid.mdadd, "/not/existing/device")
+
+ ##
+ ## mdactivate
+ ##
+ # pass
+ self.assertEqual(mdraid.mdactivate("/dev/md0", [self._LOOP_DEV0, self._LOOP_DEV1], super_minor=0), None)
+ # wait for raid to settle
+ time.sleep(2)
+
+ # fail
+ self.assertRaises(mdraid.MDRaidError, mdraid.mdactivate, "/not/existing/md", super_minor=1)
+ # requires super_minor or uuid
+ self.assertRaises(ValueError, mdraid.mdactivate, "/dev/md1")
+
+ ##
+ ## mddestroy
+ ##
+ # pass
+ # deactivate first
+ self.assertEqual(mdraid.mddeactivate("/dev/md0"), None)
+
+ self.assertEqual(mdraid.mddestroy(self._LOOP_DEV0), None)
+ self.assertEqual(mdraid.mddestroy(self._LOOP_DEV1), None)
+
+ # fail
+ # not a component
+ self.assertRaises(mdraid.MDRaidError, mdraid.mddestroy, "/dev/md0")
+ self.assertRaises(mdraid.MDRaidError, mdraid.mddestroy, "/not/existing/device")
+
+
+def suite():
+ return unittest.TestLoader().loadTestsFromTestCase(MDRaidTestCase)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/storage/devicelibs/mpath.py b/tests/storage/devicelibs/mpath.py
new file mode 100644
index 0000000..8210b0b
--- /dev/null
+++ b/tests/storage/devicelibs/mpath.py
@@ -0,0 +1,29 @@
+import baseclass
+import unittest
+import storage.devicelibs.mpath as mpath
+
+class MPathTestCase(baseclass.DevicelibsTestCase):
+ def testMPath(self):
+ ##
+ ## parseMultipathOutput
+ ##
+ output="""\
+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
+"""
+ topology = mpath.parseMultipathOutput(output)
+ expected = {'mpatha':['sdb','sdc'], 'mpathb':['sda']}
+ self.assertEqual(topology, expected)
+
+def suite():
+ return unittest.TestLoader().loadTestsFromTestCase(MPathTestCase)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/storage/devicelibs/swap.py b/tests/storage/devicelibs/swap.py
new file mode 100644
index 0000000..b99d1f6
--- /dev/null
+++ b/tests/storage/devicelibs/swap.py
@@ -0,0 +1,66 @@
+import baseclass
+import unittest
+import storage.devicelibs.swap as swap
+
+class SwapTestCase(baseclass.DevicelibsTestCase):
+
+ def testSwap(self):
+ ##
+ ## mkswap
+ ##
+ # pass
+ self.assertEqual(swap.mkswap(self._LOOP_DEV0, "swap"), None)
+
+ # fail
+ self.assertRaises(swap.SwapError, swap.mkswap, "/not/existing/device")
+
+ ##
+ ## swapon
+ ##
+ # pass
+ self.assertEqual(swap.swapon(self._LOOP_DEV0, 1), None)
+
+ # fail
+ self.assertRaises(swap.SwapError, swap.swapon, "/not/existing/device")
+ # not a swap partition
+ self.assertRaises(swap.SwapError, swap.swapon, self._LOOP_DEV1)
+
+ # pass
+ # make another swap
+ self.assertEqual(swap.mkswap(self._LOOP_DEV1, "another-swap"), None)
+ self.assertEqual(swap.swapon(self._LOOP_DEV1), None)
+
+ ##
+ ## swapstatus
+ ##
+ # pass
+ self.assertEqual(swap.swapstatus(self._LOOP_DEV0), True)
+ self.assertEqual(swap.swapstatus(self._LOOP_DEV1), True)
+
+ # does not fail
+ self.assertEqual(swap.swapstatus("/not/existing/device"), False)
+
+ ##
+ ## swapoff
+ ##
+ # pass
+ self.assertEqual(swap.swapoff(self._LOOP_DEV1), None)
+
+ # check status
+ self.assertEqual(swap.swapstatus(self._LOOP_DEV0), True)
+ self.assertEqual(swap.swapstatus(self._LOOP_DEV1), False)
+
+ self.assertEqual(swap.swapoff(self._LOOP_DEV0), None)
+
+ # fail
+ self.assertRaises(swap.SwapError, swap.swapoff, "/not/existing/device")
+ # already off
+ self.assertRaises(swap.SwapError, swap.swapoff, self._LOOP_DEV0)
+
+
+def suite():
+ return unittest.TestLoader().loadTestsFromTestCase(SwapTestCase)
+
+
+if __name__ == "__main__":
+ unittest.main()