test_provider_image_service.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import uuid
  2. from test.helpers import ProviderTestBase
  3. import test.helpers as helpers
  4. class ProviderImageServiceTestCase(ProviderTestBase):
  5. def __init__(self, methodName, provider):
  6. super(ProviderImageServiceTestCase, self).__init__(
  7. methodName=methodName, provider=provider)
  8. def setUp(self):
  9. self.instance = helpers.get_test_instance(self.provider)
  10. def tearDown(self):
  11. self.instance.terminate()
  12. def test_create_and_list_image(self):
  13. """
  14. Create a new image and check whether that image can be listed.
  15. This covers waiting till the image is ready, checking that the image
  16. name is the expected one and whether list_images is functional.
  17. """
  18. name = "CBUnitTestListImg-{0}".format(uuid.uuid4())
  19. test_image = self.instance.create_image(name)
  20. with helpers.exception_action(lambda x: test_image.delete()):
  21. test_image.wait_till_ready()
  22. images = self.provider.images.list_images()
  23. images = [image for image in images if image.name == name]
  24. self.assertTrue(
  25. len(images) == 1,
  26. "List images does not return the expected image %s" %
  27. name)
  28. test_image.delete()