test_object_life_cycle.py 1.8 KB

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