test_object_life_cycle.py 1.7 KB

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