2013-01-23 17:28:19 +00:00
|
|
|
#!/usr/bin/python
|
2011-01-18 09:24:57 +00:00
|
|
|
import baseclass
|
|
|
|
import unittest
|
2013-01-23 17:28:19 +00:00
|
|
|
from mock import acceptance
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
class SwapTestCase(baseclass.DevicelibsTestCase):
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def testSwap(self):
|
|
|
|
_LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
|
|
|
|
_LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
|
|
|
|
|
|
|
|
import storage.devicelibs.swap as swap
|
|
|
|
|
|
|
|
@acceptance
|
2011-01-18 09:24:57 +00:00
|
|
|
def testSwap(self):
|
|
|
|
##
|
|
|
|
## mkswap
|
|
|
|
##
|
|
|
|
# pass
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.mkswap(_LOOP_DEV0, "swap"), None)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
# fail
|
|
|
|
self.assertRaises(swap.SwapError, swap.mkswap, "/not/existing/device")
|
|
|
|
|
|
|
|
##
|
|
|
|
## swapon
|
|
|
|
##
|
|
|
|
# pass
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.swapon(_LOOP_DEV0, 1), None)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
# fail
|
|
|
|
self.assertRaises(swap.SwapError, swap.swapon, "/not/existing/device")
|
|
|
|
# not a swap partition
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertRaises(swap.SwapError, swap.swapon, _LOOP_DEV1)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
# pass
|
|
|
|
# make another swap
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.mkswap(_LOOP_DEV1, "another-swap"), None)
|
|
|
|
self.assertEqual(swap.swapon(_LOOP_DEV1), None)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
## swapstatus
|
|
|
|
##
|
|
|
|
# pass
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.swapstatus(_LOOP_DEV0), True)
|
|
|
|
self.assertEqual(swap.swapstatus(_LOOP_DEV1), True)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
# does not fail
|
|
|
|
self.assertEqual(swap.swapstatus("/not/existing/device"), False)
|
|
|
|
|
|
|
|
##
|
|
|
|
## swapoff
|
|
|
|
##
|
|
|
|
# pass
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.swapoff(_LOOP_DEV1), None)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
# check status
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.swapstatus(_LOOP_DEV0), True)
|
|
|
|
self.assertEqual(swap.swapstatus(_LOOP_DEV1), False)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertEqual(swap.swapoff(_LOOP_DEV0), None)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
# fail
|
|
|
|
self.assertRaises(swap.SwapError, swap.swapoff, "/not/existing/device")
|
|
|
|
# already off
|
2013-01-23 17:28:19 +00:00
|
|
|
self.assertRaises(swap.SwapError, swap.swapoff, _LOOP_DEV0)
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def suite():
|
|
|
|
return unittest.TestLoader().loadTestsFromTestCase(SwapTestCase)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|