test_object_life_cycle.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import uuid
  2. from cloudbridge.cloud.interfaces import VolumeState
  3. from cloudbridge.cloud.interfaces.resources 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(
  32. [VolumeState.ERROR],
  33. terminal_states=[VolumeState.AVAILABLE])
  34. # Hitting the timeout should raise an exception
  35. with self.assertRaises(WaitStateException):
  36. test_vol.wait_for([VolumeState.ERROR], timeout=0, interval=0)