test_object_life_cycle.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from cloudbridge.base import helpers as cb_helpers
  2. from cloudbridge.interfaces import VolumeState
  3. from cloudbridge.interfaces.exceptions import WaitStateException
  4. from tests import helpers
  5. from tests.helpers import ProviderTestBase
  6. class CloudObjectLifeCycleTestCase(ProviderTestBase):
  7. _multiprocess_can_split_ = True
  8. @helpers.skipIfNoService(['storage.volumes'])
  9. def test_object_life_cycle(self):
  10. # Test object life cycle methods by using a volume.
  11. label = "cb-objlifecycle-{0}".format(helpers.get_uuid())
  12. test_vol = None
  13. with cb_helpers.cleanup_action(lambda: test_vol.delete()):
  14. test_vol = self.provider.storage.volumes.create(
  15. label, 1)
  16. # Waiting for an invalid timeout should raise an exception
  17. with self.assertRaises(AssertionError):
  18. test_vol.wait_for([VolumeState.ERROR], timeout=-1, interval=1)
  19. with self.assertRaises(AssertionError):
  20. test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=-1)
  21. # If interval < timeout, an exception should be raised
  22. with self.assertRaises(AssertionError):
  23. test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)
  24. test_vol.wait_till_ready()
  25. # Hitting a terminal state should raise an exception
  26. with self.assertRaises(WaitStateException):
  27. test_vol.wait_for([VolumeState.ERROR],
  28. terminal_states=[VolumeState.AVAILABLE])
  29. # Hitting the timeout should raise an exception
  30. with self.assertRaises(WaitStateException):
  31. test_vol.wait_for([VolumeState.ERROR], timeout=0, interval=0)