test_object_life_cycle.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import uuid
  2. from test import helpers
  3. from test.helpers import ProviderTestBase
  4. from cloudbridge.cloud.interfaces import VolumeState
  5. from cloudbridge.cloud.interfaces.exceptions import WaitStateException
  6. class CloudObjectLifeCycleTestCase(ProviderTestBase):
  7. @helpers.skipIfNoService(['block_store.volumes'])
  8. def test_object_life_cycle(self):
  9. """
  10. Test object life cycle methods by using a volume.
  11. """
  12. name = "CBUnitTestLifeCycle-{0}".format(uuid.uuid4())
  13. test_vol = self.provider.block_store.volumes.create(
  14. name,
  15. 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. with helpers.cleanup_action(lambda: test_vol.delete()):
  26. test_vol.wait_till_ready()
  27. # Hitting a terminal state should raise an exception
  28. with self.assertRaises(WaitStateException):
  29. test_vol.wait_for([VolumeState.ERROR],
  30. terminal_states=[VolumeState.AVAILABLE])
  31. # Hitting the timeout should raise an exception
  32. with self.assertRaises(WaitStateException):
  33. test_vol.wait_for([VolumeState.ERROR], timeout=0, interval=0)