test_provider_image_service.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 test_create_and_list_image(self):
  10. """
  11. Create a new image and check whether that image can be listed.
  12. This covers waiting till the image is ready, checking that the image
  13. name is the expected one and whether list_images is functional.
  14. """
  15. instance_name = "CBImageTest-{0}-{1}".format(
  16. self.provider.name,
  17. uuid.uuid4())
  18. test_instance = helpers.get_test_instance(self.provider, instance_name)
  19. with helpers.exception_action(lambda: test_instance.terminate()):
  20. name = "CBUnitTestListImg-{0}".format(uuid.uuid4())
  21. test_image = test_instance.create_image(name)
  22. with helpers.exception_action(lambda: test_image.delete()):
  23. test_image.wait_till_ready(interval=helpers.TEST_WAIT_INTERVAL)
  24. images = self.provider.images.list_images()
  25. found_images = [image for image in images
  26. if image.name == name]
  27. self.assertTrue(
  28. len(found_images) == 1,
  29. "List images does not return the expected image %s" %
  30. name)
  31. test_image.delete()
  32. test_image.wait_for(
  33. [MachineImageState.UNKNOWN],
  34. terminal_states=[MachineImageState.ERROR],
  35. interval=helpers.TEST_WAIT_INTERVAL)
  36. # TODO: Images take a long time to deregister on EC2. Needs
  37. # investigation
  38. # images = self.provider.images.list_images()
  39. # found_images = [image for image in images
  40. # if image.name == name]
  41. # self.assertTrue(
  42. # len(found_images) == 0,
  43. # "Image %s should have been deleted but still exists." %
  44. # name)