test_object_life_cycle.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from cloudbridge.cloud.base import helpers as cb_helpers
  2. from cloudbridge.cloud.interfaces import VolumeState
  3. from cloudbridge.cloud.interfaces.exceptions import WaitStateException
  4. from test import helpers
  5. from test.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. helpers.get_provider_test_data(self.provider, "placement"))
  17. # Waiting for an invalid timeout should raise an exception
  18. with self.assertRaises(AssertionError):
  19. test_vol.wait_for([VolumeState.ERROR], timeout=-1, interval=1)
  20. with self.assertRaises(AssertionError):
  21. test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=-1)
  22. # If interval < timeout, an exception should be raised
  23. with self.assertRaises(AssertionError):
  24. test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)
  25. test_vol.wait_till_ready()
  26. # Hitting a terminal state should raise an exception
  27. with self.assertRaises(WaitStateException):
  28. test_vol.wait_for([VolumeState.ERROR],
  29. terminal_states=[VolumeState.AVAILABLE])
  30. # Hitting the timeout should raise an exception
  31. with self.assertRaises(WaitStateException):
  32. test_vol.wait_for([VolumeState.ERROR], timeout=0, interval=0)