test_object_life_cycle.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import uuid
  2. import unittest
  3. from cloudbridge.cloud.interfaces import VolumeState
  4. from cloudbridge.cloud.interfaces.resources import WaitStateException
  5. from test.helpers import ProviderTestBase
  6. import test.helpers as helpers
  7. @unittest.skip("Skipping Object Lifecycle tests")
  8. class CloudObjectLifeCycleTestCase(ProviderTestBase):
  9. def __init__(self, methodName, provider):
  10. super(CloudObjectLifeCycleTestCase, self).__init__(
  11. methodName=methodName, provider=provider)
  12. def test_object_life_cycle(self):
  13. """
  14. Test object life cycle methods by using a volume.
  15. """
  16. name = "CBUnitTestLifeCycle-{0}".format(uuid.uuid4())
  17. test_vol = self.provider.block_store.volumes.create(
  18. name,
  19. 1,
  20. helpers.get_provider_test_data(self.provider, "placement"))
  21. # Waiting for an invalid timeout should raise an exception
  22. with self.assertRaises(AssertionError):
  23. test_vol.wait_for([VolumeState.ERROR], timeout=-1, interval=1)
  24. with self.assertRaises(AssertionError):
  25. test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=-1)
  26. # If interval < timeout, an exception should be raised
  27. with self.assertRaises(AssertionError):
  28. test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)
  29. with helpers.cleanup_action(lambda: test_vol.delete()):
  30. test_vol.wait_till_ready()
  31. # Hitting a terminal state should raise an exception
  32. with self.assertRaises(WaitStateException):
  33. test_vol.wait_for([VolumeState.ERROR],
  34. terminal_states=[VolumeState.AVAILABLE])
  35. # Hitting the timeout should raise an exception
  36. with self.assertRaises(WaitStateException):
  37. test_vol.wait_for([VolumeState.ERROR], timeout=0, interval=0)