test_provider_image_service.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import uuid
  2. from cloudbridge.providers.interfaces import MachineImageState
  3. from test.helpers import ProviderTestBase
  4. import test.helpers as helpers
  5. class ProviderImageServiceTestCase(ProviderTestBase):
  6. def __init__(self, methodName, provider):
  7. super(ProviderImageServiceTestCase, self).__init__(
  8. methodName=methodName, provider=provider)
  9. def setUp(self):
  10. self.instance = helpers.get_test_instance(self.provider)
  11. def tearDown(self):
  12. self.instance.terminate()
  13. def test_create_and_list_image(self):
  14. """
  15. Create a new image and check whether that image can be listed.
  16. This covers waiting till the image is ready, checking that the image
  17. name is the expected one and whether list_images is functional.
  18. """
  19. name = "CBUnitTestListImg-{0}".format(uuid.uuid4())
  20. test_image = self.instance.create_image(name)
  21. with helpers.exception_action(lambda x: test_image.delete()):
  22. test_image.wait_till_ready()
  23. images = self.provider.images.list_images()
  24. found_images = [image for image in images if image.name == name]
  25. self.assertTrue(
  26. len(found_images) == 1,
  27. "List images does not return the expected image %s" %
  28. name)
  29. test_image.delete()
  30. test_image.wait_for(
  31. [MachineImageState.UNKNOWN],
  32. terminal_states=[MachineImageState.ERROR])
  33. # TODO: Images take a long time to deregister on EC2. Needs
  34. # investigation
  35. # images = self.provider.images.list_images()
  36. # found_images = [image for image in images if image.name == name]
  37. # self.assertTrue(
  38. # len(found_images) == 0,
  39. # "Image %s should have been deleted but still exists." %
  40. # name)