test_object_life_cycle.py 1.7 KB

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