test_object_life_cycle.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. @helpers.skipIfNoService(['block_store.volumes'])
  11. def test_object_life_cycle(self):
  12. """
  13. Test object life cycle methods by using a volume.
  14. """
  15. name = "CBUnitTestLifeCycle-{0}".format(uuid.uuid4())
  16. test_vol = self.provider.block_store.volumes.create(
  17. name,
  18. 1,
  19. helpers.get_provider_test_data(self.provider, "placement"))
  20. # Waiting for an invalid timeout should raise an exception
  21. with self.assertRaises(AssertionError):
  22. test_vol.wait_for([VolumeState.ERROR], timeout=-1, interval=1)
  23. with self.assertRaises(AssertionError):
  24. test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=-1)
  25. # If interval < timeout, an exception should be raised
  26. with self.assertRaises(AssertionError):
  27. test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)
  28. with helpers.cleanup_action(lambda: test_vol.delete()):
  29. test_vol.wait_till_ready()
  30. # Hitting a terminal state should raise an exception
  31. with self.assertRaises(WaitStateException):
  32. test_vol.wait_for([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)